-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
57 lines (51 loc) · 2.15 KB
/
test.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
53
54
55
56
57
const assert = require('assert')
const pseudolocalize = require('./index')
describe('String', () => {
it('should pseudolocalize the string correctly', () => {
assert.equal(pseudolocalize('This is a string'), 'Tλïƨ ïƨ á ƨƭřïñϱ')
})
it('should not pseudolocalize variables within a string', () => {
assert.equal(pseudolocalize('This is a string with a {{variable}} within it'), 'Tλïƨ ïƨ á ƨƭřïñϱ ωïƭλ á {{variable}} ωïƭλïñ ïƭ')
})
})
describe('Object', () => {
it('should pseudolocalize all object values correctly', () => {
const pre = { firstKey: 'First value', secondKey: 'Second value' }
const post = { firstKey: 'Fïřƨƭ Ʋáℓúè', secondKey: '§èçôñδ Ʋáℓúè' }
assert.equal(pseudolocalize(pre).firstKey, post.firstKey)
assert.equal(pseudolocalize(pre).secondKey, post.secondKey)
})
it('should pseudolocalize all nested object values correctly', () => {
const pre = { firstKey: 'First value', secondKey: { nestedKey: 'Nested value' } }
const post = { firstKey: 'Fïřƨƭ Ʋáℓúè', secondKey: { nestedKey: 'Nèƨƭèδ Ʋáℓúè' } }
assert.equal(pseudolocalize(pre).firstKey, post.firstKey)
assert.equal(pseudolocalize(pre).secondKey.nestedKey, post.secondKey.nestedKey)
})
})
describe('Array', () => {
it('should pseudolocalize all array elements correctly', () => {
const pre = [ 'First element', 'Second element', 'Third element' ]
const post = [ 'Fïřƨƭ èℓè₥èñƭ', '§èçôñδ èℓè₥èñƭ', 'Tλïřδ èℓè₥èñƭ' ]
assert.equal(pseudolocalize(pre)[0], post[0])
assert.equal(pseudolocalize(pre)[1], post[1])
assert.equal(pseudolocalize(pre)[2], post[2])
})
})
describe('Number', () => {
it('should not alter numbers', () => {
assert.equal(pseudolocalize(0), 0)
})
})
describe('Boolean', () => {
it('should not alter booleans', () => {
assert.equal(pseudolocalize(true), true)
})
})
describe('Null', () => {
it('should not alter null values', () => {
assert.equal(pseudolocalize(null), null)
})
it('should return null if no argument is supplied', () => {
assert.equal(pseudolocalize(), null)
})
})