Skip to content

Commit

Permalink
add tests for previous PR
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumepotier committed Dec 11, 2023
1 parent e44def2 commit 6db14c1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules/*
tests/*.json
8 changes: 7 additions & 1 deletion bin/po2json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --no-deprecation

/*
po2json wrapper for gettext.js
Expand Down Expand Up @@ -47,8 +47,14 @@ fs.readFile(argv[2], function (err, buffer) {
continue;
}

console.log(key, jsonData[key]);

// Do not dump untranslated keys, they already are in the templates!
<<<<<<< Updated upstream
if ('' !== jsonData[key][1].length ? jsonData[key][1][0] : jsonData[key][1])
=======
if ('' !== (jsonData[key][1].length ? jsonData[key][1][0] : jsonData[key][1]))
>>>>>>> Stashed changes
json[key] = 2 === jsonData[key].length ? jsonData[key][1] : jsonData[key].slice(1);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.0.0",
"license": "MIT",
"scripts": {
"test": "karma start tests/karma.config.js",
"test": "karma start tests/karma.config.js && node tests/po2json.test.js",
"test-dev": "karma start tests/karma.config.dev.js",
"build": "./node_modules/.bin/gulp"
},
Expand Down
11 changes: 11 additions & 0 deletions tests/another.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

msgid "foo"
msgstr "bar"

msgid "{count} foo"
msgid_plural "{count} foos"
msgstr[0] ""
msgstr[1] ""
28 changes: 28 additions & 0 deletions tests/po2json.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// execute bin/po2json on tests/test.po
// and compare the result with tests/test.json
var exec = require("child_process").exec;

exec('node ' + __dirname + '/../bin/po2json ' + __dirname + '/test.po ' + __dirname + '/test.json', function (error, stdout, stderr) {
var fs = require('fs');
var dumped = JSON.parse(fs.readFileSync(__dirname + '/test.json', 'utf8'));

// validate that the dumped json is correct
if (dumped[''] && dumped['']['plural-forms'] && dumped['foo'] && !dumped['%1 foo']) {
console.log('dumped json is correct!');
} else {
console.log('dumped json is incorrect :(');
}
});


exec('node ' + __dirname + '/../bin/po2json ' + __dirname + '/another.po ' + __dirname + '/another.json', function (error, stdout, stderr) {
var fs = require('fs');
var dumped = JSON.parse(fs.readFileSync(__dirname + '/another.json', 'utf8'));

// validate that the dumped json is correct
if (dumped[''] && dumped['']['plural-forms'] && dumped['foo'] && !dumped['%1 foo']) {
console.log('dumped json is correct!');
} else {
console.log('dumped json is incorrect :(');
}
});
10 changes: 10 additions & 0 deletions tests/test.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=1; plural=0;\n"

msgid "foo"
msgstr "bar"

msgid "%1 foo"
msgid_plural "%1 foos"
msgstr[0] ""

0 comments on commit 6db14c1

Please sign in to comment.