-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
52 lines (43 loc) · 1.46 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import assert from 'assert/strict'
import { i18n } from './intljulep.js'
i18n.addLocale('en', {
foo: "the bar",
plurals: {
msg: ["message", "messages"],
man: ["man", "men"],
woman: ["woman", "women"]
},
email: {
hey: "Hey!",
info: "Hi {name}. {@email.hey} You have {number} {@plurals.msg(number)}."
}
})
// before locale has been set
assert.throws(() => i18n('foo'), {
name: 'TypeError',
message: "Cannot read properties of undefined (reading 'foo')"
})
i18n.setLocale('en')
assert.equal(i18n('foo'), "the bar")
assert.equal(i18n('email.baz'), "email.baz")
assert.equal(i18n('plurals.msg', 0), "messages")
assert.equal(i18n('plurals.msg', 1), "message")
assert.equal(i18n('plurals.msg', 2), "messages")
assert.equal(i18n('plurals.msg', 3), "messages")
assert.equal(i18n('email.info', { name: "Laurent", number: 0 }), "Hi Laurent. Hey! You have 0 messages.")
assert.equal(i18n('email.info', { name: "Laurent", number: 1 }), "Hi Laurent. Hey! You have 1 message.")
assert.equal(i18n('email.info', { name: "Laurent", number: 2 }), "Hi Laurent. Hey! You have 2 messages.")
assert.equal(i18n('email.info', { name: "Laurent", number: 3 }), "Hi Laurent. Hey! You have 3 messages.")
i18n.addLocale('fr', {
foo: "le bar"
})
i18n.setLocale('fr')
assert.equal(i18n('foo'), "le bar")
i18n.setLocale('en')
assert.equal(i18n('foo'), "the bar")
// overwrite
i18n.addLocale('en', {
foo: "BAR"
})
assert.equal(i18n('foo'), "BAR")
console.log("All tests passed.")