Spaces:
Running
Running
File size: 1,911 Bytes
30c32c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
const test = require('tap').test;
const maybeFormatMessage = require('../../src/util/maybe-format-message');
const nonMessages = [
'hi',
42,
true,
function () {
return 'unused';
},
{
a: 1,
b: 2
},
{
id: 'almost a message',
notDefault: 'but missing the "default" property'
},
{
notId: 'this one is missing the "id" property',
default: 'but has "default"'
}
];
const argsQuick = {
speed: 'quick'
};
const argsOther = {
speed: 'slow'
};
const argsEmpty = {};
const simpleMessage = {
id: 'test.simpleMessage',
default: 'The quick brown fox jumped over the lazy dog.'
};
const complexMessage = {
id: 'test.complexMessage',
default: '{speed, select, quick {The quick brown fox jumped over the lazy dog.} other {Too slow, Gobo!}}'
};
const quickExpectedResult = 'The quick brown fox jumped over the lazy dog.';
const otherExpectedResult = 'Too slow, Gobo!';
test('preserve non-messages', t => {
t.plan(nonMessages.length);
for (const x of nonMessages) {
const result = maybeFormatMessage(x);
t.strictSame(x, result);
}
t.end();
});
test('format messages', t => {
const quickResult1 = maybeFormatMessage(simpleMessage);
t.strictNotSame(quickResult1, simpleMessage);
t.same(quickResult1, quickExpectedResult);
const quickResult2 = maybeFormatMessage(complexMessage, argsQuick);
t.strictNotSame(quickResult2, complexMessage);
t.same(quickResult2, quickExpectedResult);
const otherResult1 = maybeFormatMessage(complexMessage, argsOther);
t.strictNotSame(otherResult1, complexMessage);
t.same(otherResult1, otherExpectedResult);
const otherResult2 = maybeFormatMessage(complexMessage, argsEmpty);
t.strictNotSame(otherResult2, complexMessage);
t.same(otherResult2, otherExpectedResult);
t.end();
});
|