Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,85 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let invalidNumberingSystem = [
"invalid",
"abce",
"finance",
"native",
"traditio",
"abc-defghi",
];
let illFormedNumberingSystem = [
"",
"i",
"ij",
"abcdefghi",
"abc-ab",
];
// https://tc39.github.io/ecma402/#table-numbering-system-digits
let validNumberingSystem= [
"arab",
"arabext",
"bali",
"beng",
"deva",
"fullwide",
"gujr",
"guru",
"hanidec",
"khmr",
"knda",
"laoo",
"latn",
"limb",
"mlym",
"mong",
"mymr",
"orya",
"tamldec",
"telu",
"thai",
"tibt",
];
let locales = [
"en",
"ar",
];
invalidNumberingSystem.forEach(function(numberingSystem) {
locales.forEach(function(base) {
var df;
assertDoesNotThrow(
() => df = new Intl.RelativeTimeFormat([base], {numberingSystem}));
assertEquals(
(new Intl.RelativeTimeFormat([base])).resolvedOptions().numberingSystem,
df.resolvedOptions().numberingSystem);
});
});
illFormedNumberingSystem.forEach(function(numberingSystem) {
assertThrows(
() => new Intl.RelativeTimeFormat(["en"], {numberingSystem}),
RangeError);
});
let value = 1234567.89;
validNumberingSystem.forEach(function(numberingSystem) {
locales.forEach(function(base) {
let l = base + "-u-nu-" + numberingSystem;
let nf = new Intl.RelativeTimeFormat([base], {numberingSystem});
assertEquals(base, nf.resolvedOptions().locale);
assertEquals(numberingSystem, nf.resolvedOptions().numberingSystem);
// Test the formatting result is the same as passing in via u-nu-
// in the locale.
let nf2 = new Intl.RelativeTimeFormat([l]);
assertEquals(nf2.format(value, "day"), nf.format(value, "day"));
});
}
);

View File

@ -0,0 +1,21 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
new Intl.RelativeTimeFormat(['en-US'], {
get localeMatcher() {
assertEquals(0, getCount++);
},
get style() {
assertEquals(1, getCount++);
},
get numeric() {
assertEquals(2, getCount++);
},
});
assertEquals(3, getCount);

View File

@ -0,0 +1,77 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// RelativeTimeFormat constructor can't be called as function.
assertThrows(() => Intl.RelativeTimeFormat('sr'), TypeError);
// Non-string locale.
//assertThrows(() => new Intl.RelativeTimeFormat(5), TypeError);
// Invalid locale string.
//assertThrows(() => new Intl.RelativeTimeFormat('abcdefghi'), RangeError);
assertDoesNotThrow(() => new Intl.RelativeTimeFormat('sr', {}));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat([], {}));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat(['fr', 'ar'], {}));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat({0: 'ja', 1:'fr'}, {}));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat({1: 'ja', 2:'fr'}, {}));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat('sr'));
assertDoesNotThrow(() => new Intl.RelativeTimeFormat());
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat(
'sr', {
localeMatcher: 'lookup',
style: 'short',
numeric: 'always'
}));
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {localeMatcher: 'lookup'}));
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {localeMatcher: 'best fit'}));
assertThrows(
() => new Intl.RelativeTimeFormat('sr', {localeMatcher: 'hello'}),
RangeError);
assertThrows(
() => new Intl.RelativeTimeFormat('sr', {localeMatcher: 'look up'}),
RangeError);
assertThrows(
() => new Intl.RelativeTimeFormat('sr', {localeMatcher: 'bestfit'}),
RangeError);
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {style: 'long'}));
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {style: 'short'}));
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {style: 'narrow'}));
assertThrows(
() => new Intl.RelativeTimeFormat('sr', {style: 'giant'}),
RangeError);
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {numeric: 'always'}));
assertDoesNotThrow(
() => new Intl.RelativeTimeFormat('sr', {numeric: 'auto'}));
assertThrows(
() => new Intl.RelativeTimeFormat('sr', {numeric: 'never'}),
RangeError);

View File

@ -0,0 +1,13 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Environment Variables: LC_ALL=fr_CA
assertEquals(
'fr-CA',
(new Intl.RelativeTimeFormat()).resolvedOptions().locale);
assertEquals(
'fr-CA',
(new Intl.RelativeTimeFormat([], {style: 'short', numeric: 'auto'}))
.resolvedOptions().locale);

View File

@ -0,0 +1,13 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Environment Variables: LC_ALL=pt_BR
assertEquals(
'pt-BR',
(new Intl.RelativeTimeFormat()).resolvedOptions().locale);
assertEquals(
'pt-BR',
(new Intl.RelativeTimeFormat([], {style: 'short', numeric: 'auto'}))
.resolvedOptions().locale);

View File

@ -0,0 +1,481 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The following test are not part of the comformance. Just some output in
// English to verify the format does return something reasonable for English.
// It may be changed when we update the CLDR data.
// NOTE: These are UNSPECIFIED behavior in
// http://tc39.github.io/proposal-intl-relative-time/
let longAuto = new Intl.RelativeTimeFormat(
"en", {style: "long", localeMatcher: 'lookup', numeric: 'auto'});
assertEquals('3 seconds ago', longAuto.format(-3, 'second'));
assertEquals('2 seconds ago', longAuto.format(-2, 'second'));
assertEquals('1 second ago', longAuto.format(-1, 'second'));
assertEquals('now', longAuto.format(0, 'second'));
assertEquals('now', longAuto.format(-0, 'second'));
assertEquals('in 1 second', longAuto.format(1, 'second'));
assertEquals('in 2 seconds', longAuto.format(2, 'second'));
assertEquals('in 345 seconds', longAuto.format(345, 'second'));
assertEquals('3 minutes ago', longAuto.format(-3, 'minute'));
assertEquals('2 minutes ago', longAuto.format(-2, 'minute'));
assertEquals('1 minute ago', longAuto.format(-1, 'minute'));
assertEquals('this minute', longAuto.format(0, 'minute'));
assertEquals('this minute', longAuto.format(-0, 'minute'));
assertEquals('in 1 minute', longAuto.format(1, 'minute'));
assertEquals('in 2 minutes', longAuto.format(2, 'minute'));
assertEquals('in 345 minutes', longAuto.format(345, 'minute'));
assertEquals('3 hours ago', longAuto.format(-3, 'hour'));
assertEquals('2 hours ago', longAuto.format(-2, 'hour'));
assertEquals('1 hour ago', longAuto.format(-1, 'hour'));
assertEquals('this hour', longAuto.format(0, 'hour'));
assertEquals('this hour', longAuto.format(-0, 'hour'));
assertEquals('in 1 hour', longAuto.format(1, 'hour'));
assertEquals('in 2 hours', longAuto.format(2, 'hour'));
assertEquals('in 345 hours', longAuto.format(345, 'hour'));
assertEquals('3 days ago', longAuto.format(-3, 'day'));
assertEquals('2 days ago', longAuto.format(-2, 'day'));
assertEquals('yesterday', longAuto.format(-1, 'day'));
assertEquals('today', longAuto.format(0, 'day'));
assertEquals('today', longAuto.format(-0, 'day'));
assertEquals('tomorrow', longAuto.format(1, 'day'));
assertEquals('in 2 days', longAuto.format(2, 'day'));
assertEquals('in 345 days', longAuto.format(345, 'day'));
assertEquals('3 weeks ago', longAuto.format(-3, 'week'));
assertEquals('2 weeks ago', longAuto.format(-2, 'week'));
assertEquals('last week', longAuto.format(-1, 'week'));
assertEquals('this week', longAuto.format(0, 'week'));
assertEquals('this week', longAuto.format(-0, 'week'));
assertEquals('next week', longAuto.format(1, 'week'));
assertEquals('in 2 weeks', longAuto.format(2, 'week'));
assertEquals('in 345 weeks', longAuto.format(345, 'week'));
assertEquals('3 months ago', longAuto.format(-3, 'month'));
assertEquals('2 months ago', longAuto.format(-2, 'month'));
assertEquals('last month', longAuto.format(-1, 'month'));
assertEquals('this month', longAuto.format(0, 'month'));
assertEquals('this month', longAuto.format(-0, 'month'));
assertEquals('next month', longAuto.format(1, 'month'));
assertEquals('in 2 months', longAuto.format(2, 'month'));
assertEquals('in 345 months', longAuto.format(345, 'month'));
assertEquals('3 quarters ago', longAuto.format(-3, 'quarter'));
assertEquals('2 quarters ago', longAuto.format(-2, 'quarter'));
assertEquals('last quarter', longAuto.format(-1, 'quarter'));
assertEquals('this quarter', longAuto.format(0, 'quarter'));
assertEquals('this quarter', longAuto.format(-0, 'quarter'));
assertEquals('next quarter', longAuto.format(1, 'quarter'));
assertEquals('in 2 quarters', longAuto.format(2, 'quarter'));
assertEquals('in 345 quarters', longAuto.format(345, 'quarter'));
assertEquals('3 years ago', longAuto.format(-3, 'year'));
assertEquals('2 years ago', longAuto.format(-2, 'year'));
assertEquals('last year', longAuto.format(-1, 'year'));
assertEquals('this year', longAuto.format(0, 'year'));
assertEquals('this year', longAuto.format(-0, 'year'));
assertEquals('next year', longAuto.format(1, 'year'));
assertEquals('in 2 years', longAuto.format(2, 'year'));
assertEquals('in 345 years', longAuto.format(345, 'year'));
let shortAuto = new Intl.RelativeTimeFormat(
"en", {style: "short", localeMatcher: 'lookup', numeric: 'auto'});
assertEquals('3 sec. ago', shortAuto.format(-3, 'second'));
assertEquals('2 sec. ago', shortAuto.format(-2, 'second'));
assertEquals('1 sec. ago', shortAuto.format(-1, 'second'));
assertEquals('now', shortAuto.format(0, 'second'));
assertEquals('now', shortAuto.format(-0, 'second'));
assertEquals('in 1 sec.', shortAuto.format(1, 'second'));
assertEquals('in 2 sec.', shortAuto.format(2, 'second'));
assertEquals('in 345 sec.', shortAuto.format(345, 'second'));
assertEquals('3 min. ago', shortAuto.format(-3, 'minute'));
assertEquals('2 min. ago', shortAuto.format(-2, 'minute'));
assertEquals('1 min. ago', shortAuto.format(-1, 'minute'));
assertEquals('this minute', shortAuto.format(0, 'minute'));
assertEquals('this minute', shortAuto.format(-0, 'minute'));
assertEquals('in 1 min.', shortAuto.format(1, 'minute'));
assertEquals('in 2 min.', shortAuto.format(2, 'minute'));
assertEquals('in 345 min.', shortAuto.format(345, 'minute'));
assertEquals('3 hr. ago', shortAuto.format(-3, 'hour'));
assertEquals('2 hr. ago', shortAuto.format(-2, 'hour'));
assertEquals('1 hr. ago', shortAuto.format(-1, 'hour'));
assertEquals('this hour', shortAuto.format(0, 'hour'));
assertEquals('this hour', shortAuto.format(-0, 'hour'));
assertEquals('in 1 hr.', shortAuto.format(1, 'hour'));
assertEquals('in 2 hr.', shortAuto.format(2, 'hour'));
assertEquals('in 345 hr.', shortAuto.format(345, 'hour'));
assertEquals('3 days ago', shortAuto.format(-3, 'day'));
assertEquals('2 days ago', shortAuto.format(-2, 'day'));
assertEquals('yesterday', shortAuto.format(-1, 'day'));
assertEquals('today', shortAuto.format(0, 'day'));
assertEquals('today', shortAuto.format(-0, 'day'));
assertEquals('tomorrow', shortAuto.format(1, 'day'));
assertEquals('in 2 days', shortAuto.format(2, 'day'));
assertEquals('in 345 days', shortAuto.format(345, 'day'));
assertEquals('3 wk. ago', shortAuto.format(-3, 'week'));
assertEquals('2 wk. ago', shortAuto.format(-2, 'week'));
assertEquals('last wk.', shortAuto.format(-1, 'week'));
assertEquals('this wk.', shortAuto.format(0, 'week'));
assertEquals('this wk.', shortAuto.format(-0, 'week'));
assertEquals('next wk.', shortAuto.format(1, 'week'));
assertEquals('in 2 wk.', shortAuto.format(2, 'week'));
assertEquals('in 345 wk.', shortAuto.format(345, 'week'));
assertEquals('3 mo. ago', shortAuto.format(-3, 'month'));
assertEquals('2 mo. ago', shortAuto.format(-2, 'month'));
assertEquals('last mo.', shortAuto.format(-1, 'month'));
assertEquals('this mo.', shortAuto.format(0, 'month'));
assertEquals('this mo.', shortAuto.format(-0, 'month'));
assertEquals('next mo.', shortAuto.format(1, 'month'));
assertEquals('in 2 mo.', shortAuto.format(2, 'month'));
assertEquals('in 345 mo.', shortAuto.format(345, 'month'));
assertEquals('3 qtrs. ago', shortAuto.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', shortAuto.format(-2, 'quarter'));
assertEquals('last qtr.', shortAuto.format(-1, 'quarter'));
assertEquals('this qtr.', shortAuto.format(0, 'quarter'));
assertEquals('this qtr.', shortAuto.format(-0, 'quarter'));
assertEquals('next qtr.', shortAuto.format(1, 'quarter'));
assertEquals('in 2 qtrs.', shortAuto.format(2, 'quarter'));
assertEquals('in 345 qtrs.', shortAuto.format(345, 'quarter'));
assertEquals('3 yr. ago', shortAuto.format(-3, 'year'));
assertEquals('2 yr. ago', shortAuto.format(-2, 'year'));
assertEquals('last yr.', shortAuto.format(-1, 'year'));
assertEquals('this yr.', shortAuto.format(0, 'year'));
assertEquals('this yr.', shortAuto.format(-0, 'year'));
assertEquals('next yr.', shortAuto.format(1, 'year'));
assertEquals('in 2 yr.', shortAuto.format(2, 'year'));
assertEquals('in 345 yr.', shortAuto.format(345, 'year'));
// Somehow in the 'en' locale, there are no valeu for -narrow
let narrowAuto = new Intl.RelativeTimeFormat(
"en", {style: "narrow", localeMatcher: 'lookup', numeric: 'auto'});
assertEquals('3s ago', narrowAuto.format(-3, 'second'));
assertEquals('2s ago', narrowAuto.format(-2, 'second'));
assertEquals('1s ago', narrowAuto.format(-1, 'second'));
assertEquals('now', narrowAuto.format(0, 'second'));
assertEquals('now', narrowAuto.format(-0, 'second'));
assertEquals('in 1s', narrowAuto.format(1, 'second'));
assertEquals('in 2s', narrowAuto.format(2, 'second'));
assertEquals('in 345s', narrowAuto.format(345, 'second'));
assertEquals('3m ago', narrowAuto.format(-3, 'minute'));
assertEquals('2m ago', narrowAuto.format(-2, 'minute'));
assertEquals('1m ago', narrowAuto.format(-1, 'minute'));
assertEquals('this minute', narrowAuto.format(0, 'minute'));
assertEquals('this minute', narrowAuto.format(-0, 'minute'));
assertEquals('in 1m', narrowAuto.format(1, 'minute'));
assertEquals('in 2m', narrowAuto.format(2, 'minute'));
assertEquals('in 345m', narrowAuto.format(345, 'minute'));
assertEquals('3h ago', narrowAuto.format(-3, 'hour'));
assertEquals('2h ago', narrowAuto.format(-2, 'hour'));
assertEquals('1h ago', narrowAuto.format(-1, 'hour'));
assertEquals('this hour', narrowAuto.format(0, 'hour'));
assertEquals('this hour', narrowAuto.format(-0, 'hour'));
assertEquals('in 1h', narrowAuto.format(1, 'hour'));
assertEquals('in 2h', narrowAuto.format(2, 'hour'));
assertEquals('in 345h', narrowAuto.format(345, 'hour'));
assertEquals('3d ago', narrowAuto.format(-3, 'day'));
assertEquals('2d ago', narrowAuto.format(-2, 'day'));
assertEquals('yesterday', narrowAuto.format(-1, 'day'));
assertEquals('today', narrowAuto.format(0, 'day'));
assertEquals('today', narrowAuto.format(-0, 'day'));
assertEquals('tomorrow', narrowAuto.format(1, 'day'));
assertEquals('in 2d', narrowAuto.format(2, 'day'));
assertEquals('in 345d', narrowAuto.format(345, 'day'));
assertEquals('3w ago', narrowAuto.format(-3, 'week'));
assertEquals('2w ago', narrowAuto.format(-2, 'week'));
assertEquals('last wk.', narrowAuto.format(-1, 'week'));
assertEquals('this wk.', narrowAuto.format(0, 'week'));
assertEquals('this wk.', narrowAuto.format(-0, 'week'));
assertEquals('next wk.', narrowAuto.format(1, 'week'));
assertEquals('in 2w', narrowAuto.format(2, 'week'));
assertEquals('in 345w', narrowAuto.format(345, 'week'));
assertEquals('3mo ago', narrowAuto.format(-3, 'month'));
assertEquals('2mo ago', narrowAuto.format(-2, 'month'));
assertEquals('last mo.', narrowAuto.format(-1, 'month'));
assertEquals('this mo.', narrowAuto.format(0, 'month'));
assertEquals('this mo.', narrowAuto.format(-0, 'month'));
assertEquals('next mo.', narrowAuto.format(1, 'month'));
assertEquals('in 2mo', narrowAuto.format(2, 'month'));
assertEquals('in 345mo', narrowAuto.format(345, 'month'));
assertEquals('3q ago', narrowAuto.format(-3, 'quarter'));
assertEquals('2q ago', narrowAuto.format(-2, 'quarter'));
assertEquals('last qtr.', narrowAuto.format(-1, 'quarter'));
assertEquals('this qtr.', narrowAuto.format(0, 'quarter'));
assertEquals('this qtr.', narrowAuto.format(-0, 'quarter'));
assertEquals('next qtr.', narrowAuto.format(1, 'quarter'));
assertEquals('in 2q', narrowAuto.format(2, 'quarter'));
assertEquals('in 345q', narrowAuto.format(345, 'quarter'));
assertEquals('3y ago', narrowAuto.format(-3, 'year'));
assertEquals('2y ago', narrowAuto.format(-2, 'year'));
assertEquals('last yr.', narrowAuto.format(-1, 'year'));
assertEquals('this yr.', narrowAuto.format(0, 'year'));
assertEquals('this yr.', narrowAuto.format(-0, 'year'));
assertEquals('next yr.', narrowAuto.format(1, 'year'));
assertEquals('in 2y', narrowAuto.format(2, 'year'));
assertEquals('in 345y', narrowAuto.format(345, 'year'));
let longAlways = new Intl.RelativeTimeFormat(
"en", {style: "long", localeMatcher: 'lookup', numeric: 'always'});
assertEquals('3 seconds ago', longAlways.format(-3, 'second'));
assertEquals('2 seconds ago', longAlways.format(-2, 'second'));
assertEquals('1 second ago', longAlways.format(-1, 'second'));
assertEquals('in 0 seconds', longAlways.format(0, 'second'));
assertEquals('0 seconds ago', longAlways.format(-0, 'second'));
assertEquals('in 1 second', longAlways.format(1, 'second'));
assertEquals('in 2 seconds', longAlways.format(2, 'second'));
assertEquals('in 345 seconds', longAlways.format(345, 'second'));
assertEquals('3 minutes ago', longAlways.format(-3, 'minute'));
assertEquals('2 minutes ago', longAlways.format(-2, 'minute'));
assertEquals('1 minute ago', longAlways.format(-1, 'minute'));
assertEquals('in 0 minutes', longAlways.format(0, 'minute'));
assertEquals('0 minutes ago', longAlways.format(-0, 'minute'));
assertEquals('in 1 minute', longAlways.format(1, 'minute'));
assertEquals('in 2 minutes', longAlways.format(2, 'minute'));
assertEquals('in 345 minutes', longAlways.format(345, 'minute'));
assertEquals('3 hours ago', longAlways.format(-3, 'hour'));
assertEquals('2 hours ago', longAlways.format(-2, 'hour'));
assertEquals('1 hour ago', longAlways.format(-1, 'hour'));
assertEquals('in 0 hours', longAlways.format(0, 'hour'));
assertEquals('0 hours ago', longAlways.format(-0, 'hour'));
assertEquals('in 1 hour', longAlways.format(1, 'hour'));
assertEquals('in 2 hours', longAlways.format(2, 'hour'));
assertEquals('in 345 hours', longAlways.format(345, 'hour'));
assertEquals('3 days ago', longAlways.format(-3, 'day'));
assertEquals('2 days ago', longAlways.format(-2, 'day'));
assertEquals('1 day ago', longAlways.format(-1, 'day'));
assertEquals('in 0 days', longAlways.format(0, 'day'));
assertEquals('0 days ago', longAlways.format(-0, 'day'));
assertEquals('in 1 day', longAlways.format(1, 'day'));
assertEquals('in 2 days', longAlways.format(2, 'day'));
assertEquals('in 345 days', longAlways.format(345, 'day'));
assertEquals('3 weeks ago', longAlways.format(-3, 'week'));
assertEquals('2 weeks ago', longAlways.format(-2, 'week'));
assertEquals('1 week ago', longAlways.format(-1, 'week'));
assertEquals('in 0 weeks', longAlways.format(0, 'week'));
assertEquals('0 weeks ago', longAlways.format(-0, 'week'));
assertEquals('in 1 week', longAlways.format(1, 'week'));
assertEquals('in 2 weeks', longAlways.format(2, 'week'));
assertEquals('in 345 weeks', longAlways.format(345, 'week'));
assertEquals('3 months ago', longAlways.format(-3, 'month'));
assertEquals('2 months ago', longAlways.format(-2, 'month'));
assertEquals('1 month ago', longAlways.format(-1, 'month'));
assertEquals('in 0 months', longAlways.format(0, 'month'));
assertEquals('0 months ago', longAlways.format(-0, 'month'));
assertEquals('in 1 month', longAlways.format(1, 'month'));
assertEquals('in 2 months', longAlways.format(2, 'month'));
assertEquals('in 345 months', longAlways.format(345, 'month'));
assertEquals('3 quarters ago', longAlways.format(-3, 'quarter'));
assertEquals('2 quarters ago', longAlways.format(-2, 'quarter'));
assertEquals('1 quarter ago', longAlways.format(-1, 'quarter'));
assertEquals('in 0 quarters', longAlways.format(0, 'quarter'));
assertEquals('0 quarters ago', longAlways.format(-0, 'quarter'));
assertEquals('in 1 quarter', longAlways.format(1, 'quarter'));
assertEquals('in 2 quarters', longAlways.format(2, 'quarter'));
assertEquals('in 345 quarters', longAlways.format(345, 'quarter'));
assertEquals('3 years ago', longAlways.format(-3, 'year'));
assertEquals('2 years ago', longAlways.format(-2, 'year'));
assertEquals('1 year ago', longAlways.format(-1, 'year'));
assertEquals('in 0 years', longAlways.format(0, 'year'));
assertEquals('0 years ago', longAlways.format(-0, 'year'));
assertEquals('in 1 year', longAlways.format(1, 'year'));
assertEquals('in 2 years', longAlways.format(2, 'year'));
assertEquals('in 345 years', longAlways.format(345, 'year'));
let shortAlways = new Intl.RelativeTimeFormat(
"en", {style: "short", localeMatcher: 'lookup', numeric: 'always'});
assertEquals('3 sec. ago', shortAlways.format(-3, 'second'));
assertEquals('2 sec. ago', shortAlways.format(-2, 'second'));
assertEquals('1 sec. ago', shortAlways.format(-1, 'second'));
assertEquals('in 0 sec.', shortAlways.format(0, 'second'));
assertEquals('0 sec. ago', shortAlways.format(-0, 'second'));
assertEquals('in 1 sec.', shortAlways.format(1, 'second'));
assertEquals('in 2 sec.', shortAlways.format(2, 'second'));
assertEquals('in 345 sec.', shortAlways.format(345, 'second'));
assertEquals('3 min. ago', shortAlways.format(-3, 'minute'));
assertEquals('2 min. ago', shortAlways.format(-2, 'minute'));
assertEquals('1 min. ago', shortAlways.format(-1, 'minute'));
assertEquals('in 0 min.', shortAlways.format(0, 'minute'));
assertEquals('0 min. ago', shortAlways.format(-0, 'minute'));
assertEquals('in 1 min.', shortAlways.format(1, 'minute'));
assertEquals('in 2 min.', shortAlways.format(2, 'minute'));
assertEquals('in 345 min.', shortAlways.format(345, 'minute'));
assertEquals('3 hr. ago', shortAlways.format(-3, 'hour'));
assertEquals('2 hr. ago', shortAlways.format(-2, 'hour'));
assertEquals('1 hr. ago', shortAlways.format(-1, 'hour'));
assertEquals('in 0 hr.', shortAlways.format(0, 'hour'));
assertEquals('0 hr. ago', shortAlways.format(-0, 'hour'));
assertEquals('in 1 hr.', shortAlways.format(1, 'hour'));
assertEquals('in 2 hr.', shortAlways.format(2, 'hour'));
assertEquals('in 345 hr.', shortAlways.format(345, 'hour'));
assertEquals('3 days ago', shortAlways.format(-3, 'day'));
assertEquals('2 days ago', shortAlways.format(-2, 'day'));
assertEquals('1 day ago', shortAlways.format(-1, 'day'));
assertEquals('in 0 days', shortAlways.format(0, 'day'));
assertEquals('0 days ago', shortAlways.format(-0, 'day'));
assertEquals('in 1 day', shortAlways.format(1, 'day'));
assertEquals('in 2 days', shortAlways.format(2, 'day'));
assertEquals('in 345 days', shortAlways.format(345, 'day'));
assertEquals('3 wk. ago', shortAlways.format(-3, 'week'));
assertEquals('2 wk. ago', shortAlways.format(-2, 'week'));
assertEquals('1 wk. ago', shortAlways.format(-1, 'week'));
assertEquals('in 0 wk.', shortAlways.format(0, 'week'));
assertEquals('0 wk. ago', shortAlways.format(-0, 'week'));
assertEquals('in 1 wk.', shortAlways.format(1, 'week'));
assertEquals('in 2 wk.', shortAlways.format(2, 'week'));
assertEquals('in 345 wk.', shortAlways.format(345, 'week'));
assertEquals('3 mo. ago', shortAlways.format(-3, 'month'));
assertEquals('2 mo. ago', shortAlways.format(-2, 'month'));
assertEquals('1 mo. ago', shortAlways.format(-1, 'month'));
assertEquals('in 0 mo.', shortAlways.format(0, 'month'));
assertEquals('0 mo. ago', shortAlways.format(-0, 'month'));
assertEquals('in 1 mo.', shortAlways.format(1, 'month'));
assertEquals('in 2 mo.', shortAlways.format(2, 'month'));
assertEquals('in 345 mo.', shortAlways.format(345, 'month'));
assertEquals('3 qtrs. ago', shortAlways.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', shortAlways.format(-2, 'quarter'));
assertEquals('1 qtr. ago', shortAlways.format(-1, 'quarter'));
assertEquals('in 0 qtrs.', shortAlways.format(0, 'quarter'));
assertEquals('0 qtrs. ago', shortAlways.format(-0, 'quarter'));
assertEquals('in 1 qtr.', shortAlways.format(1, 'quarter'));
assertEquals('in 2 qtrs.', shortAlways.format(2, 'quarter'));
assertEquals('in 345 qtrs.', shortAlways.format(345, 'quarter'));
assertEquals('3 yr. ago', shortAlways.format(-3, 'year'));
assertEquals('2 yr. ago', shortAlways.format(-2, 'year'));
assertEquals('1 yr. ago', shortAlways.format(-1, 'year'));
assertEquals('in 0 yr.', shortAlways.format(0, 'year'));
assertEquals('0 yr. ago', shortAlways.format(-0, 'year'));
assertEquals('in 1 yr.', shortAlways.format(1, 'year'));
assertEquals('in 2 yr.', shortAlways.format(2, 'year'));
assertEquals('in 345 yr.', shortAlways.format(345, 'year'));
// Somehow in the 'en' locale, there are no valeu for -narrow
let narrowAlways = new Intl.RelativeTimeFormat(
"en", {style: "narrow", localeMatcher: 'lookup', numeric: 'always'});
assertEquals('3s ago', narrowAlways.format(-3, 'second'));
assertEquals('2s ago', narrowAlways.format(-2, 'second'));
assertEquals('1s ago', narrowAlways.format(-1, 'second'));
assertEquals('in 0s', narrowAlways.format(0, 'second'));
assertEquals('0s ago', narrowAlways.format(-0, 'second'));
assertEquals('in 1s', narrowAlways.format(1, 'second'));
assertEquals('in 2s', narrowAlways.format(2, 'second'));
assertEquals('in 345s', narrowAlways.format(345, 'second'));
assertEquals('3m ago', narrowAlways.format(-3, 'minute'));
assertEquals('2m ago', narrowAlways.format(-2, 'minute'));
assertEquals('1m ago', narrowAlways.format(-1, 'minute'));
assertEquals('in 0m', narrowAlways.format(0, 'minute'));
assertEquals('0m ago', narrowAlways.format(-0, 'minute'));
assertEquals('in 1m', narrowAlways.format(1, 'minute'));
assertEquals('in 2m', narrowAlways.format(2, 'minute'));
assertEquals('in 345m', narrowAlways.format(345, 'minute'));
assertEquals('3h ago', narrowAlways.format(-3, 'hour'));
assertEquals('2h ago', narrowAlways.format(-2, 'hour'));
assertEquals('1h ago', narrowAlways.format(-1, 'hour'));
assertEquals('in 0h', narrowAlways.format(0, 'hour'));
assertEquals('0h ago', narrowAlways.format(-0, 'hour'));
assertEquals('in 1h', narrowAlways.format(1, 'hour'));
assertEquals('in 2h', narrowAlways.format(2, 'hour'));
assertEquals('in 345h', narrowAlways.format(345, 'hour'));
assertEquals('3d ago', narrowAlways.format(-3, 'day'));
assertEquals('2d ago', narrowAlways.format(-2, 'day'));
assertEquals('1d ago', narrowAlways.format(-1, 'day'));
assertEquals('in 0d', narrowAlways.format(0, 'day'));
assertEquals('0d ago', narrowAlways.format(-0, 'day'));
assertEquals('in 1d', narrowAlways.format(1, 'day'));
assertEquals('in 2d', narrowAlways.format(2, 'day'));
assertEquals('in 345d', narrowAlways.format(345, 'day'));
assertEquals('3w ago', narrowAlways.format(-3, 'week'));
assertEquals('2w ago', narrowAlways.format(-2, 'week'));
assertEquals('1w ago', narrowAlways.format(-1, 'week'));
assertEquals('in 0w', narrowAlways.format(0, 'week'));
assertEquals('0w ago', narrowAlways.format(-0, 'week'));
assertEquals('in 1w', narrowAlways.format(1, 'week'));
assertEquals('in 2w', narrowAlways.format(2, 'week'));
assertEquals('in 345w', narrowAlways.format(345, 'week'));
assertEquals('3mo ago', narrowAlways.format(-3, 'month'));
assertEquals('2mo ago', narrowAlways.format(-2, 'month'));
assertEquals('1mo ago', narrowAlways.format(-1, 'month'));
assertEquals('in 0mo', narrowAlways.format(0, 'month'));
assertEquals('0mo ago', narrowAlways.format(-0, 'month'));
assertEquals('in 1mo', narrowAlways.format(1, 'month'));
assertEquals('in 2mo', narrowAlways.format(2, 'month'));
assertEquals('in 345mo', narrowAlways.format(345, 'month'));
assertEquals('3q ago', narrowAlways.format(-3, 'quarter'));
assertEquals('2q ago', narrowAlways.format(-2, 'quarter'));
assertEquals('1q ago', narrowAlways.format(-1, 'quarter'));
assertEquals('in 0q', narrowAlways.format(0, 'quarter'));
assertEquals('0q ago', narrowAlways.format(-0, 'quarter'));
assertEquals('in 1q', narrowAlways.format(1, 'quarter'));
assertEquals('in 2q', narrowAlways.format(2, 'quarter'));
assertEquals('in 345q', narrowAlways.format(345, 'quarter'));
assertEquals('3y ago', narrowAlways.format(-3, 'year'));
assertEquals('2y ago', narrowAlways.format(-2, 'year'));
assertEquals('1y ago', narrowAlways.format(-1, 'year'));
assertEquals('in 0y', narrowAlways.format(0, 'year'));
assertEquals('0y ago', narrowAlways.format(-0, 'year'));
assertEquals('in 1y', narrowAlways.format(1, 'year'));
assertEquals('in 2y', narrowAlways.format(2, 'year'));
assertEquals('in 345y', narrowAlways.format(345, 'year'));
var styleNumericCombinations = [
longAuto, shortAuto, narrowAuto, longAlways,
shortAlways, narrowAlways ];
var validUnits = [
'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
// Test these all throw RangeError
for (var i = 0; i < styleNumericCombinations.length; i++) {
for (var j = 0; j < validUnits.length; j++) {
assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j]),
RangeError);
assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j] + 's'),
RangeError);
assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j]),
RangeError);
assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j] + 's'),
RangeError);
}
}

View File

@ -0,0 +1,107 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The following test are not part of the comformance. Just some output in
// English to verify the format does return something reasonable for English.
// It may be changed when we update the CLDR data.
// NOTE: These are UNSPECIFIED behavior in
// http://tc39.github.io/proposal-intl-relative-time/
// From Sample code in https://github.com/tc39/proposal-intl-relative-time#intlrelativetimeformatprototypeformattopartsvalue-unit
// // Format relative time using the day unit.
// rtf.formatToParts(-1, "day");
// // > [{ type: "literal", value: "yesterday"}]
let longAuto = new Intl.RelativeTimeFormat(
"en", {style: "long", localeMatcher: 'lookup', numeric: 'auto'});
var parts = longAuto.formatToParts(-1, "day");
assertEquals(1, parts.length);
assertEquals(2, Object.getOwnPropertyNames(parts[0]).length);
assertEquals('literal', parts[0].type);
assertEquals('yesterday', parts[0].value);
// From Sample code in https://github.com/tc39/proposal-intl-relative-time#intlrelativetimeformatprototypeformattopartsvalue-unit
// rtf.formatToParts(100, "day");
// // > [{ type: "literal", value: "in " }, { type: "integer", value: "100", unit: "day" }, { type: "literal", value: " days" }]
let longAlways = new Intl.RelativeTimeFormat(
"en", {style: "long", localeMatcher: 'lookup', numeric: 'always'});
parts = longAlways.formatToParts(100, "day");
assertEquals(3, parts.length);
assertEquals(2, Object.getOwnPropertyNames(parts[0]).length);
assertEquals('literal', parts[0].type);
assertEquals('in ', parts[0].value);
assertEquals(3, Object.getOwnPropertyNames(parts[1]).length);
assertEquals('integer', parts[1].type);
assertEquals('100', parts[1].value);
assertEquals('day', parts[1].unit);
assertEquals(2, Object.getOwnPropertyNames(parts[2]).length);
assertEquals('literal', parts[2].type);
assertEquals(' days', parts[2].value);
assertThrows(() => longAlways.format(NaN, 'second'), RangeError);
assertThrows(() => longAuto.format(NaN, 'second'), RangeError);
parts = longAlways.formatToParts(-10, "day");
assertEquals(2, parts.length);
assertEquals(3, Object.getOwnPropertyNames(parts[0]).length);
assertEquals('integer', parts[0].type);
assertEquals('10', parts[0].value);
assertEquals('day', parts[0].unit);
assertEquals(2, Object.getOwnPropertyNames(parts[1]).length);
assertEquals('literal', parts[1].type);
assertEquals(' days ago', parts[1].value);
parts = longAlways.formatToParts(-0, "day");
assertEquals(2, parts.length);
assertEquals(3, Object.getOwnPropertyNames(parts[0]).length);
assertEquals('integer', parts[0].type);
assertEquals('0', parts[0].value);
assertEquals('day', parts[0].unit);
assertEquals(2, Object.getOwnPropertyNames(parts[1]).length);
assertEquals('literal', parts[1].type);
assertEquals(' days ago', parts[1].value);
// Test with non integer
// Part Idx: 0 1 23 45 6
assertEquals('in 123,456.78 seconds', longAlways.format(123456.78, 'seconds'));
parts = longAlways.formatToParts(123456.78, 'seconds');
assertEquals(7, parts.length);
// 0: "in "
assertEquals(2, Object.getOwnPropertyNames(parts[0]).length);
assertEquals('literal', parts[0].type);
assertEquals('in ', parts[0].value);
assertEquals(undefined, parts[0].unit);
// 1: "123"
assertEquals(3, Object.getOwnPropertyNames(parts[1]).length);
assertEquals('integer', parts[1].type);
assertEquals('123', parts[1].value);
assertEquals('second', parts[1].unit);
// 2: ","
assertEquals(3, Object.getOwnPropertyNames(parts[2]).length);
assertEquals('group', parts[2].type);
assertEquals(',', parts[2].value);
assertEquals('second', parts[2].unit);
// 3: "456"
assertEquals(3, Object.getOwnPropertyNames(parts[3]).length);
assertEquals('integer', parts[3].type);
assertEquals('456', parts[3].value);
assertEquals('second', parts[3].unit);
// 4: "."
assertEquals(3, Object.getOwnPropertyNames(parts[4]).length);
assertEquals('decimal', parts[4].type);
assertEquals('.', parts[4].value);
assertEquals('second', parts[4].unit);
// 5: "78"
assertEquals(3, Object.getOwnPropertyNames(parts[4]).length);
assertEquals('fraction', parts[5].type);
assertEquals('78', parts[5].value);
assertEquals('second', parts[5].unit);
// 6: " seconds"
assertEquals(2, Object.getOwnPropertyNames(parts[6]).length);
assertEquals('literal', parts[6].type);
assertEquals(' seconds', parts[6].value);
assertEquals(undefined, parts[6].unit);

View File

@ -0,0 +1,26 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Check plural w/ formatToParts
// http://tc39.github.io/proposal-intl-relative-time/
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit )
function verifyElement(part, expectedUnit) {
assertEquals(true, part.type == 'literal' || part.type == 'integer');
assertEquals('string', typeof part.value);
if (part.type == 'integer') {
assertEquals('string', typeof part.unit);
assertEquals(expectedUnit, part.unit);
}
};
['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second'].forEach(
function(unit) {
rtf.formatToParts(100, unit + 's').forEach(
function(part) {
verifyElement(part, unit);
});
});

View File

@ -0,0 +1,80 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Make sure that RelativeTimeFormat exposes all required properties. Those not specified
// should have undefined value.
// http://tc39.github.io/proposal-intl-relative-time/
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit )
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'seconds')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'second')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'minutes')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'minute')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'hours')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'hour')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'days')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'day')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'weeks')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'week')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'months')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'month')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'quarters')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'quarter')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'years')));
assertEquals(true, Array.isArray(rtf.formatToParts(-1, 'year')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'seconds')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'second')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'minutes')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'minute')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'hours')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'hour')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'days')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'day')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'weeks')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'week')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'months')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'month')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'quarters')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'quarter')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'years')));
assertEquals(true, Array.isArray(rtf.formatToParts(-0, 'year')));
assertThrows(() => rtf.formatToParts(-1, 'decades'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'decade'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'centuries'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'century'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'milliseconds'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'millisecond'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'microseconds'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'microsecond'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'nanoseconds'), RangeError);
assertThrows(() => rtf.formatToParts(-1, 'nanosecond'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'seconds'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'second'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'minutes'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'minute'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'hours'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'hour'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'days'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'day'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'weeks'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'week'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'months'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'month'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'years'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'year'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'quarters'), RangeError);
assertThrows(() => rtf.formatToParts(NaN, 'quarter'), RangeError);
assertEquals(true, Array.isArray(rtf.formatToParts(100, 'day')));
rtf.formatToParts(100, 'day').forEach(function(part) {
assertEquals(true, part.type == 'literal' || part.type == 'integer');
assertEquals('string', typeof part.value);
if (part.type == 'integer') {
assertEquals('string', typeof part.unit);
}
});

View File

@ -0,0 +1,80 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Make sure that RelativeTimeFormat exposes all required properties. Those not specified
// should have undefined value.
// http://tc39.github.io/proposal-intl-relative-time/
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.3 Intl.RelativeTimeFormat.prototype.format( value, unit )
assertEquals('string', typeof rtf.format(-1, 'seconds'));
assertEquals('string', typeof rtf.format(-1, 'second'));
assertEquals('string', typeof rtf.format(-1, 'minutes'));
assertEquals('string', typeof rtf.format(-1, 'minute'));
assertEquals('string', typeof rtf.format(-1, 'hours'));
assertEquals('string', typeof rtf.format(-1, 'hour'));
assertEquals('string', typeof rtf.format(-1, 'days'));
assertEquals('string', typeof rtf.format(-1, 'day'));
assertEquals('string', typeof rtf.format(-1, 'weeks'));
assertEquals('string', typeof rtf.format(-1, 'week'));
assertEquals('string', typeof rtf.format(-1, 'months'));
assertEquals('string', typeof rtf.format(-1, 'month'));
assertEquals('string', typeof rtf.format(-1, 'years'));
assertEquals('string', typeof rtf.format(-1, 'year'));
assertEquals('string', typeof rtf.format(-1, 'quarter'));
assertEquals('string', typeof rtf.format(-1, 'quarters'));
assertEquals('string', typeof rtf.format(-0, 'seconds'));
assertEquals('string', typeof rtf.format(-0, 'second'));
assertEquals('string', typeof rtf.format(-0, 'minutes'));
assertEquals('string', typeof rtf.format(-0, 'minute'));
assertEquals('string', typeof rtf.format(-0, 'hours'));
assertEquals('string', typeof rtf.format(-0, 'hour'));
assertEquals('string', typeof rtf.format(-0, 'days'));
assertEquals('string', typeof rtf.format(-0, 'day'));
assertEquals('string', typeof rtf.format(-0, 'weeks'));
assertEquals('string', typeof rtf.format(-0, 'week'));
assertEquals('string', typeof rtf.format(-0, 'months'));
assertEquals('string', typeof rtf.format(-0, 'month'));
assertEquals('string', typeof rtf.format(-0, 'years'));
assertEquals('string', typeof rtf.format(-0, 'year'));
assertEquals('string', typeof rtf.format(-0, 'quarter'));
assertEquals('string', typeof rtf.format(-0, 'quarters'));
assertThrows(() => rtf.format(NaN, 'seconds'), RangeError);
assertThrows(() => rtf.format(NaN, 'second'), RangeError);
assertThrows(() => rtf.format(NaN, 'minutes'), RangeError);
assertThrows(() => rtf.format(NaN, 'minute'), RangeError);
assertThrows(() => rtf.format(NaN, 'hours'), RangeError);
assertThrows(() => rtf.format(NaN, 'hour'), RangeError);
assertThrows(() => rtf.format(NaN, 'days'), RangeError);
assertThrows(() => rtf.format(NaN, 'day'), RangeError);
assertThrows(() => rtf.format(NaN, 'weeks'), RangeError);
assertThrows(() => rtf.format(NaN, 'week'), RangeError);
assertThrows(() => rtf.format(NaN, 'months'), RangeError);
assertThrows(() => rtf.format(NaN, 'month'), RangeError);
assertThrows(() => rtf.format(NaN, 'years'), RangeError);
assertThrows(() => rtf.format(NaN, 'year'), RangeError);
assertThrows(() => rtf.format(NaN, 'quarters'), RangeError);
assertThrows(() => rtf.format(NaN, 'quarter'), RangeError);
assertThrows(() => rtf.format(-1, 'decades'), RangeError);
assertThrows(() => rtf.format(-1, 'decade'), RangeError);
assertThrows(() => rtf.format(-1, 'centuries'), RangeError);
assertThrows(() => rtf.format(-1, 'century'), RangeError);
assertThrows(() => rtf.format(-1, 'milliseconds'), RangeError);
assertThrows(() => rtf.format(-1, 'millisecond'), RangeError);
assertThrows(() => rtf.format(-1, 'microseconds'), RangeError);
assertThrows(() => rtf.format(-1, 'microsecond'), RangeError);
assertThrows(() => rtf.format(-1, 'nanoseconds'), RangeError);
assertThrows(() => rtf.format(-1, 'nanosecond'), RangeError);
assertEquals('string', typeof rtf.format(5, 'day'));
assertEquals('string', typeof rtf.format('5', 'day'));
assertEquals('string', typeof rtf.format('-5', 'day'));
assertEquals('string', typeof rtf.format('534', 'day'));
assertEquals('string', typeof rtf.format('-534', 'day'));
//assertThrows(() => rtf.format('xyz', 'day'), RangeError);

View File

@ -0,0 +1,46 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Based on https://www.ecma-international.org/ecma-402/#table-numbering-system-digits
let testCases = [
["arab", "in ١٢٣ days"], // U+0660 to U+0669
["arabext", "in ۱۲۳ days"], // U+06F0 to U+06F9
["bali", "in ᭑᭒᭓ days"], // U+1B50 to U+1B59
["beng", "in ১২৩ days"], // U+09E6 to U+09EF
["deva", "in १२३ days"], // U+0966 to U+096F
["fullwide", "in days"], // U+FF10 to U+FF19
["gujr", "in ૧૨૩ days"], // U+0AE6 to U+0AEF
["guru", "in ੧੨੩ days"], // U+0A66 to U+0A6F
// U+3007, U+4E00, U+4E8C, U+4E09, U+56DB, U+4E94, U+516D, U+4E03, U+516B, U+4E5D
["hanidec", "in 一二三 days"],
["khmr", "in ១២៣ days"], // U+17E0 to U+17E9
["knda", "in ೧೨೩ days"], // U+0CE6 to U+0CEF
["laoo", "in ໑໒໓ days"], // U+0ED0 to U+0ED9
["latn", "in 123 days"], // U+0030 to U+0039
["limb", "in ᥇᥈᥉ days"], // U+1946 to U+194F
["mlym", "in ൧൨൩ days"], // U+0D66 to U+0D6F
["mong", "in ᠑᠒᠓ days"], // U+1810 to U+1819
["mymr", "in ၁၂၃ days"], // U+1040 to U+1049
["orya", "in ୧୨୩ days"], // U+0B66 to U+0B6F
["tamldec", "in ௧௨௩ days"], // U+0BE6 to U+0BEF
["telu", "in ౧౨౩ days"], // U+0C66 to U+0C6F
["thai", "in ๑๒๓ days"], // U+0E50 to U+0E59
["tibt", "in ༡༢༣ days"], // U+0F20 to U+0F29
];
for ([numberingSystem, expected] of testCases) {
let byLocale = new Intl.RelativeTimeFormat("en-u-nu-" + numberingSystem);
let byOptions = new Intl.RelativeTimeFormat("en", { numberingSystem });
// Check the numberingSystem in the resolvedOptions matched.
assertEquals(numberingSystem,
byOptions.resolvedOptions().numberingSystem, numberingSystem);
assertEquals(byLocale.resolvedOptions().numberingSystem,
byOptions.resolvedOptions().numberingSystem, numberingSystem);
// Check the formatted result are the same as if creating by using -u-nu- in
// locale.
assertEquals(byLocale.format(123, "day"), byOptions.format(123, "day"), numberingSystem);
assertEquals(expected, byLocale.format(123, "day"), numberingSystem);
}

View File

@ -0,0 +1,30 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Testing 'bn' locale with -u-nu.
// Split from test/intl/relative-time-format/resolved-options-nu.js
// because Android not yet include bn locale data.
// Only test if the browser support 'bn' locale
if (Intl.RelativeTimeFormat.supportedLocalesOf(["bn"]).length > 0) {
// For locale default the numberingSystem to other than 'latn'
assertEquals(
"beng",
new Intl.RelativeTimeFormat("bn").resolvedOptions().numberingSystem
);
// For locale which default others but use -u-nu-latn to change to 'latn'
// numberingSystem
assertEquals(
"latn",
new Intl.RelativeTimeFormat("bn-u-nu-latn").resolvedOptions()
.numberingSystem
);
// For locale use -u-nu- with invalid value still back to default.
assertEquals(
"beng",
new Intl.RelativeTimeFormat("bn-u-nu-abcd").resolvedOptions()
.numberingSystem
);
}

View File

@ -0,0 +1,81 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// For locale default the numberingSystem to 'latn'
assertEquals(
"latn",
new Intl.RelativeTimeFormat("ar").resolvedOptions().numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("en").resolvedOptions().numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("fr").resolvedOptions().numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("hi").resolvedOptions().numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("th").resolvedOptions().numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("zh-Hant").resolvedOptions().numberingSystem
);
// For locale default the numberingSystem to other than 'latn'
assertEquals(
"arab",
new Intl.RelativeTimeFormat("ar-TD").resolvedOptions().numberingSystem
);
assertEquals(
"arabext",
new Intl.RelativeTimeFormat("fa").resolvedOptions().numberingSystem
);
// For locale use -u-nu- to change to other numberingSystem
assertEquals(
"thai",
new Intl.RelativeTimeFormat("en-u-nu-thai").resolvedOptions()
.numberingSystem
);
assertEquals(
"arab",
new Intl.RelativeTimeFormat("en-u-nu-arab").resolvedOptions()
.numberingSystem
);
// For locale which default others but use -u-nu-latn to change to 'latn' numberingSystem
assertEquals(
"latn",
new Intl.RelativeTimeFormat("fa-u-nu-latn").resolvedOptions()
.numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("ar-TD-u-nu-latn").resolvedOptions()
.numberingSystem
);
assertEquals(
"latn",
new Intl.RelativeTimeFormat("fa-u-nu-latn").resolvedOptions()
.numberingSystem
);
// For locale use -u-nu- with invalid value still back to default.
assertEquals(
"latn",
new Intl.RelativeTimeFormat("en-u-nu-abcd").resolvedOptions()
.numberingSystem
);
assertEquals(
"arabext",
new Intl.RelativeTimeFormat("fa-u-nu-abcd").resolvedOptions()
.numberingSystem
);

View File

@ -0,0 +1,158 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ()
// The default style is 'long'
assertEquals('long', rtf.resolvedOptions().style);
// The default numeric is 'always'
assertEquals('always', rtf.resolvedOptions().numeric);
// contains style, numeric and locale key
assertEquals(4, Object.getOwnPropertyNames(rtf.resolvedOptions()).length);
// contains style, numeric and locale key
assertEquals(
4,
Object.getOwnPropertyNames(
new Intl.RelativeTimeFormat("en").resolvedOptions()
).length
);
assertEquals(
'short',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short'}))
.resolvedOptions().numeric);
assertEquals(
'narrow',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow'}))
.resolvedOptions().numeric);
assertEquals(
'long',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long'}))
.resolvedOptions().numeric);
assertEquals(
'auto',
(new Intl.RelativeTimeFormat(['sr'], {numeric: 'auto'}))
.resolvedOptions().numeric);
assertEquals(
'long',
(new Intl.RelativeTimeFormat(['sr'], {numeric: 'auto'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {numeric: 'always'}))
.resolvedOptions().numeric);
assertEquals(
'long',
(new Intl.RelativeTimeFormat(['sr'], {numeric: 'always'}))
.resolvedOptions().style);
assertEquals(
'long',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'auto'}))
.resolvedOptions().style);
assertEquals(
'auto',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'auto'}))
.resolvedOptions().numeric);
assertEquals(
'long',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'always'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'long', numeric: 'always'}))
.resolvedOptions().numeric);
assertEquals(
'short',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'auto'}))
.resolvedOptions().style);
assertEquals(
'auto',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'auto'}))
.resolvedOptions().numeric);
assertEquals(
'short',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'always'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'short', numeric: 'always'}))
.resolvedOptions().numeric);
assertEquals(
'narrow',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'auto'}))
.resolvedOptions().style);
assertEquals(
'auto',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'auto'}))
.resolvedOptions().numeric);
assertEquals(
'narrow',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'always'}))
.resolvedOptions().style);
assertEquals(
'always',
(new Intl.RelativeTimeFormat(['sr'], {style: 'narrow', numeric: 'always'}))
.resolvedOptions().numeric);
assertEquals(
'ar',
(new Intl.RelativeTimeFormat(['ar'])).resolvedOptions().locale);
assertEquals(
'ar',
(new Intl.RelativeTimeFormat(['ar', 'en'])).resolvedOptions().locale);
assertEquals(
'fr',
(new Intl.RelativeTimeFormat(['fr', 'en'])).resolvedOptions().locale);
assertEquals(
'ar',
(new Intl.RelativeTimeFormat(['xyz', 'ar'])).resolvedOptions().locale);
{
var receiver = 1;
assertThrows(() =>
Intl.RelativeTimeFormat.prototype.resolvedOptions.call(receiver), TypeError);
receiver = {};
assertThrows(() =>
Intl.RelativeTimeFormat.prototype.resolvedOptions.call(receiver), TypeError);
}

View File

@ -0,0 +1,20 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertEquals(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function",
"Intl.RelativeTimeFormat.supportedLocalesOf should be a function");
var undef = Intl.RelativeTimeFormat.supportedLocalesOf();
assertEquals([], undef);
var empty = Intl.RelativeTimeFormat.supportedLocalesOf([]);
assertEquals([], empty);
var strLocale = Intl.RelativeTimeFormat.supportedLocalesOf('sr');
assertEquals('sr', strLocale[0]);
var multiLocale = ['sr-Thai-RS', 'de', 'zh-CN'];
assertEquals(multiLocale,
Intl.RelativeTimeFormat.supportedLocalesOf(multiLocale,
{localeMatcher: "lookup"}));