@esgettext/tools 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -21
- package/dist/command.d.ts +11 -0
- package/dist/command.js +3 -0
- package/dist/command.js.map +1 -0
- package/dist/commands/convert.d.ts +24 -0
- package/dist/commands/convert.js +284 -0
- package/dist/commands/convert.js.map +1 -0
- package/dist/commands/install.d.ts +22 -0
- package/dist/commands/install.js +249 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/msgfmt-all.d.ts +20 -0
- package/dist/commands/msgfmt-all.js +200 -0
- package/dist/commands/msgfmt-all.js.map +1 -0
- package/dist/commands/msgmerge-all.d.ts +21 -0
- package/dist/commands/msgmerge-all.js +212 -0
- package/dist/commands/msgmerge-all.js.map +1 -0
- package/dist/{xgettext → commands/xgettext}/file-resolver.d.ts +1 -1
- package/dist/commands/xgettext/file-resolver.js +21 -0
- package/dist/commands/xgettext/file-resolver.js.map +1 -0
- package/dist/commands/xgettext/file-resolver.spec.js +22 -0
- package/dist/commands/xgettext/file-resolver.spec.js.map +1 -0
- package/dist/commands/xgettext/files-collector.js +39 -0
- package/dist/commands/xgettext/files-collector.js.map +1 -0
- package/dist/{xgettext → commands/xgettext}/files-collector.spec.js +39 -21
- package/dist/commands/xgettext/files-collector.spec.js.map +1 -0
- package/dist/commands/xgettext.d.ts +29 -0
- package/dist/commands/xgettext.js +525 -0
- package/dist/commands/xgettext.js.map +1 -0
- package/dist/commands/xgettext.spec.js +897 -0
- package/dist/commands/xgettext.spec.js.map +1 -0
- package/dist/configuration.d.ts +36 -0
- package/dist/configuration.js +261 -0
- package/dist/configuration.js.map +1 -0
- package/dist/esgettext-package-json.d.ts +15 -0
- package/dist/esgettext-package-json.js +3 -0
- package/dist/esgettext-package-json.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/package.d.ts +1 -0
- package/dist/package.js +10 -11
- package/dist/package.js.map +1 -1
- package/dist/parser/javascript.js +7 -27
- package/dist/parser/javascript.js.map +1 -1
- package/dist/parser/javascript.spec.js +271 -172
- package/dist/parser/javascript.spec.js.map +1 -1
- package/dist/parser/parser.js +159 -146
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/po.d.ts +1 -1
- package/dist/parser/po.js +111 -128
- package/dist/parser/po.js.map +1 -1
- package/dist/parser/po.spec.js +349 -159
- package/dist/parser/po.spec.js.map +1 -1
- package/dist/parser/typescript.js +8 -27
- package/dist/parser/typescript.js.map +1 -1
- package/dist/parser/typescript.spec.js +56 -41
- package/dist/parser/typescript.spec.js.map +1 -1
- package/dist/pot/catalog.js +98 -82
- package/dist/pot/catalog.js.map +1 -1
- package/dist/pot/catalog.spec.js +47 -43
- package/dist/pot/catalog.spec.js.map +1 -1
- package/dist/pot/entry.js +102 -114
- package/dist/pot/entry.js.map +1 -1
- package/dist/pot/entry.spec.js +255 -139
- package/dist/pot/entry.spec.js.map +1 -1
- package/dist/pot/keyword.js +57 -88
- package/dist/pot/keyword.js.map +1 -1
- package/dist/pot/keyword.spec.js +26 -26
- package/dist/pot/keyword.spec.js.map +1 -1
- package/package.json +36 -24
- package/bin/esgettext-install.js +0 -5
- package/bin/esgettext-mo2json.js +0 -5
- package/bin/esgettext-msgfmt-all.js +0 -5
- package/bin/esgettext-msgmerge-all.js +0 -5
- package/bin/esgettext-xgettext.js +0 -5
- package/dist/cli/getopt.d.ts +0 -34
- package/dist/cli/getopt.js +0 -150
- package/dist/cli/getopt.js.map +0 -1
- package/dist/cli/getopt.spec.d.ts +0 -1
- package/dist/cli/getopt.spec.js +0 -164
- package/dist/cli/getopt.spec.js.map +0 -1
- package/dist/cli/install.d.ts +0 -1
- package/dist/cli/install.js +0 -91
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/mo2json-cli.d.ts +0 -1
- package/dist/cli/mo2json-cli.js +0 -48
- package/dist/cli/mo2json-cli.js.map +0 -1
- package/dist/cli/msgfmt-all.d.ts +0 -1
- package/dist/cli/msgfmt-all.js +0 -99
- package/dist/cli/msgfmt-all.js.map +0 -1
- package/dist/cli/msgmerge-all.d.ts +0 -1
- package/dist/cli/msgmerge-all.js +0 -85
- package/dist/cli/msgmerge-all.js.map +0 -1
- package/dist/cli/xgettext-cli.d.ts +0 -1
- package/dist/cli/xgettext-cli.js +0 -303
- package/dist/cli/xgettext-cli.js.map +0 -1
- package/dist/install/install.d.ts +0 -10
- package/dist/install/install.js +0 -157
- package/dist/install/install.js.map +0 -1
- package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
- package/dist/msgfmt-all/msgfmt-all.js +0 -142
- package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
- package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
- package/dist/msgmerge-all/msgmerge-all.js +0 -157
- package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
- package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
- package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
- package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
- package/dist/xgettext/file-resolver.js +0 -23
- package/dist/xgettext/file-resolver.js.map +0 -1
- package/dist/xgettext/file-resolver.spec.js +0 -22
- package/dist/xgettext/file-resolver.spec.js.map +0 -1
- package/dist/xgettext/files-collector.js +0 -41
- package/dist/xgettext/files-collector.js.map +0 -1
- package/dist/xgettext/files-collector.spec.js.map +0 -1
- package/dist/xgettext/xgettext.d.ts +0 -16
- package/dist/xgettext/xgettext.js +0 -335
- package/dist/xgettext/xgettext.js.map +0 -1
- package/dist/xgettext/xgettext.spec.js +0 -743
- package/dist/xgettext/xgettext.spec.js.map +0 -1
- /package/dist/{xgettext → commands/xgettext}/file-resolver.spec.d.ts +0 -0
- /package/dist/{xgettext → commands/xgettext}/files-collector.d.ts +0 -0
- /package/dist/{xgettext → commands/xgettext}/files-collector.spec.d.ts +0 -0
- /package/dist/{xgettext → commands}/xgettext.spec.d.ts +0 -0
package/dist/parser/po.spec.js
CHANGED
|
@@ -1,226 +1,394 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const catalog_1 = require("../pot/catalog");
|
|
4
|
+
const po_1 = require("./po");
|
|
5
|
+
const date = '2020-04-23 08:50+0300';
|
|
6
|
+
const warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(() => {
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
const errorSpy = jest.spyOn(global.console, 'error').mockImplementation(() => {
|
|
9
9
|
});
|
|
10
|
-
describe('parse po files',
|
|
11
|
-
describe('simple file',
|
|
12
|
-
afterEach(
|
|
10
|
+
describe('parse po files', () => {
|
|
11
|
+
describe('simple file', () => {
|
|
12
|
+
afterEach(() => {
|
|
13
13
|
warnSpy.mockClear();
|
|
14
14
|
errorSpy.mockClear();
|
|
15
15
|
});
|
|
16
|
-
it('should parse',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
it('should parse', () => {
|
|
17
|
+
const pot = `# Translations for smell-o-vision.
|
|
18
|
+
# Copyright (C) 2020 SmellOVision Inc.
|
|
19
|
+
# This file is distributed under the same license as the smell-o-vision package.
|
|
20
|
+
# John Doe <john.doe@example.com>, 2020.
|
|
21
|
+
#
|
|
22
|
+
msgid ""
|
|
23
|
+
msgstr ""
|
|
24
|
+
"Project-Id-Version: smell-o-vision 0.1.1\\n"
|
|
25
|
+
"Report-Msgid-Bugs-To: jane.appleseed@example.com\\n"
|
|
26
|
+
"POT-Creation-Date: 2020-04-23 08:50+0300\\n"
|
|
27
|
+
"PO-Revision-Date: 2020-04-25 23:04+0300\\n"
|
|
28
|
+
"Last-Translator: John Doe <John.Doe@example.com>\\n"
|
|
29
|
+
"Language-Team: Finnish <fi@li.org>\\n"
|
|
30
|
+
"Language: Finnish\\n"
|
|
31
|
+
"MIME-Version: 1.0\\n"
|
|
32
|
+
"Content-Type: text/plain; charset=utf-8\\n"
|
|
33
|
+
"Content-Transfer-Encoding: 8bit\\n"
|
|
34
|
+
|
|
35
|
+
msgid "no comment"
|
|
36
|
+
msgstr ""
|
|
37
|
+
|
|
38
|
+
#, perl-brace-format, no-perl-format
|
|
39
|
+
msgid "Hello, {name}!"
|
|
40
|
+
msgstr ""
|
|
41
|
+
|
|
42
|
+
#: src/example.ts:2304 src/other.ts:1303
|
|
43
|
+
msgid "strawberry"
|
|
44
|
+
msgstr ""
|
|
45
|
+
|
|
46
|
+
msgid "One universe"
|
|
47
|
+
msgid_plural "Parallel universes"
|
|
48
|
+
msgstr[0] ""
|
|
49
|
+
msgstr[1] ""
|
|
50
|
+
|
|
51
|
+
msgctxt "escapes"
|
|
52
|
+
msgid "\\\\\\a\\b\\t\\n\\v\\f\\r\\""
|
|
53
|
+
msgstr ""
|
|
54
|
+
|
|
55
|
+
msgid ""
|
|
56
|
+
"Multi-line msgid"
|
|
57
|
+
msgstr ""
|
|
58
|
+
|
|
59
|
+
msgctxt ""
|
|
60
|
+
"multi-line"
|
|
61
|
+
msgid "Hello, world!\\n"
|
|
62
|
+
msgstr ""
|
|
63
|
+
|
|
64
|
+
msgid "One world"
|
|
65
|
+
msgid_plural ""
|
|
66
|
+
"Many worlds"
|
|
67
|
+
msgstr[0] ""
|
|
68
|
+
msgstr[1] ""
|
|
69
|
+
|
|
70
|
+
msgid "The translation has to be discarded."
|
|
71
|
+
msgstr "Die Übersetzung muss verworfen werden."
|
|
72
|
+
|
|
73
|
+
msgid "And this one, too."
|
|
74
|
+
msgid_plural "And these ones, too."
|
|
75
|
+
msgstr[0] "For a very long time ..."
|
|
76
|
+
msgstr[1] "For a very long time ..."
|
|
77
|
+
msgstr[2] "For a very long time ..."
|
|
78
|
+
msgstr[3] "For a very long time ..."
|
|
79
|
+
msgstr[4] "For a very long time ..."
|
|
80
|
+
msgstr[5] "For a very long time ..."
|
|
81
|
+
msgstr[6] "For a very long time ..."
|
|
82
|
+
msgstr[7] "For a very long time ..."
|
|
83
|
+
|
|
84
|
+
#. TRANSLATORS: This is the day of the week, not our star.
|
|
85
|
+
#. It is the abbreviation for Sunday.
|
|
86
|
+
msgid "Sun"
|
|
87
|
+
msgstr ""
|
|
88
|
+
|
|
89
|
+
#~ msgid "obsolete entry"
|
|
90
|
+
#~ msgstr ""
|
|
91
|
+
`;
|
|
92
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
93
|
+
const parser = new po_1.PoParser(catalog);
|
|
94
|
+
const input = Buffer.from(pot);
|
|
21
95
|
parser.parse(input, 'example.js');
|
|
22
96
|
expect(catalog.toString()).toMatchSnapshot();
|
|
23
97
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
24
98
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
25
99
|
});
|
|
26
100
|
});
|
|
27
|
-
describe('errors',
|
|
28
|
-
afterEach(
|
|
101
|
+
describe('errors', () => {
|
|
102
|
+
afterEach(() => {
|
|
29
103
|
warnSpy.mockClear();
|
|
30
104
|
errorSpy.mockClear();
|
|
31
105
|
});
|
|
32
|
-
it('should discard lone strings',
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
106
|
+
it('should discard lone strings', () => {
|
|
107
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
108
|
+
const parser = new po_1.PoParser(catalog);
|
|
109
|
+
const pot = `msgid "okay"
|
|
110
|
+
msgstr ""
|
|
111
|
+
|
|
112
|
+
"does not belong here"
|
|
113
|
+
`;
|
|
114
|
+
const input = Buffer.from(pot);
|
|
37
115
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
38
116
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
39
|
-
expect(errorSpy).toHaveBeenCalledWith('example.ts:4:1:
|
|
117
|
+
expect(errorSpy).toHaveBeenCalledWith('example.ts:4:1: Error: syntax error');
|
|
40
118
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
41
119
|
});
|
|
42
|
-
it('should discard lone strings reading from standard input',
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
120
|
+
it('should discard lone strings reading from standard input', () => {
|
|
121
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
122
|
+
const parser = new po_1.PoParser(catalog);
|
|
123
|
+
const pot = `msgid "okay"
|
|
124
|
+
msgstr ""
|
|
125
|
+
|
|
126
|
+
"does not belong here"
|
|
127
|
+
`;
|
|
128
|
+
const input = Buffer.from(pot);
|
|
47
129
|
expect(parser.parse(input, '-')).toBeFalsy();
|
|
48
130
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
49
|
-
expect(errorSpy).toHaveBeenCalledWith('[standard input]:4:1:
|
|
131
|
+
expect(errorSpy).toHaveBeenCalledWith('[standard input]:4:1: Error: syntax error');
|
|
50
132
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
51
133
|
});
|
|
52
|
-
it('should bail out on unexpected input',
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
134
|
+
it('should bail out on unexpected input', () => {
|
|
135
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
136
|
+
const parser = new po_1.PoParser(catalog);
|
|
137
|
+
let pot = `msgid "okay"
|
|
138
|
+
msgstr ""
|
|
139
|
+
|
|
140
|
+
MSGID "uppercase not allowed"
|
|
141
|
+
msgstr ""
|
|
142
|
+
`;
|
|
143
|
+
let input = Buffer.from(pot);
|
|
57
144
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
58
145
|
expect(errorSpy).toHaveBeenCalledTimes(2);
|
|
59
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1:
|
|
60
|
-
expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:4:6:
|
|
146
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: keyword "MSGID" unknown');
|
|
147
|
+
expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:4:6: Error: syntax error');
|
|
61
148
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
62
|
-
pot =
|
|
149
|
+
pot = `msgid "okay"
|
|
150
|
+
msgstr ""
|
|
151
|
+
|
|
152
|
+
nsgid "no, no, no"
|
|
153
|
+
msgstr ""
|
|
154
|
+
`;
|
|
63
155
|
input = Buffer.from(pot);
|
|
64
156
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
65
157
|
expect(errorSpy).toHaveBeenCalledTimes(4);
|
|
66
|
-
expect(errorSpy).toHaveBeenNthCalledWith(3, 'example.ts:4:1:
|
|
67
|
-
expect(errorSpy).toHaveBeenNthCalledWith(4, 'example.ts:4:6:
|
|
158
|
+
expect(errorSpy).toHaveBeenNthCalledWith(3, 'example.ts:4:1: Error: keyword "nsgid" unknown');
|
|
159
|
+
expect(errorSpy).toHaveBeenNthCalledWith(4, 'example.ts:4:6: Error: syntax error');
|
|
68
160
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
69
161
|
});
|
|
70
|
-
it('should bail out on garbage',
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
162
|
+
it('should bail out on garbage', () => {
|
|
163
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
164
|
+
const parser = new po_1.PoParser(catalog);
|
|
165
|
+
const pot = `msgid "okay"
|
|
166
|
+
msgstr ""
|
|
167
|
+
|
|
168
|
+
'garbage'
|
|
169
|
+
`;
|
|
170
|
+
const input = Buffer.from(pot);
|
|
75
171
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
76
172
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1:
|
|
173
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: syntax error');
|
|
78
174
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
79
175
|
});
|
|
80
|
-
it('should bail out on entries w/o msgid',
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
176
|
+
it('should bail out on entries w/o msgid', () => {
|
|
177
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
178
|
+
const parser = new po_1.PoParser(catalog);
|
|
179
|
+
const pot = `msgid "okay"
|
|
180
|
+
msgstr ""
|
|
181
|
+
|
|
182
|
+
# Missing msgid.
|
|
183
|
+
msgstr ""
|
|
184
|
+
`;
|
|
185
|
+
const input = Buffer.from(pot);
|
|
85
186
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
86
187
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
87
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1:
|
|
188
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: missing "msgid" section');
|
|
88
189
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
89
190
|
});
|
|
90
|
-
it('should bail out on duplicate entries',
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
191
|
+
it('should bail out on duplicate entries', () => {
|
|
192
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
193
|
+
const parser = new po_1.PoParser(catalog);
|
|
194
|
+
const pot = `msgid "okay"
|
|
195
|
+
msgstr ""
|
|
196
|
+
|
|
197
|
+
msgid "okay"
|
|
198
|
+
msgstr ""
|
|
199
|
+
`;
|
|
200
|
+
const input = Buffer.from(pot);
|
|
95
201
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
96
202
|
expect(errorSpy).toHaveBeenCalledTimes(2);
|
|
97
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1:
|
|
98
|
-
expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:1:1:
|
|
203
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: duplicate message definition...');
|
|
204
|
+
expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:1:1: Error: ...this is the location of the first definition');
|
|
99
205
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
100
206
|
});
|
|
101
|
-
it('should bail out on duplicate msgid sections',
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
207
|
+
it('should bail out on duplicate msgid sections', () => {
|
|
208
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
209
|
+
const parser = new po_1.PoParser(catalog);
|
|
210
|
+
const pot = `msgid "okay"
|
|
211
|
+
msgstr ""
|
|
212
|
+
|
|
213
|
+
msgid "not"
|
|
214
|
+
msgstr ""
|
|
215
|
+
msgid "okay"
|
|
216
|
+
`;
|
|
217
|
+
const input = Buffer.from(pot);
|
|
106
218
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
107
219
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
108
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1:
|
|
220
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgid" section');
|
|
109
221
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
110
222
|
});
|
|
111
|
-
it('should bail out on duplicate msgstr sections',
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
223
|
+
it('should bail out on duplicate msgstr sections', () => {
|
|
224
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
225
|
+
const parser = new po_1.PoParser(catalog);
|
|
226
|
+
const pot = `msgid "okay"
|
|
227
|
+
msgstr ""
|
|
228
|
+
|
|
229
|
+
msgid "not"
|
|
230
|
+
msgstr ""
|
|
231
|
+
msgstr "okay"
|
|
232
|
+
`;
|
|
233
|
+
const input = Buffer.from(pot);
|
|
116
234
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
117
235
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
118
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1:
|
|
236
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgstr" section');
|
|
119
237
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
120
238
|
});
|
|
121
|
-
it('should bail out on duplicate msgid_plural sections',
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
239
|
+
it('should bail out on duplicate msgid_plural sections', () => {
|
|
240
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
241
|
+
const parser = new po_1.PoParser(catalog);
|
|
242
|
+
const pot = `msgid "okay"
|
|
243
|
+
msgstr ""
|
|
244
|
+
|
|
245
|
+
msgid "not"
|
|
246
|
+
msgid_plural "really"
|
|
247
|
+
msgid_plural "really"
|
|
248
|
+
msgstr[0] ""
|
|
249
|
+
msgstr[1] ""
|
|
250
|
+
`;
|
|
251
|
+
const input = Buffer.from(pot);
|
|
126
252
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
127
253
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
128
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1:
|
|
254
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgid_plural" section');
|
|
129
255
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
130
256
|
});
|
|
131
|
-
it('should bail out on duplicate msgctxt sections',
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
257
|
+
it('should bail out on duplicate msgctxt sections', () => {
|
|
258
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
259
|
+
const parser = new po_1.PoParser(catalog);
|
|
260
|
+
const pot = `msgid "okay"
|
|
261
|
+
msgstr ""
|
|
262
|
+
|
|
263
|
+
msgctxt "Menu"
|
|
264
|
+
msgctxt "File"
|
|
265
|
+
msgid "Hello, world!"
|
|
266
|
+
msgstr ""
|
|
267
|
+
`;
|
|
268
|
+
const input = Buffer.from(pot);
|
|
136
269
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
137
270
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
138
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1:
|
|
271
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: Error: duplicate "msgctxt" section');
|
|
139
272
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
140
273
|
});
|
|
141
|
-
it('should enforce consistent use of #~',
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
274
|
+
it('should enforce consistent use of #~', () => {
|
|
275
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
276
|
+
const parser = new po_1.PoParser(catalog);
|
|
277
|
+
const pot = `msgid "okay"
|
|
278
|
+
msgstr ""
|
|
279
|
+
|
|
280
|
+
msgid "not"
|
|
281
|
+
#~ msgstr "okay"
|
|
282
|
+
msgstr "okay"
|
|
283
|
+
`;
|
|
284
|
+
const input = Buffer.from(pot);
|
|
146
285
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
147
286
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
148
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1:
|
|
287
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: Error: inconsistent use of #~');
|
|
149
288
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
150
289
|
});
|
|
151
|
-
it('should bail out on non-strings for msgids',
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
290
|
+
it('should bail out on non-strings for msgids', () => {
|
|
291
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
292
|
+
const parser = new po_1.PoParser(catalog);
|
|
293
|
+
const pot = `msgid "okay"
|
|
294
|
+
msgstr ""
|
|
295
|
+
|
|
296
|
+
msgid not
|
|
297
|
+
msgstr "okay"
|
|
298
|
+
`;
|
|
299
|
+
const input = Buffer.from(pot);
|
|
156
300
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
157
301
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
158
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:14:
|
|
302
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:14: Error: syntax error');
|
|
159
303
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
160
304
|
});
|
|
161
|
-
it('should bail out on unterminated strings',
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
305
|
+
it('should bail out on unterminated strings', () => {
|
|
306
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
307
|
+
const parser = new po_1.PoParser(catalog);
|
|
308
|
+
const pot = `msgid "okay"
|
|
309
|
+
msgstr ""
|
|
310
|
+
|
|
311
|
+
msgid "not
|
|
312
|
+
msgstr "okay"
|
|
313
|
+
`;
|
|
314
|
+
const input = Buffer.from(pot);
|
|
166
315
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
167
316
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
168
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:11:
|
|
317
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:11: Error: end-of-line within string');
|
|
169
318
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
170
319
|
});
|
|
171
|
-
it('should bail out on trailing backslashes',
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
320
|
+
it('should bail out on trailing backslashes', () => {
|
|
321
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
322
|
+
const parser = new po_1.PoParser(catalog);
|
|
323
|
+
const pot = `msgid "okay"
|
|
324
|
+
msgstr ""
|
|
325
|
+
|
|
326
|
+
msgid "not\\"
|
|
327
|
+
msgstr "okay"
|
|
328
|
+
`;
|
|
329
|
+
const input = Buffer.from(pot);
|
|
176
330
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
177
331
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
178
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:7:
|
|
332
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:7: Error: end-of-line within string');
|
|
179
333
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
180
334
|
});
|
|
181
|
-
it('should bail out on invalid control sequences',
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
335
|
+
it('should bail out on invalid control sequences', () => {
|
|
336
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
337
|
+
const parser = new po_1.PoParser(catalog);
|
|
338
|
+
const pot = `msgid "okay"
|
|
339
|
+
msgstr ""
|
|
340
|
+
|
|
341
|
+
msgid "beware of \\x-rays"
|
|
342
|
+
msgstr ""
|
|
343
|
+
`;
|
|
344
|
+
const input = Buffer.from(pot);
|
|
186
345
|
expect(parser.parse(input, 'example.ts')).toBeFalsy();
|
|
187
346
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
188
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:18:
|
|
347
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:18: Error: invalid control sequence');
|
|
189
348
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
190
349
|
});
|
|
191
350
|
});
|
|
192
|
-
describe('warnings',
|
|
193
|
-
afterEach(
|
|
351
|
+
describe('warnings', () => {
|
|
352
|
+
afterEach(() => {
|
|
194
353
|
warnSpy.mockClear();
|
|
195
354
|
errorSpy.mockClear();
|
|
196
355
|
});
|
|
197
|
-
it('should warn about empty flags',
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
356
|
+
it('should warn about empty flags', () => {
|
|
357
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
358
|
+
const parser = new po_1.PoParser(catalog);
|
|
359
|
+
const pot = `#, fuzzy ,, perl-brace-format
|
|
360
|
+
msgid "Hello, {name}!"
|
|
361
|
+
msgstr ""
|
|
362
|
+
`;
|
|
363
|
+
const input = Buffer.from(pot);
|
|
202
364
|
parser.parse(input, 'example.js');
|
|
203
365
|
expect(catalog.toString()).toMatchSnapshot();
|
|
204
366
|
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
205
367
|
expect(warnSpy).toHaveBeenNthCalledWith(1, 'example.js:1:11: warning: ignoring empty flag');
|
|
206
368
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
207
369
|
});
|
|
208
|
-
it('should warn about empty flags reading from standard input',
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
370
|
+
it('should warn about empty flags reading from standard input', () => {
|
|
371
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
372
|
+
const parser = new po_1.PoParser(catalog);
|
|
373
|
+
const pot = `#, fuzzy ,, perl-brace-format
|
|
374
|
+
msgid "Hello, {name}!"
|
|
375
|
+
msgstr ""
|
|
376
|
+
`;
|
|
377
|
+
const input = Buffer.from(pot);
|
|
213
378
|
parser.parse(input, '-');
|
|
214
379
|
expect(catalog.toString()).toMatchSnapshot();
|
|
215
380
|
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
216
381
|
expect(warnSpy).toHaveBeenNthCalledWith(1, '[standard input]:1:11: warning: ignoring empty flag');
|
|
217
382
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
218
383
|
});
|
|
219
|
-
it('should warn about invalid references',
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
384
|
+
it('should warn about invalid references', () => {
|
|
385
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
386
|
+
const parser = new po_1.PoParser(catalog);
|
|
387
|
+
const pot = `#: src/here.js:2304 somewhere
|
|
388
|
+
msgid "Hello, {name}!"
|
|
389
|
+
msgstr ""
|
|
390
|
+
`;
|
|
391
|
+
const input = Buffer.from(pot);
|
|
224
392
|
parser.parse(input, 'example.js');
|
|
225
393
|
expect(catalog.toString()).toMatchSnapshot();
|
|
226
394
|
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
@@ -228,63 +396,85 @@ describe('parse po files', function () {
|
|
|
228
396
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
229
397
|
});
|
|
230
398
|
});
|
|
231
|
-
describe('encoding',
|
|
232
|
-
afterEach(
|
|
399
|
+
describe('encoding', () => {
|
|
400
|
+
afterEach(() => {
|
|
233
401
|
warnSpy.mockClear();
|
|
234
402
|
errorSpy.mockClear();
|
|
235
403
|
});
|
|
236
|
-
it('should accept cp1252',
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
404
|
+
it('should accept cp1252', () => {
|
|
405
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
406
|
+
const parser = new po_1.PoParser(catalog);
|
|
407
|
+
const pot = `msgid ""
|
|
408
|
+
msgstr ""
|
|
409
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
410
|
+
"Content-Type: text/plain; charset=CP1252\\n"
|
|
411
|
+
`;
|
|
412
|
+
const input = Buffer.from(pot);
|
|
241
413
|
parser.parse(input, 'example.ts');
|
|
242
414
|
expect(catalog.toString()).toMatchSnapshot();
|
|
243
415
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
244
416
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
245
417
|
});
|
|
246
|
-
it('should throw on unsupported encodings',
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
418
|
+
it('should throw on unsupported encodings', () => {
|
|
419
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
420
|
+
const parser = new po_1.PoParser(catalog);
|
|
421
|
+
const pot = `msgid ""
|
|
422
|
+
msgstr ""
|
|
423
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
424
|
+
"Content-Type: text/plain; charset=CP1252\\n"
|
|
425
|
+
`;
|
|
426
|
+
const input = Buffer.from(pot);
|
|
251
427
|
expect(parser.parse(input, 'example.ts', 'invalid')).toBeFalsy();
|
|
252
428
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
253
429
|
expect(errorSpy).toHaveBeenNthCalledWith(1, 'unsupported encoding "invalid"');
|
|
254
430
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
255
431
|
});
|
|
256
|
-
it('should re-parse a lone header',
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
432
|
+
it('should re-parse a lone header', () => {
|
|
433
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
434
|
+
const parser = new po_1.PoParser(catalog);
|
|
435
|
+
const pot = `msgid ""
|
|
436
|
+
msgstr ""
|
|
437
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
438
|
+
"Content-Type: text/plain; charset=iso-8859-1\\n"`;
|
|
439
|
+
const input = Buffer.from(pot);
|
|
261
440
|
parser.parse(input, 'example.ts');
|
|
262
441
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
263
442
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
264
443
|
});
|
|
265
|
-
it('should not reparse w/o content-type header',
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
444
|
+
it('should not reparse w/o content-type header', () => {
|
|
445
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
446
|
+
const parser = new po_1.PoParser(catalog);
|
|
447
|
+
const pot = `msgid ""
|
|
448
|
+
msgstr ""
|
|
449
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
450
|
+
"Content-Transfer-Encoding: 8bit\\n"`;
|
|
451
|
+
const input = Buffer.from(pot);
|
|
270
452
|
parser.parse(input, 'example.ts');
|
|
271
453
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
272
454
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
273
455
|
});
|
|
274
|
-
it('should not reparse w/o charset',
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
456
|
+
it('should not reparse w/o charset', () => {
|
|
457
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
458
|
+
const parser = new po_1.PoParser(catalog);
|
|
459
|
+
const pot = `msgid ""
|
|
460
|
+
msgstr ""
|
|
461
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
462
|
+
"Content-Type: text/plain\\n"
|
|
463
|
+
"Content-Transfer-Encoding: 8bit\\n"`;
|
|
464
|
+
const input = Buffer.from(pot);
|
|
279
465
|
parser.parse(input, 'example.ts');
|
|
280
466
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
281
467
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
282
468
|
});
|
|
283
|
-
it('should not reparse for unknown encoding',
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
469
|
+
it('should not reparse for unknown encoding', () => {
|
|
470
|
+
const catalog = new catalog_1.Catalog({ date });
|
|
471
|
+
const parser = new po_1.PoParser(catalog);
|
|
472
|
+
const pot = `msgid ""
|
|
473
|
+
msgstr ""
|
|
474
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
|
475
|
+
"Content-Type: text/plain; charset=invalid\\n"
|
|
476
|
+
"Content-Transfer-Encoding: 8bit\\n"`;
|
|
477
|
+
const input = Buffer.from(pot);
|
|
288
478
|
parser.parse(input, 'example.ts');
|
|
289
479
|
expect(warnSpy).toHaveBeenCalledTimes(2);
|
|
290
480
|
expect(warnSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: warning: the charset "invalid" is not a portable encoding name.');
|