From 3161b18f7109a07612adf2d108c65af7d0532ac3 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 14 Aug 2018 17:39:18 +0200 Subject: [PATCH] Intl.RelativeTimeFormat: Add some tests for non-object options arguments to the constructor. --- .../constructor/options-toobject-prototype.js | 35 +++++++++++++++++ .../constructor/options-toobject.js | 26 +++++++++++++ .../constructor/options-undefined.js | 38 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject-prototype.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject.js create mode 100644 test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject-prototype.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject-prototype.js new file mode 100644 index 0000000000..f7a8c04048 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject-prototype.js @@ -0,0 +1,35 @@ +// 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 non-object option arguments to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) +features: [Intl.RelativeTimeFormat] +---*/ + +Object.defineProperties(Object.prototype, { + "style": { + value: "short", + }, + "numeric": { + value: "auto", + }, +}) + +const optionsArguments = [ + true, + "test", + 7, + Symbol(), +]; + +for (const options of optionsArguments) { + const rtf = new Intl.RelativeTimeFormat([], options); + const resolvedOptions = rtf.resolvedOptions(); + assert.sameValue(resolvedOptions.style, "short", + `options argument ${String(options)} should yield the correct value for "style"`); + assert.sameValue(resolvedOptions.numeric, "auto", + `options argument ${String(options)} should yield the correct value for "numeric"`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject.js new file mode 100644 index 0000000000..796bfaa2b0 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-toobject.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 non-object option arguments to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) +features: [Intl.RelativeTimeFormat] +---*/ + +const optionsArguments = [ + true, + "test", + 7, + Symbol(), +]; + +for (const options of optionsArguments) { + const rtf = new Intl.RelativeTimeFormat([], options); + const resolvedOptions = rtf.resolvedOptions(); + assert.sameValue(resolvedOptions.style, "long", + `options argument ${String(options)} should yield the correct value for "style"`); + assert.sameValue(resolvedOptions.numeric, "always", + `options argument ${String(options)} should yield the correct value for "numeric"`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js new file mode 100644 index 0000000000..f5ab4bf838 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js @@ -0,0 +1,38 @@ +// 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 non-object option arguments to the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat (relativeTimeFormat, locales, options) +features: [Intl.RelativeTimeFormat] +---*/ + +Object.defineProperties(Object.prototype, { + "style": { + get() { + throw new Error("Should not call style getter"); + } + }, + "numeric": { + get() { + throw new Error("Should not call numeric getter"); + } + }, +}) + +const optionsArguments = [ + [], + [[]], + [[], undefined], +]; + +for (const args of optionsArguments) { + const rtf = new Intl.RelativeTimeFormat(...args); + const resolvedOptions = rtf.resolvedOptions(); + assert.sameValue(resolvedOptions.style, "long", + `Calling with ${args.length} empty arguments should yield the correct value for "style"`); + assert.sameValue(resolvedOptions.numeric, "always", + `Calling with ${args.length} empty arguments should yield the correct value for "numeric"`); +}