-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathloc_test.js
80 lines (73 loc) · 2.15 KB
/
loc_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { ENV } from '@ember/-internals/environment';
import { loc } from '@ember/string';
import { setStrings, getStrings } from '@ember/string/lib/string_registry';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
let oldString;
function test(assert, given, args, expected, description) {
expectDeprecation(() => {
assert.equal(loc(given, args), expected, description);
if (ENV.EXTEND_PROTOTYPES.String) {
assert.deepEqual(given.loc(...args), expected, description);
}
}, /loc is deprecated/);
}
moduleFor(
'EmberStringUtils.loc',
class extends AbstractTestCase {
beforeEach() {
oldString = getStrings();
setStrings({
'_Hello World': 'Bonjour le monde',
'_Hello %@': 'Bonjour %@',
'_Hello %@ %@': 'Bonjour %@ %@',
'_Hello %@# %@#': 'Bonjour %@2 %@1',
});
}
afterEach() {
setStrings(oldString);
}
['@test String.prototype.loc is not available without EXTEND_PROTOTYPES'](assert) {
if (!ENV.EXTEND_PROTOTYPES.String) {
assert.ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled');
} else {
assert.expect(0);
}
}
['@test String loc tests'](assert) {
test(
assert,
'_Hello World',
[],
'Bonjour le monde',
`loc('_Hello World') => 'Bonjour le monde'`
);
test(
assert,
'_Hello %@ %@',
['John', 'Doe'],
'Bonjour John Doe',
`loc('_Hello %@ %@', ['John', 'Doe']) => 'Bonjour John Doe'`
);
test(
assert,
'_Hello %@# %@#',
['John', 'Doe'],
'Bonjour Doe John',
`loc('_Hello %@# %@#', ['John', 'Doe']) => 'Bonjour Doe John'`
);
test(
assert,
'_Not In Strings',
[],
'_Not In Strings',
`loc('_Not In Strings') => '_Not In Strings'`
);
}
['@test works with argument form'](assert) {
expectDeprecation(() => {
assert.equal(loc('_Hello %@', 'John'), 'Bonjour John');
assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour John Doe');
}, /loc is deprecated/);
}
}
);