Skip to content

Commit

Permalink
add test for .po files with no header
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Petty committed Aug 29, 2016
1 parent 2ba0779 commit 13be2c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ module.exports = function(buffer, options) {
});

// Attach headers (overwrites any empty translation keys that may have somehow gotten in)
result[''] = parsed.headers;
if (parsed.headers) {
result[''] = parsed.headers;
}

if (options.format === 'mf') {
delete result[''];
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/en-no-header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Hello World": [
null,
"Hello World"
]
}
4 changes: 4 additions & 0 deletions test/fixtures/en-no-header.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Very minimal .po

msgid "Hello World"
msgstr "Hello World"
14 changes: 14 additions & 0 deletions test/po2json_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,17 @@ module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = {
test.done();
}
}

module.exports["parse with no headers"] ={
setUp: function(callback){
this.po = fs.readFileSync(__dirname + "/fixtures/en-no-header.po");
this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-no-header.json", "utf-8"));
callback();
},

parse: function(test){
var parsed = po2json.parse(this.po);
test.deepEqual(parsed, this.json);
test.done();
}
}

0 comments on commit 13be2c9

Please sign in to comment.