From d38e98d1f31a3c7f6a01feeecdae769ee1f4e3c1 Mon Sep 17 00:00:00 2001
From: Frank Tang <ftang@chromium.org>
Date: Mon, 29 Oct 2018 15:10:29 -0700
Subject: [PATCH] Fix formatToParts expectation @ RelativeTimeFormat

Fix wrong expectations of
Intl.RelativeTimeFormat.prototype.formatToParts
Add tests to cover "group", "decimal" and "fraction".
---
 .../formatToParts/en-us-numeric-always.js     | 18 ++++++++++++--
 .../formatToParts/en-us-numeric-auto.js       | 18 ++++++++++++--
 .../formatToParts/en-us-style-short.js        | 18 ++++++++++++--
 .../formatToParts/pl-pl-style-long.js         | 24 +++++++++++++++++--
 .../formatToParts/pl-pl-style-narrow.js       | 22 +++++++++++++++--
 .../formatToParts/pl-pl-style-short.js        | 22 +++++++++++++++--
 6 files changed, 110 insertions(+), 12 deletions(-)

diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-always.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-always.js
index 5cc5b1d8ab..5b6252ed2b 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-always.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-always.js
@@ -36,7 +36,9 @@ assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be
 for (const unit of units) {
   verifyFormatParts(rtf.formatToParts(1000, unit), [
     { "type": "literal", "value": "in " },
-    { "type": "integer", "value": "1,000", "unit": unit },
+    { "type": "integer", "value": "1", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "000", "unit": unit },
     { "type": "literal", "value": ` ${unit}s` },
   ], `formatToParts(1000, ${unit})`);
 
@@ -85,7 +87,19 @@ for (const unit of units) {
   ], `formatToParts(-10, ${unit})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unit), [
-    { "type": "integer", "value": "1,000", "unit": unit },
+    { "type": "integer", "value": "1", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "000", "unit": unit },
     { "type": "literal", "value": ` ${unit}s ago` },
   ], `formatToParts(-1000, ${unit})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unit), [
+    { "type": "literal", "value": "in " },
+    { "type": "integer", "value": "123", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "456", "unit": unit },
+    { "type": "decimal", "value": ".", "unit": unit },
+    { "type": "fraction", "value": "78", "unit": unit },
+    { "type": "literal", "value": ` ${unit}s` },
+  ], `formatToParts(123456.78, ${unit})`);
 }
diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-auto.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-auto.js
index a7f39ae821..00f319bb86 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-auto.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-numeric-auto.js
@@ -79,7 +79,9 @@ assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be
 for (const unit of units) {
   verifyFormatParts(rtf.formatToParts(1000, unit), [
     { "type": "literal", "value": "in " },
-    { "type": "integer", "value": "1,000", "unit": unit },
+    { "type": "integer", "value": "1", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "000", "unit": unit },
     { "type": "literal", "value": ` ${unit}s` },
   ], `formatToParts(1000, ${unit})`);
 
@@ -128,7 +130,19 @@ for (const unit of units) {
   ], `formatToParts(-10, ${unit})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unit), [
-    { "type": "integer", "value": "1,000", "unit": unit },
+    { "type": "integer", "value": "1", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "000", "unit": unit },
     { "type": "literal", "value": ` ${unit}s ago` },
   ], `formatToParts(-1000, ${unit})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unit), [
+    { "type": "literal", "value": "in " },
+    { "type": "integer", "value": "123", "unit": unit },
+    { "type": "group", "value": ",", "unit": unit },
+    { "type": "integer", "value": "456", "unit": unit },
+    { "type": "decimal", "value": ".", "unit": unit },
+    { "type": "fraction", "value": "78", "unit": unit },
+    { "type": "literal", "value": ` ${unit}s` },
+  ], `formatToParts(123456.78, ${unit})`);
 }
diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-style-short.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-style-short.js
index 2ff39cf608..2e9fedf186 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-style-short.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/en-us-style-short.js
@@ -40,7 +40,9 @@ for (const [unitArgument, unitStrings] of Object.entries(units)) {
 
   verifyFormatParts(rtf.formatToParts(1000, unitArgument), [
     { "type": "literal", "value": "in " },
-    { "type": "integer", "value": "1,000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": ",", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${plural}` },
   ], `formatToParts(1000, ${unitArgument})`);
 
@@ -89,7 +91,19 @@ for (const [unitArgument, unitStrings] of Object.entries(units)) {
   ], `formatToParts(-10, ${unitArgument})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unitArgument), [
-    { "type": "integer", "value": "1,000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": ",", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${plural} ago` },
   ], `formatToParts(-1000, ${unitArgument})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unitArgument), [
+    { "type": "literal", "value": "in " },
+    { "type": "integer", "value": "123", "unit": unitArgument },
+    { "type": "group", "value": ",", "unit": unitArgument },
+    { "type": "integer", "value": "456", "unit": unitArgument },
+    { "type": "decimal", "value": ".", "unit": unitArgument },
+    { "type": "fraction", "value": "78", "unit": unitArgument },
+    { "type": "literal", "value": ` ${plural}` },
+  ], `formatToParts(123456.78, ${unitArgument})`);
 }
diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-long.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-long.js
index 49d43f7482..fb8d539344 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-long.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-long.js
@@ -23,6 +23,7 @@ function regular(s) {
     "many": s,
     "few": s + "y",
     "one": s + "Ä™",
+    "other": s + "y",
   }
 }
 
@@ -35,27 +36,32 @@ const units = {
     "many": "dni",
     "few": "dni",
     "one": "dzień",
+    "other": "dnia",
   },
   "week": {
     "many": "tygodni",
     "few": "tygodnie",
     "one": "tydzień",
+    "other": "tygodnia",
   },
   "month": {
     1000: "miesięcy",
     "many": "miesięcy",
     "few": "miesiÄ…ce",
     "one": "miesiÄ…c",
+    "other": "miesiÄ…ca",
   },
   "quarter": {
     "many": "kwartałów",
     "few": "kwartały",
     "one": "kwartał",
+    "other": "kwartału",
   },
   "year": {
     "many": "lat",
     "few": "lata",
     "one": "rok",
+    "other": "roku",
   },
 };
 
@@ -68,7 +74,9 @@ assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be
 for (const [unitArgument, expected] of Object.entries(units)) {
   verifyFormatParts(rtf.formatToParts(1000, unitArgument), [
     { "type": "literal", "value": "za " },
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many}` },
   ], `formatToParts(1000, ${unitArgument})`);
 
@@ -117,7 +125,19 @@ for (const [unitArgument, expected] of Object.entries(units)) {
   ], `formatToParts(-10, ${unitArgument})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unitArgument), [
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many} temu` },
   ], `formatToParts(-1000, ${unitArgument})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unitArgument), [
+    { "type": "literal", "value": "za " },
+    { "type": "integer", "value": "123", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "456", "unit": unitArgument },
+    { "type": "decimal", "value": ",", "unit": unitArgument },
+    { "type": "fraction", "value": "78", "unit": unitArgument },
+    { "type": "literal", "value": ` ${expected.other}` },
+  ], `formatToParts(123456.78, ${unitArgument})`);
 }
diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-narrow.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-narrow.js
index 263a36450f..c2a2c0ee59 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-narrow.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-narrow.js
@@ -23,6 +23,7 @@ function always(s) {
     "many": s,
     "few": s,
     "one": s,
+    "other": s,
   }
 }
 
@@ -35,11 +36,13 @@ const units = {
     "many": "dni",
     "few": "dni",
     "one": "dzień",
+    "other": "dnia",
   },
   "week": {
     "many": "tyg.",
     "few": "tyg.",
     "one": "tydz.",
+    "other": "tyg.",
   },
   "month": always("mies."),
   "quarter": always("kw."),
@@ -47,6 +50,7 @@ const units = {
     "many": "lat",
     "few": "lata",
     "one": "rok",
+    "other": "roku",
   },
 };
 
@@ -59,7 +63,9 @@ assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be
 for (const [unitArgument, expected] of Object.entries(units)) {
   verifyFormatParts(rtf.formatToParts(1000, unitArgument), [
     { "type": "literal", "value": "za " },
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many}` },
   ], `formatToParts(1000, ${unitArgument})`);
 
@@ -108,7 +114,19 @@ for (const [unitArgument, expected] of Object.entries(units)) {
   ], `formatToParts(-10, ${unitArgument})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unitArgument), [
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many} temu` },
   ], `formatToParts(-1000, ${unitArgument})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unitArgument), [
+    { "type": "literal", "value": "za " },
+    { "type": "integer", "value": "123", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "456", "unit": unitArgument },
+    { "type": "decimal", "value": ",", "unit": unitArgument },
+    { "type": "fraction", "value": "78", "unit": unitArgument },
+    { "type": "literal", "value": ` ${expected.other}` },
+  ], `formatToParts(123456.78, ${unitArgument})`);
 }
diff --git a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-short.js b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-short.js
index cdf74d3106..c105d91793 100644
--- a/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-short.js
+++ b/test/intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-short.js
@@ -23,6 +23,7 @@ function always(s) {
     "many": s,
     "few": s,
     "one": s,
+    "other": s,
   }
 }
 
@@ -35,11 +36,13 @@ const units = {
     "many": "dni",
     "few": "dni",
     "one": "dzień",
+    "other": "dnia",
   },
   "week": {
     "many": "tyg.",
     "few": "tyg.",
     "one": "tydz.",
+    "other": "tyg.",
   },
   "month": always("mies."),
   "quarter": always("kw."),
@@ -47,6 +50,7 @@ const units = {
     "many": "lat",
     "few": "lata",
     "one": "rok",
+    "other": "roku",
   },
 };
 
@@ -59,7 +63,9 @@ assert.sameValue(typeof rtf.formatToParts, "function", "formatToParts should be
 for (const [unitArgument, expected] of Object.entries(units)) {
   verifyFormatParts(rtf.formatToParts(1000, unitArgument), [
     { "type": "literal", "value": "za " },
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many}` },
   ], `formatToParts(1000, ${unitArgument})`);
 
@@ -108,7 +114,19 @@ for (const [unitArgument, expected] of Object.entries(units)) {
   ], `formatToParts(-10, ${unitArgument})`);
 
   verifyFormatParts(rtf.formatToParts(-1000, unitArgument), [
-    { "type": "integer", "value": "1\u00a0000", "unit": unitArgument },
+    { "type": "integer", "value": "1", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "000", "unit": unitArgument },
     { "type": "literal", "value": ` ${expected.many} temu` },
   ], `formatToParts(-1000, ${unitArgument})`);
+
+  verifyFormatParts(rtf.formatToParts(123456.78, unitArgument), [
+    { "type": "literal", "value": "za " },
+    { "type": "integer", "value": "123", "unit": unitArgument },
+    { "type": "group", "value": "\u00a0", "unit": unitArgument },
+    { "type": "integer", "value": "456", "unit": unitArgument },
+    { "type": "decimal", "value": ",", "unit": unitArgument },
+    { "type": "fraction", "value": "78", "unit": unitArgument },
+    { "type": "literal", "value": ` ${expected.other}` },
+  ], `formatToParts(123456.78, ${unitArgument})`);
 }
-- 
GitLab