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 33f6cb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 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
6 changes: 3 additions & 3 deletions fluent/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class FluentType {
}

export class FluentNone extends FluentType {
valueOf() {
return null;
constructor(value = "???") {
super(value);
}

toString() {
return `{${this.value || "???"}}`;
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 33f6cb2

Please sign in to comment.