From f8b6b929df671095a2ec02009bb8e0487b87f540 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 20 Jun 2018 15:48:54 +0200 Subject: [PATCH] Add some more tests for the options argument to the RelativeTimeFormat constructor. --- .../options-localeMatcher-invalid.js | 29 +++++++++++++++++ .../constructor/options-numeric-invalid.js | 29 +++++++++++++++++ .../constructor/options-numeric-valid.js | 25 +++++++++++++++ .../constructor/options-style-invalid.js | 32 +++++++++++++++++++ .../constructor/options-style-valid.js | 26 +++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-localeMatcher-invalid.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-valid.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-style-invalid.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-style-valid.js diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-localeMatcher-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-localeMatcher-invalid.js new file mode 100644 index 0000000000..bb852f62a9 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-localeMatcher-invalid.js @@ -0,0 +1,29 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat +description: Checks handling of invalid value for the localeMatcher option to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.RelativeTimeFormat] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.RelativeTimeFormat([], {"localeMatcher": invalidOption}); + }, `${invalidOption} is an invalid localeMatcher option value`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js new file mode 100644 index 0000000000..d0733a06e4 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js @@ -0,0 +1,29 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat +description: Checks handling of invalid value for the numeric option to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) + 16. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always"). +features: [Intl.RelativeTimeFormat] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Always", + "ALWAYS", + "always\0", + "Auto", + "AUTO", + "auto\0", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.RelativeTimeFormat([], {"numeric": invalidOption}); + }, `${invalidOption} is an invalid numeric option value`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-valid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-valid.js new file mode 100644 index 0000000000..f4f82bd73c --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-valid.js @@ -0,0 +1,25 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat +description: Checks handling of valid values for the numeric option to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) + 16. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always"). + 17. Set relativeTimeFormat.[[Numeric]] to numeric. +features: [Intl.RelativeTimeFormat] +---*/ + +const validOptions = [ + [undefined, "always"], + ["always", "always"], + ["auto", "auto"], + [{ toString() { return "auto"; } }, "auto"], +]; + +for (const [validOption, expected] of validOptions) { + const tf = new Intl.RelativeTimeFormat([], {"numeric": validOption}); + const resolvedOptions = tf.resolvedOptions(); + assert.sameValue(resolvedOptions.numeric, expected); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-invalid.js new file mode 100644 index 0000000000..e3b2803962 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-invalid.js @@ -0,0 +1,32 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat +description: Checks handling of invalid value for the style option to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) + 14. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). +features: [Intl.RelativeTimeFormat] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Long", + "LONG", + "long\0", + "Short", + "SHORT", + "short\0", + "Narrow", + "NARROW", + "narrow\0", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.RelativeTimeFormat([], {"style": invalidOption}); + }, `${invalidOption} is an invalid style option value`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-valid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-valid.js new file mode 100644 index 0000000000..0e74fb84a9 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-style-valid.js @@ -0,0 +1,26 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat +description: Checks handling of valid values for the style option to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) + 14. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). + 15. Set relativeTimeFormat.[[Style]] to s. +features: [Intl.RelativeTimeFormat] +---*/ + +const validOptions = [ + [undefined, "long"], + ["long", "long"], + ["short", "short"], + ["narrow", "narrow"], + [{ toString() { return "narrow"; } }, "narrow"], +]; + +for (const [validOption, expected] of validOptions) { + const tf = new Intl.RelativeTimeFormat([], {"style": validOption}); + const resolvedOptions = tf.resolvedOptions(); + assert.sameValue(resolvedOptions.style, expected); +}