-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
bake-ctc-to-lhl-test.js
91 lines (85 loc) · 2.2 KB
/
bake-ctc-to-lhl-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
81
82
83
84
85
86
87
88
89
90
91
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as bakery from '../../../scripts/i18n/bake-ctc-to-lhl.js';
describe('Baking Placeholders', () => {
it('passthroughs a basic message unchanged', () => {
const strings = {
hello: {
message: 'world',
},
};
const res = bakery.bakePlaceholders(strings);
expect(res).toEqual({
hello: {
message: 'world',
},
});
});
it('bakes a placeholder into the output string', () => {
const strings = {
hello: {
message: '$MARKDOWN_SNIPPET_0$',
placeholders: {
MARKDOWN_SNIPPET_0: {
content: '`World`',
},
},
},
};
const res = bakery.bakePlaceholders(strings);
expect(res).toStrictEqual({
hello: {
message: '`World`',
},
});
});
it('bakes a placeholder into the output string multiple times', () => {
const strings = {
hello: {
message: '$MARKDOWN_SNIPPET_0$ - $MARKDOWN_SNIPPET_0$',
placeholders: {
MARKDOWN_SNIPPET_0: {
content: '`World`',
},
},
},
};
const res = bakery.bakePlaceholders(strings);
expect(res).toStrictEqual({
hello: {
message: '`World` - `World`',
},
});
});
it('throws when a placeholder cannot be found', () => {
const strings = {
hello: {
message: 'Hello $MARKDOWN_SNIPPET_0$ $MARKDOWN_SNIPPET_1$',
placeholders: {
MARKDOWN_SNIPPET_0: {
content: '`World`',
},
},
},
};
// eslint-disable-next-line max-len
expect(() => bakery.bakePlaceholders(strings)).toThrow(/Message "Hello `World` \$MARKDOWN_SNIPPET_1\$" is missing placeholder\(s\): \$MARKDOWN_SNIPPET_1\$/);
});
it('throws when a placeholder is not in string', () => {
const strings = {
hello: {
message: 'World',
placeholders: {
MARKDOWN_SNIPPET_0: {
content: '`World`',
},
},
},
};
expect(() => bakery.bakePlaceholders(strings))
.toThrow(/Provided placeholder "MARKDOWN_SNIPPET_0" not found in message "World"./);
});
});