Skip to content

Commit

Permalink
Use NUMBER() as the placeable fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Jul 22, 2019
1 parent 055b222 commit c7050a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions fluent/src/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function values(opts) {
export
function NUMBER([arg], opts) {
if (arg instanceof FluentNone) {
return new FluentNone("NUMBER()");
return new FluentNone(`NUMBER(${arg.valueOf()})`);
}

if (arg instanceof FluentNumber) {
Expand All @@ -41,7 +41,7 @@ function NUMBER([arg], opts) {
export
function DATETIME([arg], opts) {
if (arg instanceof FluentNone) {
return new FluentNone("DATETIME()");
return new FluentNone(`DATETIME(${arg.valueOf()})`);
}

if (arg instanceof FluentDateTime) {
Expand Down
4 changes: 0 additions & 4 deletions fluent/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export class FluentType {
}

export class FluentNone extends FluentType {
valueOf() {
return null;
}

toString() {
return `{${this.value || "???"}}`;
}
Expand Down
24 changes: 12 additions & 12 deletions fluent/test/functions_builtin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ suite('Built-in functions', function() {

errors = [];
msg = bundle.getMessage('num-decimal');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");

errors = [];
msg = bundle.getMessage('num-percent');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");

errors = [];
msg = bundle.getMessage('num-bad-opt');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");
Expand Down Expand Up @@ -124,21 +124,21 @@ suite('Built-in functions', function() {

errors = [];
msg = bundle.getMessage('num-decimal');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");

errors = [];
msg = bundle.getMessage('num-percent');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");

errors = [];
msg = bundle.getMessage('num-bad-opt');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{NUMBER($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");
Expand All @@ -160,21 +160,21 @@ suite('Built-in functions', function() {

errors = [];
msg = bundle.getMessage('dt-default');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");

errors = [];
msg = bundle.getMessage('dt-month');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");

errors = [];
msg = bundle.getMessage('dt-bad-opt');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, {}, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof ReferenceError);
assert.strictEqual(errors[0].message, "Unknown variable: $arg");
Expand Down Expand Up @@ -267,21 +267,21 @@ suite('Built-in functions', function() {

errors = [];
msg = bundle.getMessage('dt-default');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");

errors = [];
msg = bundle.getMessage('dt-month');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");

errors = [];
msg = bundle.getMessage('dt-bad-opt');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME()}');
assert.strictEqual(bundle.formatPattern(msg.value, args, errors), '{DATETIME($arg)}');
assert.strictEqual(errors.length, 1);
assert.ok(errors[0] instanceof TypeError);
assert.strictEqual(errors[0].message, "Variable type not supported: $arg, object");
Expand Down

0 comments on commit c7050a4

Please sign in to comment.