Skip to content

Commit d9dfd07

Browse files
committed
Print braces around FluentNone
1 parent 326b6ee commit d9dfd07

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

fluent/src/types.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ export class FluentType {
4545
}
4646

4747
export class FluentNone extends FluentType {
48+
valueOf() {
49+
return null;
50+
}
51+
4852
toString() {
49-
return this.value || "???";
53+
return `{${this.value || "???"}}`;
5054
}
5155
}
5256

fluent/test/arguments_test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,49 +101,49 @@ suite('Variables', function() {
101101
test('falls back to argument\'s name if it\'s missing', function() {
102102
const msg = bundle.getMessage('foo');
103103
const val = bundle.format(msg, {}, errs);
104-
assert.equal(val, '$arg');
104+
assert.equal(val, '{$arg}');
105105
assert(errs[0] instanceof ReferenceError); // unknown variable
106106
});
107107

108108
test('cannot be arrays', function() {
109109
const msg = bundle.getMessage('foo');
110110
const val = bundle.format(msg, { arg: [1, 2, 3] }, errs);
111-
assert.equal(val, '$arg');
111+
assert.equal(val, '{$arg}');
112112
assert(errs[0] instanceof TypeError); // unsupported variable type
113113
});
114114

115115
test('cannot be a dict-like object', function() {
116116
const msg = bundle.getMessage('foo');
117117
const val = bundle.format(msg, { arg: { prop: 1 } }, errs);
118-
assert.equal(val, '$arg');
118+
assert.equal(val, '{$arg}');
119119
assert(errs[0] instanceof TypeError); // unsupported variable type
120120
});
121121

122122
test('cannot be a boolean', function() {
123123
const msg = bundle.getMessage('foo');
124124
const val = bundle.format(msg, { arg: true }, errs);
125-
assert.equal(val, '$arg');
125+
assert.equal(val, '{$arg}');
126126
assert(errs[0] instanceof TypeError); // unsupported variable type
127127
});
128128

129129
test('cannot be undefined', function() {
130130
const msg = bundle.getMessage('foo');
131131
const val = bundle.format(msg, { arg: undefined }, errs);
132-
assert.equal(val, '$arg');
132+
assert.equal(val, '{$arg}');
133133
assert(errs[0] instanceof TypeError); // unsupported variable type
134134
});
135135

136136
test('cannot be null', function() {
137137
const msg = bundle.getMessage('foo');
138138
const val = bundle.format(msg, { arg: null }, errs);
139-
assert.equal(val, '$arg');
139+
assert.equal(val, '{$arg}');
140140
assert(errs[0] instanceof TypeError); // unsupported variable type
141141
});
142142

143143
test('cannot be a function', function() {
144144
const msg = bundle.getMessage('foo');
145145
const val = bundle.format(msg, { arg: () => null }, errs);
146-
assert.equal(val, '$arg');
146+
assert.equal(val, '{$arg}');
147147
assert(errs[0] instanceof TypeError); // unsupported variable type
148148
});
149149
});

fluent/test/functions_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite('Functions', function() {
2323
test('falls back to the name of the function', function() {
2424
const msg = bundle.getMessage('foo');
2525
const val = bundle.format(msg, args, errs);
26-
assert.equal(val, 'MISSING()');
26+
assert.equal(val, '{MISSING()}');
2727
assert.equal(errs.length, 1);
2828
assert(errs[0] instanceof ReferenceError); // unknown function
2929
});

fluent/test/macros_test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ suite("Macros", function() {
5757
test("Not parameterized, no externals", function() {
5858
const msg = bundle.getMessage("ref-foo");
5959
const val = bundle.format(msg, {}, errs);
60-
assert.equal(val, "Foo $arg");
60+
assert.equal(val, "Foo {$arg}");
6161
assert.equal(errs.length, 0);
6262
});
6363

6464
test("Not parameterized but with externals", function() {
6565
const msg = bundle.getMessage("ref-foo");
6666
const val = bundle.format(msg, {arg: 1}, errs);
67-
assert.equal(val, "Foo $arg");
67+
assert.equal(val, "Foo {$arg}");
6868
assert.equal(errs.length, 0);
6969
});
7070

7171
test("No arguments, no externals", function() {
7272
const msg = bundle.getMessage("call-foo-no-args");
7373
const val = bundle.format(msg, {}, errs);
74-
assert.equal(val, "Foo $arg");
74+
assert.equal(val, "Foo {$arg}");
7575
assert.equal(errs.length, 0);
7676
});
7777

7878
test("No arguments, but with externals", function() {
7979
const msg = bundle.getMessage("call-foo-no-args");
8080
const val = bundle.format(msg, {arg: 1}, errs);
81-
assert.equal(val, "Foo $arg");
81+
assert.equal(val, "Foo {$arg}");
8282
assert.equal(errs.length, 0);
8383
});
8484

@@ -99,14 +99,14 @@ suite("Macros", function() {
9999
test("With other args, no externals", function() {
100100
const msg = bundle.getMessage("call-foo-with-other-arg");
101101
const val = bundle.format(msg, {}, errs);
102-
assert.equal(val, "Foo $arg");
102+
assert.equal(val, "Foo {$arg}");
103103
assert.equal(errs.length, 0);
104104
});
105105

106106
test("With other args, and with externals", function() {
107107
const msg = bundle.getMessage("call-foo-with-other-arg");
108108
const val = bundle.format(msg, {arg: 5}, errs);
109-
assert.equal(val, "Foo $arg");
109+
assert.equal(val, "Foo {$arg}");
110110
assert.equal(errs.length, 0);
111111
});
112112
});
@@ -128,28 +128,28 @@ suite("Macros", function() {
128128
test("No parameterization, no externals", function() {
129129
const msg = bundle.getMessage("ref-bar");
130130
const val = bundle.format(msg, {}, errs);
131-
assert.equal(val, "Foo $arg");
131+
assert.equal(val, "Foo {$arg}");
132132
assert.equal(errs.length, 0);
133133
});
134134

135135
test("No parameterization, but with externals", function() {
136136
const msg = bundle.getMessage("ref-bar");
137137
const val = bundle.format(msg, {arg: 5}, errs);
138-
assert.equal(val, "Foo $arg");
138+
assert.equal(val, "Foo {$arg}");
139139
assert.equal(errs.length, 0);
140140
});
141141

142142
test("No arguments, no externals", function() {
143143
const msg = bundle.getMessage("call-bar");
144144
const val = bundle.format(msg, {}, errs);
145-
assert.equal(val, "Foo $arg");
145+
assert.equal(val, "Foo {$arg}");
146146
assert.equal(errs.length, 0);
147147
});
148148

149149
test("No arguments, but with externals", function() {
150150
const msg = bundle.getMessage("call-bar");
151151
const val = bundle.format(msg, {arg: 5}, errs);
152-
assert.equal(val, "Foo $arg");
152+
assert.equal(val, "Foo {$arg}");
153153
assert.equal(errs.length, 0);
154154
});
155155

@@ -197,28 +197,28 @@ suite("Macros", function() {
197197
test("No parameterization, no parameterization, no externals", function() {
198198
const msg = bundle.getMessage("ref-bar");
199199
const val = bundle.format(msg, {}, errs);
200-
assert.equal(val, "Foo $arg");
200+
assert.equal(val, "Foo {$arg}");
201201
assert.equal(errs.length, 0);
202202
});
203203

204204
test("No parameterization, no parameterization, with externals", function() {
205205
const msg = bundle.getMessage("ref-bar");
206206
const val = bundle.format(msg, {arg: 5}, errs);
207-
assert.equal(val, "Foo $arg");
207+
assert.equal(val, "Foo {$arg}");
208208
assert.equal(errs.length, 0);
209209
});
210210

211211
test("No parameterization, no arguments, no externals", function() {
212212
const msg = bundle.getMessage("ref-baz");
213213
const val = bundle.format(msg, {}, errs);
214-
assert.equal(val, "Foo $arg");
214+
assert.equal(val, "Foo {$arg}");
215215
assert.equal(errs.length, 0);
216216
});
217217

218218
test("No parameterization, no arguments, with externals", function() {
219219
const msg = bundle.getMessage("ref-baz");
220220
const val = bundle.format(msg, {arg: 5}, errs);
221-
assert.equal(val, "Foo $arg");
221+
assert.equal(val, "Foo {$arg}");
222222
assert.equal(errs.length, 0);
223223
});
224224

@@ -239,28 +239,28 @@ suite("Macros", function() {
239239
test("No arguments, no parameterization, no externals", function() {
240240
const msg = bundle.getMessage("call-bar-no-args");
241241
const val = bundle.format(msg, {}, errs);
242-
assert.equal(val, "Foo $arg");
242+
assert.equal(val, "Foo {$arg}");
243243
assert.equal(errs.length, 0);
244244
});
245245

246246
test("No arguments, no parameterization, with externals", function() {
247247
const msg = bundle.getMessage("call-bar-no-args");
248248
const val = bundle.format(msg, {arg: 5}, errs);
249-
assert.equal(val, "Foo $arg");
249+
assert.equal(val, "Foo {$arg}");
250250
assert.equal(errs.length, 0);
251251
});
252252

253253
test("No arguments, no arguments, no externals", function() {
254254
const msg = bundle.getMessage("call-baz-no-args");
255255
const val = bundle.format(msg, {}, errs);
256-
assert.equal(val, "Foo $arg");
256+
assert.equal(val, "Foo {$arg}");
257257
assert.equal(errs.length, 0);
258258
});
259259

260260
test("No arguments, no arguments, with externals", function() {
261261
const msg = bundle.getMessage("call-baz-no-args");
262262
const val = bundle.format(msg, {arg: 5}, errs);
263-
assert.equal(val, "Foo $arg");
263+
assert.equal(val, "Foo {$arg}");
264264
assert.equal(errs.length, 0);
265265
});
266266

@@ -281,28 +281,28 @@ suite("Macros", function() {
281281
test("With arguments, no parameterization, no externals", function() {
282282
const msg = bundle.getMessage("call-bar-with-arg");
283283
const val = bundle.format(msg, {}, errs);
284-
assert.equal(val, "Foo $arg");
284+
assert.equal(val, "Foo {$arg}");
285285
assert.equal(errs.length, 0);
286286
});
287287

288288
test("With arguments, no parameterization, with externals", function() {
289289
const msg = bundle.getMessage("call-bar-with-arg");
290290
const val = bundle.format(msg, {arg: 5}, errs);
291-
assert.equal(val, "Foo $arg");
291+
assert.equal(val, "Foo {$arg}");
292292
assert.equal(errs.length, 0);
293293
});
294294

295295
test("With arguments, no arguments, no externals", function() {
296296
const msg = bundle.getMessage("call-baz-with-arg");
297297
const val = bundle.format(msg, {}, errs);
298-
assert.equal(val, "Foo $arg");
298+
assert.equal(val, "Foo {$arg}");
299299
assert.equal(errs.length, 0);
300300
});
301301

302302
test("With arguments, no arguments, with externals", function() {
303303
const msg = bundle.getMessage("call-baz-with-arg");
304304
const val = bundle.format(msg, {arg: 5}, errs);
305-
assert.equal(val, "Foo $arg");
305+
assert.equal(val, "Foo {$arg}");
306306
assert.equal(errs.length, 0);
307307
});
308308

fluent/test/patterns_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ suite('Patterns', function(){
6262
test('returns the id if a message reference is missing', function(){
6363
const msg = bundle.getMessage('ref-missing-message');
6464
const val = bundle.format(msg, args, errs);
65-
assert.strictEqual(val, 'missing');
65+
assert.strictEqual(val, '{missing}');
6666
assert.ok(errs[0] instanceof ReferenceError); // unknown message
6767
});
6868

6969
test('returns the id if a term reference is missing', function(){
7070
const msg = bundle.getMessage('ref-missing-term');
7171
const val = bundle.format(msg, args, errs);
72-
assert.strictEqual(val, '-missing');
72+
assert.strictEqual(val, '{-missing}');
7373
assert.ok(errs[0] instanceof ReferenceError); // unknown message
7474
});
7575
});
@@ -102,7 +102,7 @@ suite('Patterns', function(){
102102
function(){
103103
const msg = bundle.getMessage('bar');
104104
const val = bundle.format(msg, args, errs);
105-
assert.strictEqual(val, '??? Bar');
105+
assert.strictEqual(val, '{???} Bar');
106106
assert.ok(errs[0] instanceof RangeError); // no default
107107
});
108108
});
@@ -119,7 +119,7 @@ suite('Patterns', function(){
119119
test('returns ???', function(){
120120
const msg = bundle.getMessage('foo');
121121
const val = bundle.format(msg, args, errs);
122-
assert.strictEqual(val, '???');
122+
assert.strictEqual(val, '{???}');
123123
assert.ok(errs[0] instanceof RangeError); // cyclic reference
124124
});
125125
});
@@ -135,7 +135,7 @@ suite('Patterns', function(){
135135
test('returns the raw string', function(){
136136
const msg = bundle.getMessage('foo');
137137
const val = bundle.format(msg, args, errs);
138-
assert.strictEqual(val, '???');
138+
assert.strictEqual(val, '{???}');
139139
assert.ok(errs[0] instanceof RangeError); // cyclic reference
140140
});
141141
});
@@ -156,7 +156,7 @@ suite('Patterns', function(){
156156
test('returns ???', function(){
157157
const msg = bundle.getMessage('foo');
158158
const val = bundle.format(msg, {sel: 'a'}, errs);
159-
assert.strictEqual(val, '???');
159+
assert.strictEqual(val, '{???}');
160160
assert.ok(errs[0] instanceof RangeError); // cyclic reference
161161
});
162162

fluent/test/values_ref_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ suite('Referencing values', function(){
7777
test('uses ??? if there is no value', function(){
7878
const msg = bundle.getMessage('ref5');
7979
const val = bundle.format(msg, args, errs);
80-
assert.strictEqual(val, '???');
80+
assert.strictEqual(val, '{???}');
8181
assert.ok(errs[0] instanceof RangeError); // no default
8282
});
8383

0 commit comments

Comments
 (0)