@esgettext/tools 1.0.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/LICENSE +19 -0
- package/README.md +126 -0
- package/bin/esgettext-install.js +5 -0
- package/bin/esgettext-mo2json.js +5 -0
- package/bin/esgettext-msgfmt-all.js +5 -0
- package/bin/esgettext-msgmerge-all.js +5 -0
- package/bin/esgettext-xgettext.js +5 -0
- package/dist/cli/getopt.d.ts +34 -0
- package/dist/cli/getopt.js +150 -0
- package/dist/cli/getopt.js.map +1 -0
- package/dist/cli/getopt.spec.d.ts +1 -0
- package/dist/cli/getopt.spec.js +164 -0
- package/dist/cli/getopt.spec.js.map +1 -0
- package/dist/cli/install.d.ts +1 -0
- package/dist/cli/install.js +91 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/mo2json-cli.d.ts +1 -0
- package/dist/cli/mo2json-cli.js +48 -0
- package/dist/cli/mo2json-cli.js.map +1 -0
- package/dist/cli/msgfmt-all.d.ts +1 -0
- package/dist/cli/msgfmt-all.js +99 -0
- package/dist/cli/msgfmt-all.js.map +1 -0
- package/dist/cli/msgmerge-all.d.ts +1 -0
- package/dist/cli/msgmerge-all.js +85 -0
- package/dist/cli/msgmerge-all.js.map +1 -0
- package/dist/cli/xgettext-cli.d.ts +1 -0
- package/dist/cli/xgettext-cli.js +303 -0
- package/dist/cli/xgettext-cli.js.map +1 -0
- package/dist/install/install.d.ts +10 -0
- package/dist/install/install.js +157 -0
- package/dist/install/install.js.map +1 -0
- package/dist/msgfmt-all/msgfmt-all.d.ts +8 -0
- package/dist/msgfmt-all/msgfmt-all.js +142 -0
- package/dist/msgfmt-all/msgfmt-all.js.map +1 -0
- package/dist/msgmerge-all/msgmerge-all.d.ts +9 -0
- package/dist/msgmerge-all/msgmerge-all.js +157 -0
- package/dist/msgmerge-all/msgmerge-all.js.map +1 -0
- package/dist/package.d.ts +4 -0
- package/dist/package.js +17 -0
- package/dist/package.js.map +1 -0
- package/dist/parser/__snapshots__/javascript.spec.js.snap +56 -0
- package/dist/parser/__snapshots__/po.spec.js.snap +176 -0
- package/dist/parser/javascript.d.ts +4 -0
- package/dist/parser/javascript.js +47 -0
- package/dist/parser/javascript.js.map +1 -0
- package/dist/parser/javascript.spec.d.ts +1 -0
- package/dist/parser/javascript.spec.js +436 -0
- package/dist/parser/javascript.spec.js.map +1 -0
- package/dist/parser/parser.d.ts +45 -0
- package/dist/parser/parser.js +582 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/po.d.ts +22 -0
- package/dist/parser/po.js +394 -0
- package/dist/parser/po.js.map +1 -0
- package/dist/parser/po.spec.d.ts +1 -0
- package/dist/parser/po.spec.js +296 -0
- package/dist/parser/po.spec.js.map +1 -0
- package/dist/parser/typescript.d.ts +4 -0
- package/dist/parser/typescript.js +47 -0
- package/dist/parser/typescript.js.map +1 -0
- package/dist/parser/typescript.spec.d.ts +1 -0
- package/dist/parser/typescript.spec.js +106 -0
- package/dist/parser/typescript.spec.js.map +1 -0
- package/dist/pot/__snapshots__/catalog.spec.js.snap +591 -0
- package/dist/pot/catalog.d.ts +26 -0
- package/dist/pot/catalog.js +210 -0
- package/dist/pot/catalog.js.map +1 -0
- package/dist/pot/catalog.spec.d.ts +1 -0
- package/dist/pot/catalog.spec.js +240 -0
- package/dist/pot/catalog.spec.js.map +1 -0
- package/dist/pot/entry.d.ts +35 -0
- package/dist/pot/entry.js +322 -0
- package/dist/pot/entry.js.map +1 -0
- package/dist/pot/entry.spec.d.ts +1 -0
- package/dist/pot/entry.spec.js +317 -0
- package/dist/pot/entry.spec.js.map +1 -0
- package/dist/pot/keyword.d.ts +17 -0
- package/dist/pot/keyword.js +181 -0
- package/dist/pot/keyword.js.map +1 -0
- package/dist/pot/keyword.spec.d.ts +1 -0
- package/dist/pot/keyword.spec.js +54 -0
- package/dist/pot/keyword.spec.js.map +1 -0
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +462 -0
- package/dist/xgettext/file-resolver.d.ts +5 -0
- package/dist/xgettext/file-resolver.js +23 -0
- package/dist/xgettext/file-resolver.js.map +1 -0
- package/dist/xgettext/file-resolver.spec.d.ts +1 -0
- package/dist/xgettext/file-resolver.spec.js +22 -0
- package/dist/xgettext/file-resolver.spec.js.map +1 -0
- package/dist/xgettext/files-collector.d.ts +5 -0
- package/dist/xgettext/files-collector.js +41 -0
- package/dist/xgettext/files-collector.js.map +1 -0
- package/dist/xgettext/files-collector.spec.d.ts +1 -0
- package/dist/xgettext/files-collector.spec.js +78 -0
- package/dist/xgettext/files-collector.spec.js.map +1 -0
- package/dist/xgettext/xgettext.d.ts +16 -0
- package/dist/xgettext/xgettext.js +335 -0
- package/dist/xgettext/xgettext.js.map +1 -0
- package/dist/xgettext/xgettext.spec.d.ts +1 -0
- package/dist/xgettext/xgettext.spec.js +743 -0
- package/dist/xgettext/xgettext.spec.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
var fs = __importStar(require("fs"));
|
|
38
|
+
var xgettext_1 = require("./xgettext");
|
|
39
|
+
jest.mock('fs');
|
|
40
|
+
var date = '2020-04-23 08:50+0300';
|
|
41
|
+
var readFileSync = fs.readFileSync;
|
|
42
|
+
var writeFileSync = fs.writeFileSync;
|
|
43
|
+
var warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(function () {
|
|
44
|
+
});
|
|
45
|
+
var errorSpy = jest.spyOn(global.console, 'error').mockImplementation(function () {
|
|
46
|
+
});
|
|
47
|
+
var baseArgv = {
|
|
48
|
+
$0: 'esgettext-xgettext',
|
|
49
|
+
};
|
|
50
|
+
function resetMocks() {
|
|
51
|
+
readFileSync.mockReset();
|
|
52
|
+
writeFileSync.mockReset();
|
|
53
|
+
warnSpy.mockReset();
|
|
54
|
+
errorSpy.mockReset();
|
|
55
|
+
}
|
|
56
|
+
describe('xgettext', function () {
|
|
57
|
+
describe('defaults', function () {
|
|
58
|
+
beforeEach(function () {
|
|
59
|
+
resetMocks();
|
|
60
|
+
});
|
|
61
|
+
it('should extract strings from javascript files', function () {
|
|
62
|
+
var hello = "\nconsole.log(gtx._('Hello, world!'));\n";
|
|
63
|
+
var goodbye = "\nconsole.log(gtx._('Goodbye, world!'));\n";
|
|
64
|
+
readFileSync
|
|
65
|
+
.mockReturnValueOnce(Buffer.from(hello))
|
|
66
|
+
.mockReturnValueOnce(Buffer.from(goodbye));
|
|
67
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello1.js', 'goodbye.js'] });
|
|
68
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
69
|
+
expect(xgettext.run()).toEqual(0);
|
|
70
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
71
|
+
var call = writeFileSync.mock.calls[0];
|
|
72
|
+
expect(call[0]).toEqual('messages.po');
|
|
73
|
+
expect(call[1]).toMatchSnapshot();
|
|
74
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
75
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
it('should extract strings from typescript files', function () {
|
|
78
|
+
var hello = "\nconst hello: string = gtx._('Hello, world!');\n";
|
|
79
|
+
var goodbye = "\nconst goodbye: string = gtx._('Goodbye, world!');\n";
|
|
80
|
+
readFileSync
|
|
81
|
+
.mockReturnValueOnce(Buffer.from(hello))
|
|
82
|
+
.mockReturnValueOnce(Buffer.from(goodbye));
|
|
83
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello2.ts', 'goodbye.ts'] });
|
|
84
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
85
|
+
expect(xgettext.run()).toEqual(0);
|
|
86
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
87
|
+
var call = writeFileSync.mock.calls[0];
|
|
88
|
+
expect(call[0]).toEqual('messages.po');
|
|
89
|
+
expect(call[1]).toMatchSnapshot();
|
|
90
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
91
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
it('should parse po files', function () {
|
|
94
|
+
var po = "# SOME DESCRIPTIVE TITLE\n# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n# This file is distributed under the same license as the PACKAGE package.\n# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n#, fuzzy\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Report-Msgid-Bugs-To: MSGID_BUGS_ADDRESS\\n\"\n\"POT-Creation-Date: 2020-05-25 11:50+0300\\n\"\n\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n\"Language-Team: German <de@li.org>\\n\"\n\"Language: \\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\"Plural-Forms: Plural-Forms: nplurals=2; plural=(n != 1);\\n\"\n\n#: src/cli/getopt.ts:122\n#, perl-brace-format\nmsgid \"'{programName}': unrecognized option '--{option}'\"\nmsgstr \"\"\n";
|
|
95
|
+
readFileSync.mockReturnValueOnce(Buffer.from(po));
|
|
96
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['de.po'] });
|
|
97
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
98
|
+
expect(xgettext.run()).toEqual(0);
|
|
99
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
100
|
+
var call = writeFileSync.mock.calls[0];
|
|
101
|
+
expect(call[0]).toEqual('messages.po');
|
|
102
|
+
expect(call[1]).toMatchSnapshot();
|
|
103
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
104
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
it('should parse pot files', function () {
|
|
107
|
+
var pot = "# SOME DESCRIPTIVE TITLE\n# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n# This file is distributed under the same license as the PACKAGE package.\n# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n#, fuzzy\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Report-Msgid-Bugs-To: MSGID_BUGS_ADDRESS\\n\"\n\"POT-Creation-Date: 2020-05-25 11:50+0300\\n\"\n\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n\"Language: \\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\n#: src/cli/getopt.ts:122\n#, perl-brace-format\nmsgid \"'{programName}': unrecognized option '--{option}'\"\nmsgstr \"\"\n";
|
|
108
|
+
readFileSync.mockReturnValueOnce(Buffer.from(pot));
|
|
109
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['package.pot'] });
|
|
110
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
111
|
+
expect(xgettext.run()).toEqual(0);
|
|
112
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
113
|
+
var call = writeFileSync.mock.calls[0];
|
|
114
|
+
expect(call[0]).toEqual('messages.po');
|
|
115
|
+
expect(call[1]).toMatchSnapshot();
|
|
116
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
117
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
it('should fall back to the JavaScript parser', function () {
|
|
120
|
+
var pot = "# SOME DESCRIPTIVE TITLE\n# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n# This file is distributed under the same license as the PACKAGE package.\n# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n#, fuzzy\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Report-Msgid-Bugs-To: MSGID_BUGS_ADDRESS\\n\"\n\"POT-Creation-Date: 2020-05-25 11:50+0300\\n\"\n\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n\"Language: \\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\n#: src/cli/getopt.ts:122\n#, perl-brace-format\nmsgid \"'{programName}': unrecognized option '--{option}'\"\nmsgstr \"\"\n";
|
|
121
|
+
readFileSync.mockReturnValueOnce(Buffer.from(pot));
|
|
122
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['package.xyz'] });
|
|
123
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
124
|
+
expect(xgettext.run()).toEqual(1);
|
|
125
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
126
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
127
|
+
expect(errorSpy).toHaveBeenCalled();
|
|
128
|
+
});
|
|
129
|
+
it('should fail on errors', function () {
|
|
130
|
+
var hello = 'console.log(gtx._(`Hello, ${name}!`));';
|
|
131
|
+
readFileSync.mockReturnValueOnce(Buffer.from(hello));
|
|
132
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello3.js'] });
|
|
133
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
134
|
+
expect(xgettext.run()).toEqual(1);
|
|
135
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
136
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
137
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'hello3.js:1:18-1:35: error: template literals with embedded expressions are not allowed as arguments to gettext functions because they are not constant');
|
|
139
|
+
});
|
|
140
|
+
it('should fail on exceptions', function () {
|
|
141
|
+
readFileSync.mockImplementationOnce(function () {
|
|
142
|
+
throw new Error('no such file or directory');
|
|
143
|
+
});
|
|
144
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello4.js'] });
|
|
145
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
146
|
+
expect(xgettext.run()).toEqual(1);
|
|
147
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
148
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
149
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
150
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'hello4.js: Error: no such file or directory');
|
|
151
|
+
});
|
|
152
|
+
it('should fail on output exceptions', function () {
|
|
153
|
+
var code = 'gtx._("Hello, world!");';
|
|
154
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
155
|
+
writeFileSync.mockImplementationOnce(function () {
|
|
156
|
+
throw new Error('no such file or directory');
|
|
157
|
+
});
|
|
158
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello5.js'] });
|
|
159
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
160
|
+
expect(xgettext.run()).toEqual(1);
|
|
161
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
163
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
164
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'esgettext-xgettext: Error: no such file or directory');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('xgettext command-line options and arguments', function () {
|
|
169
|
+
describe('input file location', function () {
|
|
170
|
+
describe('input file arguments', function () {
|
|
171
|
+
beforeEach(function () {
|
|
172
|
+
resetMocks();
|
|
173
|
+
});
|
|
174
|
+
it('should treat non-options as input file names', function () {
|
|
175
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'option-output.pot', _: ['here/option-output.js', 'there/option-output.js'] });
|
|
176
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
177
|
+
expect(xgettext.run()).toEqual(1);
|
|
178
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
179
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
180
|
+
expect(readFileSync.mock.calls[0][0]).toEqual('here/option-output.js');
|
|
181
|
+
expect(readFileSync.mock.calls[1][0]).toEqual('there/option-output.js');
|
|
182
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
183
|
+
expect(errorSpy).toHaveBeenCalledTimes(2);
|
|
184
|
+
});
|
|
185
|
+
it('should interpret "-" as stdin', function () {
|
|
186
|
+
var code = 'gtx._("Hello, world!")';
|
|
187
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'option-output.pot', _: ['-'] });
|
|
188
|
+
var stdinSpy = jest
|
|
189
|
+
.spyOn(global.process.stdin, 'read')
|
|
190
|
+
.mockReturnValueOnce(Buffer.from(code));
|
|
191
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
192
|
+
expect(xgettext.run()).toEqual(0);
|
|
193
|
+
expect(stdinSpy).toHaveBeenCalledTimes(1);
|
|
194
|
+
stdinSpy.mockReset();
|
|
195
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
196
|
+
expect(writeFileSync.mock.calls[0][0]).toMatchSnapshot();
|
|
197
|
+
expect(readFileSync).not.toHaveBeenCalled();
|
|
198
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
199
|
+
expect(warnSpy).toHaveBeenNthCalledWith(1, 'esgettext-xgettext: warning: language for standard' +
|
|
200
|
+
' input is unknown without option "--language";' +
|
|
201
|
+
' will try JavaScript');
|
|
202
|
+
expect(errorSpy).toHaveBeenCalledTimes(0);
|
|
203
|
+
});
|
|
204
|
+
it('should catch errors on stdin', function () {
|
|
205
|
+
var argv = __assign(__assign({}, baseArgv), { language: 'JavaScript', _: ['-'] });
|
|
206
|
+
var stdinSpy = jest
|
|
207
|
+
.spyOn(global.process.stdin, 'read')
|
|
208
|
+
.mockImplementation(function () {
|
|
209
|
+
throw new Error('I/O error');
|
|
210
|
+
});
|
|
211
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
212
|
+
expect(xgettext.run()).toEqual(1);
|
|
213
|
+
expect(stdinSpy).toHaveBeenCalledTimes(1);
|
|
214
|
+
stdinSpy.mockReset();
|
|
215
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
216
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
217
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
218
|
+
expect(errorSpy).toHaveBeenCalledWith('[standard input]: Error: I/O error');
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('option --files-from', function () {
|
|
222
|
+
beforeEach(function () { return resetMocks(); });
|
|
223
|
+
it('should accept multiple --files-from options', function () {
|
|
224
|
+
var potfiles1 = 'files-from1.js';
|
|
225
|
+
var filesFrom1 = 'gtx._("Hello, world!")';
|
|
226
|
+
var potfiles2 = 'files-from2.js';
|
|
227
|
+
var filesFrom2 = 'gtx._("Hello, world!")';
|
|
228
|
+
readFileSync
|
|
229
|
+
.mockReturnValueOnce(Buffer.from(potfiles1))
|
|
230
|
+
.mockReturnValueOnce(Buffer.from(potfiles2))
|
|
231
|
+
.mockReturnValueOnce(Buffer.from(filesFrom1))
|
|
232
|
+
.mockReturnValueOnce(Buffer.from(filesFrom2));
|
|
233
|
+
var argv = __assign(__assign({}, baseArgv), { filesFrom: ['POTFILES-1', 'POTFILES-2'], _: [] });
|
|
234
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
235
|
+
expect(xgettext.run()).toEqual(0);
|
|
236
|
+
expect(readFileSync).toHaveBeenCalledTimes(4);
|
|
237
|
+
expect(readFileSync.mock.calls[0][0]).toEqual('POTFILES-1');
|
|
238
|
+
expect(readFileSync.mock.calls[1][0]).toEqual('POTFILES-2');
|
|
239
|
+
expect(readFileSync.mock.calls[2][0]).toEqual('files-from1.js');
|
|
240
|
+
expect(readFileSync.mock.calls[3][0]).toEqual('files-from2.js');
|
|
241
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
242
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
243
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
244
|
+
});
|
|
245
|
+
it('should report errors for missing --files-from files', function () {
|
|
246
|
+
readFileSync.mockImplementation(function (filename) {
|
|
247
|
+
throw new Error("ENOENT: no such file or directory, open '".concat(filename, "'"));
|
|
248
|
+
});
|
|
249
|
+
var argv = __assign(__assign({}, baseArgv), { filesFrom: ['POTFILES'], _: [] });
|
|
250
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
251
|
+
expect(xgettext.run()).toEqual(1);
|
|
252
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
253
|
+
expect(readFileSync).toHaveBeenCalledWith('POTFILES');
|
|
254
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
255
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
256
|
+
expect(errorSpy).toHaveBeenCalledWith("esgettext-xgettext: Error: ENOENT: no such file or directory, open 'POTFILES'");
|
|
257
|
+
});
|
|
258
|
+
it('should treat "-" as standard input', function () {
|
|
259
|
+
var filesFrom1 = 'gtx._("Hello, world!")';
|
|
260
|
+
var filesFrom2 = 'gtx._("Hello, world!")';
|
|
261
|
+
readFileSync
|
|
262
|
+
.mockReturnValueOnce(Buffer.from(filesFrom1))
|
|
263
|
+
.mockReturnValueOnce(Buffer.from(filesFrom2));
|
|
264
|
+
var argv = __assign(__assign({}, baseArgv), { filesFrom: ['-'], _: [] });
|
|
265
|
+
var stdinSpy = jest
|
|
266
|
+
.spyOn(global.process.stdin, 'read')
|
|
267
|
+
.mockReturnValueOnce(Buffer.from("\nfiles-from-1.js\nfiles-from-2.js\n"));
|
|
268
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
269
|
+
expect(xgettext.run()).toEqual(0);
|
|
270
|
+
expect(stdinSpy).toHaveBeenCalledTimes(1);
|
|
271
|
+
stdinSpy.mockReset();
|
|
272
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
273
|
+
expect(readFileSync.mock.calls[0][0]).toEqual('files-from-1.js');
|
|
274
|
+
expect(readFileSync.mock.calls[1][0]).toEqual('files-from-2.js');
|
|
275
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
276
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
277
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
describe('option --directory', function () {
|
|
281
|
+
beforeEach(resetMocks);
|
|
282
|
+
it('should search for files in other directories', function () {
|
|
283
|
+
var argv = __assign(__assign({}, baseArgv), { directory: ['foo', 'bar', 'baz'], _: ['directory.js'] });
|
|
284
|
+
readFileSync.mockImplementation(function (filename) {
|
|
285
|
+
throw new Error("ENOENT: no such file or directory, open '".concat(filename, "'"));
|
|
286
|
+
});
|
|
287
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
288
|
+
expect(xgettext.run()).toEqual(1);
|
|
289
|
+
expect(readFileSync).toHaveBeenCalledTimes(3);
|
|
290
|
+
expect(readFileSync).toHaveBeenNthCalledWith(1, 'foo/directory.js');
|
|
291
|
+
expect(readFileSync).toHaveBeenNthCalledWith(2, 'bar/directory.js');
|
|
292
|
+
expect(readFileSync).toHaveBeenNthCalledWith(3, 'baz/directory.js');
|
|
293
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
294
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
295
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
296
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, "directory.js: Error: ENOENT: no such file or directory, open 'baz/directory.js'");
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
describe('output file location', function () {
|
|
301
|
+
describe('option --output', function () {
|
|
302
|
+
beforeEach(function () {
|
|
303
|
+
resetMocks();
|
|
304
|
+
});
|
|
305
|
+
it('should honor the option --output', function () {
|
|
306
|
+
var code = 'console.log(gtx._("Hello, world!"))';
|
|
307
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
308
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'option-output.pot', _: ['option-output.js'] });
|
|
309
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
310
|
+
expect(xgettext.run()).toEqual(0);
|
|
311
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
312
|
+
expect(writeFileSync.mock.calls[0][0]).toEqual('option-output.pot');
|
|
313
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
314
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
315
|
+
});
|
|
316
|
+
it('should write to stdout', function () {
|
|
317
|
+
var code = 'console.log(gtx._("Hello, world!"))';
|
|
318
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
319
|
+
var argv = __assign(__assign({}, baseArgv), { output: '-', _: ['option-output.js'] });
|
|
320
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
321
|
+
var stdoutSpy = jest
|
|
322
|
+
.spyOn(global.process.stdout, 'write')
|
|
323
|
+
.mockImplementation(function () {
|
|
324
|
+
return true;
|
|
325
|
+
});
|
|
326
|
+
expect(xgettext.run()).toEqual(0);
|
|
327
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
328
|
+
expect(stdoutSpy.mock.calls).toMatchSnapshot();
|
|
329
|
+
stdoutSpy.mockRestore();
|
|
330
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
331
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
describe('option --default-domain', function () {
|
|
335
|
+
beforeEach(function () {
|
|
336
|
+
resetMocks();
|
|
337
|
+
});
|
|
338
|
+
it('should default to "messages"', function () {
|
|
339
|
+
var code = 'gtx._("Hello, world")';
|
|
340
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
341
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['option-output.js'] });
|
|
342
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
343
|
+
expect(xgettext.run()).toEqual(0);
|
|
344
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
345
|
+
expect(writeFileSync.mock.calls[0][0]).toEqual('messages.po');
|
|
346
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
347
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
348
|
+
});
|
|
349
|
+
it('should be changed to "strings"', function () {
|
|
350
|
+
var code = 'gtx._("Hello, world")';
|
|
351
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
352
|
+
var argv = __assign(__assign({}, baseArgv), { defaultDomain: 'strings', _: ['option-output.js'] });
|
|
353
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
354
|
+
expect(xgettext.run()).toEqual(0);
|
|
355
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
356
|
+
expect(writeFileSync.mock.calls[0][0]).toEqual('strings.po');
|
|
357
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
358
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
describe('option --output-dir', function () {
|
|
362
|
+
beforeEach(function () {
|
|
363
|
+
resetMocks();
|
|
364
|
+
});
|
|
365
|
+
it('should be changed to "po"', function () {
|
|
366
|
+
var code = 'gtx._("Hello, world")';
|
|
367
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
368
|
+
var argv = __assign(__assign({}, baseArgv), { outputDir: 'po', _: ['option-output.js'] });
|
|
369
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
370
|
+
expect(xgettext.run()).toEqual(0);
|
|
371
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
372
|
+
expect(writeFileSync.mock.calls[0][0]).toEqual('po/messages.po');
|
|
373
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
374
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
describe('choice of input language', function () {
|
|
379
|
+
describe('option --language', function () {
|
|
380
|
+
afterEach(function () {
|
|
381
|
+
resetMocks();
|
|
382
|
+
});
|
|
383
|
+
it('should honor the --language option', function () {
|
|
384
|
+
var code = "# SOME DESCRIPTIVE TITLE\n# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n# This file is distributed under the same license as the PACKAGE package.\n# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n#, fuzzy\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Report-Msgid-Bugs-To: MSGID_BUGS_ADDRESS\\n\"\n\"POT-Creation-Date: 2020-05-25 11:50+0300\\n\"\n\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n\"Language: \\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\n#: src/cli/getopt.ts:122\n#, perl-brace-format\nmsgid \"'{programName}': unrecognized option '--{option}'\"\nmsgstr \"\"\n";
|
|
385
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
386
|
+
var argv = __assign(__assign({}, baseArgv), { language: 'javascript', _: ['hello6.pot'] });
|
|
387
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
388
|
+
expect(xgettext.run()).toEqual(1);
|
|
389
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
390
|
+
expect(errorSpy).toHaveBeenCalled();
|
|
391
|
+
});
|
|
392
|
+
it('should bail out on unknown languages', function () {
|
|
393
|
+
var code = "gtx._('Hello, world!)";
|
|
394
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
395
|
+
var argv = __assign(__assign({}, baseArgv), { language: 'VBScript', _: ['hello7.js'] });
|
|
396
|
+
expect(function () { return new xgettext_1.XGettext(argv, date); }).toThrow('language "VBScript" unknown');
|
|
397
|
+
});
|
|
398
|
+
it('should accept the language typescript', function () {
|
|
399
|
+
var code = 'gtx._("Hello, world!");';
|
|
400
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
401
|
+
var argv = __assign(__assign({}, baseArgv), { language: 'TypeScript', _: ['hello-language-typescript.ts'] });
|
|
402
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
403
|
+
expect(xgettext.run()).toEqual(0);
|
|
404
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
405
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
406
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
407
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
describe('operation mode', function () {
|
|
412
|
+
describe('option --join-existing', function () {
|
|
413
|
+
beforeEach(resetMocks);
|
|
414
|
+
it('should merge into the output file regardless of language', function () {
|
|
415
|
+
var existing = "\nmsgid \"existing\"\nmsgstr \"\"\n";
|
|
416
|
+
readFileSync.mockReturnValueOnce(Buffer.from(existing));
|
|
417
|
+
var code = 'gtx._("new")';
|
|
418
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
419
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'package.pot', language: 'javascript', joinExisting: true, _: ['join-existing1.js'] });
|
|
420
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
421
|
+
expect(xgettext.run()).toEqual(0);
|
|
422
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
423
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
424
|
+
expect(writeFileSync.mock.calls[0][0]).toEqual('package.pot');
|
|
425
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
426
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
427
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
428
|
+
});
|
|
429
|
+
it('should bail out, when output is stdout', function () {
|
|
430
|
+
var argv = __assign(__assign({}, baseArgv), { output: '-', language: 'javascript', joinExisting: true, _: ['join-existing2.js'] });
|
|
431
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
432
|
+
expect(xgettext.run()).toEqual(1);
|
|
433
|
+
expect(readFileSync).not.toHaveBeenCalled();
|
|
434
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
435
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
436
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
437
|
+
expect(errorSpy).toHaveBeenCalledWith('esgettext-xgettext: error: --join-existing cannot be used, when output is written to stdout');
|
|
438
|
+
});
|
|
439
|
+
it('should report exceptions', function () {
|
|
440
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'package.pot', language: 'javascript', joinExisting: true, _: ['join-existing3.js'] });
|
|
441
|
+
readFileSync.mockImplementationOnce(function () {
|
|
442
|
+
throw new Error('no such file or directory');
|
|
443
|
+
});
|
|
444
|
+
readFileSync.mockReturnValueOnce(Buffer.from(''));
|
|
445
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
446
|
+
expect(xgettext.run()).toEqual(1);
|
|
447
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
448
|
+
expect(readFileSync).toHaveBeenNthCalledWith(1, 'package.pot');
|
|
449
|
+
expect(readFileSync).toHaveBeenNthCalledWith(2, 'join-existing3.js');
|
|
450
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
451
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
452
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
453
|
+
expect(errorSpy).toHaveBeenCalledWith('package.pot: Error: no such file or directory');
|
|
454
|
+
});
|
|
455
|
+
it('should report parser errors', function () {
|
|
456
|
+
var existing = "\nmsgidError \"existing\"\nmsgstr \"\"\n";
|
|
457
|
+
readFileSync.mockReturnValueOnce(Buffer.from(existing));
|
|
458
|
+
var code = 'gtx._("new")';
|
|
459
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
460
|
+
var argv = __assign(__assign({}, baseArgv), { output: 'package.pot', language: 'javascript', joinExisting: true, _: ['join-existing1.js'] });
|
|
461
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
462
|
+
expect(xgettext.run()).toEqual(1);
|
|
463
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
464
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
465
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
466
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
467
|
+
expect(errorSpy).toHaveBeenCalledWith('package.pot:2:1: error: keyword "msgidError" unknown');
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
describe('option --exclude-file', function () {
|
|
471
|
+
beforeEach(resetMocks);
|
|
472
|
+
it('should exclude entries from the reference pots', function () {
|
|
473
|
+
var exclude1 = "\nmsgid \"exclude 1\"\nmsgstr \"\"\n";
|
|
474
|
+
var exclude2 = "\nmsgid \"exclude 2\"\nmsgstr \"\"\n";
|
|
475
|
+
var code = "\ngtx._(\"exclude 1\");\ngtx._(\"exclude 2\");\ngtx._(\"catch me!\");\n";
|
|
476
|
+
readFileSync.mockReturnValueOnce(Buffer.from(exclude1));
|
|
477
|
+
readFileSync.mockReturnValueOnce(Buffer.from(exclude2));
|
|
478
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
479
|
+
var argv = __assign(__assign({}, baseArgv), { excludeFile: ['exclude1.pot', 'exclude2.pot'], _: ['exclude-file1.js'] });
|
|
480
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
481
|
+
expect(xgettext.run()).toEqual(0);
|
|
482
|
+
expect(readFileSync).toHaveBeenCalledTimes(3);
|
|
483
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
484
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
485
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
486
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
487
|
+
});
|
|
488
|
+
it('should report i/o errors for the reference pots', function () {
|
|
489
|
+
readFileSync.mockImplementation(function () {
|
|
490
|
+
throw new Error('ouch!');
|
|
491
|
+
});
|
|
492
|
+
var argv = __assign(__assign({}, baseArgv), { excludeFile: ['exclude1.pot', 'exclude2.pot'], _: ['exclude-file1.js'] });
|
|
493
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
494
|
+
expect(xgettext.run()).toEqual(1);
|
|
495
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
496
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
497
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
498
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
499
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'esgettext-xgettext: error: ouch!');
|
|
500
|
+
});
|
|
501
|
+
it('should report parsing errors for the reference pots', function () {
|
|
502
|
+
readFileSync.mockReturnValue(Buffer.from('invalid'));
|
|
503
|
+
var argv = __assign(__assign({}, baseArgv), { excludeFile: ['exclude1.pot', 'exclude2.pot'], _: ['exclude-file1.js'] });
|
|
504
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
505
|
+
expect(xgettext.run()).toEqual(1);
|
|
506
|
+
expect(readFileSync).toHaveBeenCalledTimes(2);
|
|
507
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
508
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
509
|
+
expect(errorSpy).toHaveBeenCalledTimes(4);
|
|
510
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'exclude1.pot:1:1: error: keyword "invalid" unknown');
|
|
511
|
+
expect(errorSpy).toHaveBeenNthCalledWith(2, 'exclude1.pot:1:8: error: syntax error');
|
|
512
|
+
expect(errorSpy).toHaveBeenNthCalledWith(3, 'exclude2.pot:1:1: error: keyword "invalid" unknown');
|
|
513
|
+
expect(errorSpy).toHaveBeenNthCalledWith(4, 'exclude2.pot:1:8: error: syntax error');
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
describe('add-comments', function () {
|
|
517
|
+
beforeEach(resetMocks);
|
|
518
|
+
it('should add selected comments', function () {
|
|
519
|
+
var code = "\n// TRANSLATORS: The abbreviated day of the week, not our star.\ngtx._(\"Sun\");\n\n// TESTERS: This must be translated!\ngtx._(\"Hello, world!\");\n\n// DEVELOPERS: Don't repeat yourself.\ngtx._(\"Copy & Paste\");\n";
|
|
520
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
521
|
+
var argv = __assign(__assign({}, baseArgv), { addComments: ['TRANSLATORS:', 'TESTERS:'], _: ['add-comments.js'] });
|
|
522
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
523
|
+
expect(xgettext.run()).toEqual(0);
|
|
524
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
525
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
526
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
527
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
describe('add-all-comments', function () {
|
|
531
|
+
beforeEach(resetMocks);
|
|
532
|
+
it('should add all comments', function () {
|
|
533
|
+
var code = "\n// TRANSLATORS: The abbreviated day of the week, not our star.\ngtx._(\"Sun\");\n\n// TESTERS: This must be translated!\ngtx._(\"Hello, world!\");\n\n// DEVELOPERS: Don't repeat yourself.\ngtx._(\"Copy & Paste\");\n";
|
|
534
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
535
|
+
var argv = __assign(__assign({}, baseArgv), { addAllComments: true, _: ['add-comments.js'] });
|
|
536
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
537
|
+
expect(xgettext.run()).toEqual(0);
|
|
538
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
539
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
540
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
541
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
describe('language specific options', function () {
|
|
546
|
+
describe('--extract-all', function () {
|
|
547
|
+
beforeEach(resetMocks);
|
|
548
|
+
it('should extract all strings', function () {
|
|
549
|
+
var code = "\ngtx._(\"gettext function\");\nconsole.log(\"non-gettext-function\");\n";
|
|
550
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
551
|
+
var argv = __assign(__assign({}, baseArgv), { extractAll: true, _: ['extract-all.js'] });
|
|
552
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
553
|
+
expect(xgettext.run()).toEqual(0);
|
|
554
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
555
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
556
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
557
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
describe('--keyword', function () {
|
|
561
|
+
beforeEach(resetMocks);
|
|
562
|
+
it('should extract the selected keywords', function () {
|
|
563
|
+
var code = "\ngtx._(\"ignore\");\ngettext(\"catch\");\nnpgettext(\"context\", \"one file\", \"multiple files\", 2304);\n";
|
|
564
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
565
|
+
var argv = __assign(__assign({}, baseArgv), { keyword: ['', 'gettext', 'npgettext:1c,2,3'], _: ['keyword.js'] });
|
|
566
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
567
|
+
expect(xgettext.run()).toEqual(0);
|
|
568
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
569
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
570
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
571
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
describe('output details', function () {
|
|
576
|
+
describe('option --force-po', function () {
|
|
577
|
+
beforeEach(resetMocks);
|
|
578
|
+
it('should not write empty catalogs', function () {
|
|
579
|
+
var code = 'console.log("Hello, world!")';
|
|
580
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
581
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['force-po1.js'] });
|
|
582
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
583
|
+
expect(xgettext.run()).toEqual(0);
|
|
584
|
+
expect(writeFileSync).not.toHaveBeenCalled();
|
|
585
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
586
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
587
|
+
});
|
|
588
|
+
it('should write empty catalogs with option --force-po', function () {
|
|
589
|
+
var code = 'console.log("Hello, world!")';
|
|
590
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
591
|
+
var argv = __assign(__assign({}, baseArgv), { forcePo: true, _: ['force-po1.js'] });
|
|
592
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
593
|
+
expect(xgettext.run()).toEqual(0);
|
|
594
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
595
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
596
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
597
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
describe('option --width', function () {
|
|
601
|
+
beforeEach(resetMocks);
|
|
602
|
+
it('should honor the option --width', function () {
|
|
603
|
+
var code = 'gtx._("For a very long time! For a very long time!")';
|
|
604
|
+
readFileSync.mockReturnValue(Buffer.from(code));
|
|
605
|
+
var argv = __assign(__assign({}, baseArgv), { width: 25, _: ['width.js'] });
|
|
606
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
607
|
+
expect(xgettext.run()).toEqual(0);
|
|
608
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
609
|
+
expect(writeFileSync.mock.calls[0][1]).toMatchSnapshot();
|
|
610
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
611
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
describe('xgettext encodings', function () {
|
|
617
|
+
describe('ascii', function () {
|
|
618
|
+
beforeEach(resetMocks);
|
|
619
|
+
it('should accept plain ascii by default', function () {
|
|
620
|
+
var code = 'gtx._("Hello, world!");';
|
|
621
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
622
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello-ascii.js'] });
|
|
623
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
624
|
+
expect(xgettext.run()).toEqual(0);
|
|
625
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
626
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
627
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
628
|
+
});
|
|
629
|
+
it('should complain about 8 bit characters', function () {
|
|
630
|
+
var code = "\ngtx._(\"Hello, world!\");\n";
|
|
631
|
+
var buf = Buffer.from(code).map(function (c) { return (c === 0x6f ? 0xf6 : c); });
|
|
632
|
+
readFileSync.mockReturnValueOnce(buf);
|
|
633
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hello-ascii.js'] });
|
|
634
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
635
|
+
expect(xgettext.run()).toEqual(1);
|
|
636
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
637
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
638
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
639
|
+
expect(errorSpy)
|
|
640
|
+
.toHaveBeenCalledWith("hello-ascii.js:2:12: error: Non-ASCII character.\nPlease specify the encoding through \"--from-code\".");
|
|
641
|
+
});
|
|
642
|
+
it('should accept 8 bit characters with iso-8859-1', function () {
|
|
643
|
+
var code = "\ngtx._(\"Hello, world!\");\n";
|
|
644
|
+
var buf = Buffer.from(code).map(function (c) { return (c === 0x6f ? 0xf6 : c); });
|
|
645
|
+
readFileSync.mockReturnValueOnce(buf);
|
|
646
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'iso-8859-1', _: ['hello-ascii.js'] });
|
|
647
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
648
|
+
expect(xgettext.run()).toEqual(0);
|
|
649
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
650
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
651
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
652
|
+
expect(writeFileSync.mock.calls[0]).toMatchSnapshot();
|
|
653
|
+
});
|
|
654
|
+
it('should accept ASCII-8bit as an alias for ASCII', function () {
|
|
655
|
+
var code = "gtx._(\"Hyv\u00E4\u00E4 y\u00F6t\u00E4!\")";
|
|
656
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
657
|
+
var argv = __assign(__assign({}, baseArgv), { _: ['hyvää-yötä.js'] });
|
|
658
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
659
|
+
expect(xgettext.run()).toEqual(1);
|
|
660
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
661
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
662
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
663
|
+
expect(errorSpy)
|
|
664
|
+
.toHaveBeenCalledWith("hyv\u00E4\u00E4-y\u00F6t\u00E4.js:1:11: error: Non-ASCII character.\nPlease specify the encoding through \"--from-code\".");
|
|
665
|
+
});
|
|
666
|
+
it('should accept US-ASCII as an alias for ASCII', function () {
|
|
667
|
+
var code = "gtx._(\"Hyv\u00E4\u00E4 y\u00F6t\u00E4!\")";
|
|
668
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
669
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'US-ASCII', _: ['hyvää-yötä.js'] });
|
|
670
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
671
|
+
expect(xgettext.run()).toEqual(1);
|
|
672
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
673
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
674
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
675
|
+
expect(errorSpy)
|
|
676
|
+
.toHaveBeenCalledWith("hyv\u00E4\u00E4-y\u00F6t\u00E4.js:1:11: error: Non-ASCII character.\nPlease specify the encoding through \"--from-code\".");
|
|
677
|
+
});
|
|
678
|
+
it('should accept ANSI_X3.4-1968 as an alias for ASCII', function () {
|
|
679
|
+
var code = "gtx._(\"Hyv\u00E4\u00E4 y\u00F6t\u00E4!\")";
|
|
680
|
+
readFileSync.mockReturnValueOnce(Buffer.from(code));
|
|
681
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'ANSI_X3.4-1968', _: ['hyvää-yötä.js'] });
|
|
682
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
683
|
+
expect(xgettext.run()).toEqual(1);
|
|
684
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
685
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
686
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
687
|
+
expect(errorSpy)
|
|
688
|
+
.toHaveBeenCalledWith("hyv\u00E4\u00E4-y\u00F6t\u00E4.js:1:11: error: Non-ASCII character.\nPlease specify the encoding through \"--from-code\".");
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
describe('utf-8', function () {
|
|
692
|
+
beforeEach(resetMocks);
|
|
693
|
+
it('should accept valid utf-8', function () {
|
|
694
|
+
var code = "\ngtx._('Hyv\u00E4\u00E4, y\u00F6t\u00E4!');\ngtx._('\u0414\u043E\u0431\u0440\u043E, \u0443\u0442\u0440\u043E!');\ngtx._('\uD83D\uDE00');\ngtx._('\uC88B\uC740 \uC544\uCE68!');\n// Some random chars for better test coverage.\ngtx._('\u0AAA\uD208');\ngtx._('\uD8E0\uDE08\uDBE0\uDE08');\n";
|
|
695
|
+
var buf = Buffer.from(code);
|
|
696
|
+
readFileSync.mockReturnValueOnce(buf);
|
|
697
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'utf-8', _: ['hello-ascii.js'] });
|
|
698
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
699
|
+
expect(xgettext.run()).toEqual(0);
|
|
700
|
+
expect(writeFileSync).toHaveBeenCalledTimes(1);
|
|
701
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
702
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
703
|
+
});
|
|
704
|
+
it('should complain about a lone 8-bit byte', function () {
|
|
705
|
+
var code = "\ngtx._(\"Hello, world!\");\n";
|
|
706
|
+
var buf = Buffer.from(code).map(function (c) { return (c === 0x6f ? 0xf6 : c); });
|
|
707
|
+
readFileSync.mockReturnValueOnce(buf);
|
|
708
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'utf-8', _: ['hello-ascii.js'] });
|
|
709
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
710
|
+
expect(xgettext.run()).toEqual(1);
|
|
711
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
712
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
713
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
714
|
+
expect(errorSpy).toHaveBeenCalledWith('hello-ascii.js:2:12: error: invalid multibyte sequence');
|
|
715
|
+
});
|
|
716
|
+
it('should complain about invalid charsets', function () {
|
|
717
|
+
var code = "\ngtx._(\"Hello, world!\");\n";
|
|
718
|
+
var buf = Buffer.from(code);
|
|
719
|
+
readFileSync.mockReturnValueOnce(buf);
|
|
720
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'no-such-charset', _: ['hello-ascii.js'] });
|
|
721
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
722
|
+
expect(xgettext.run()).toEqual(1);
|
|
723
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
724
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
725
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
726
|
+
});
|
|
727
|
+
it('should complain about invalid charsets converting stanard input', function () {
|
|
728
|
+
var code = "\ngtx._(\"Hello, world!\");\n";
|
|
729
|
+
var argv = __assign(__assign({}, baseArgv), { fromCode: 'no-such-charset', language: 'javascript', _: ['-'] });
|
|
730
|
+
var stdinSpy = jest
|
|
731
|
+
.spyOn(global.process.stdin, 'read')
|
|
732
|
+
.mockReturnValueOnce(Buffer.from(code));
|
|
733
|
+
var xgettext = new xgettext_1.XGettext(argv, date);
|
|
734
|
+
expect(xgettext.run()).toEqual(1);
|
|
735
|
+
expect(stdinSpy).toHaveBeenCalledTimes(1);
|
|
736
|
+
stdinSpy.mockReset();
|
|
737
|
+
expect(writeFileSync).toHaveBeenCalledTimes(0);
|
|
738
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
739
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
//# sourceMappingURL=xgettext.spec.js.map
|