Only write flags when they evaluate to true.
This commit is contained in:
parent
db5e540824
commit
104d114d5d
4
dist/pofile.js
vendored
4
dist/pofile.js
vendored
@ -290,7 +290,9 @@ PO.Item.prototype.toString = function () {
|
||||
lines.push('#: ' + ref);
|
||||
});
|
||||
|
||||
var flags = Object.keys(this.flags);
|
||||
var flags = Object.keys(this.flags).filter(function (flag) {
|
||||
return !!this.flags[flag];
|
||||
}, this);
|
||||
if (flags.length > 0) {
|
||||
lines.push('#, ' + flags.join(','));
|
||||
}
|
||||
|
2
dist/pofile.min.js
vendored
2
dist/pofile.min.js
vendored
File diff suppressed because one or more lines are too long
@ -289,7 +289,9 @@ PO.Item.prototype.toString = function () {
|
||||
lines.push('#: ' + ref);
|
||||
});
|
||||
|
||||
var flags = Object.keys(this.flags);
|
||||
var flags = Object.keys(this.flags).filter(function (flag) {
|
||||
return !!this.flags[flag];
|
||||
}, this);
|
||||
if (flags.length > 0) {
|
||||
lines.push('#, ' + flags.join(','));
|
||||
}
|
||||
|
@ -16,6 +16,20 @@ function assertHasLine(str, line) {
|
||||
assert(found, 'Could not find line: ' + line);
|
||||
}
|
||||
|
||||
function assertDoesntHaveLine(str, line) {
|
||||
var lines = str.split('\n');
|
||||
var found = false;
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
if (lines[i].trim() === line) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(!found, 'Shouldn\'t have line: ' + line);
|
||||
}
|
||||
|
||||
describe('Write', function () {
|
||||
it('write flags', function () {
|
||||
var input = fs.readFileSync(__dirname + '/fixtures/fuzzy.po', 'utf8');
|
||||
@ -24,6 +38,17 @@ describe('Write', function () {
|
||||
assertHasLine(str, '#, fuzzy');
|
||||
});
|
||||
|
||||
it('write flags only when true', function () {
|
||||
var input = fs.readFileSync(__dirname + '/fixtures/fuzzy.po', 'utf8');
|
||||
var po = PO.parse(input);
|
||||
|
||||
// Flip flag
|
||||
po.items[0].flags.fuzzy = false;
|
||||
|
||||
var str = po.toString();
|
||||
assertDoesntHaveLine(str, '#, fuzzy');
|
||||
});
|
||||
|
||||
it('write msgid', function () {
|
||||
var input = fs.readFileSync(__dirname + '/fixtures/fuzzy.po', 'utf8');
|
||||
var po = PO.parse(input);
|
||||
|
Loading…
Reference in New Issue
Block a user