From 258b86349350e4e05f0aee4e36ca514003c9f0c2 Mon Sep 17 00:00:00 2001 From: Daniel Wile Date: Tue, 10 Dec 2024 10:48:19 -0500 Subject: [PATCH 1/4] added unit tests --- package-lock.json | 8 +-- src/impl/english.js | 1 + test/datetime/locale.test.js | 0 test/datetime/tokenParse.test.js | 12 ++-- test/impl/english.test.js | 97 +++++++++++++++++++++++++++++++- 5 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 test/datetime/locale.test.js diff --git a/package-lock.json b/package-lock.json index 1676906d0..a687d3ef1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,15 +17,15 @@ "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "babel-jest": "^28.1.2", - "benchmark": "*", - "codecov": "*", - "documentation": "*", + "benchmark": "latest", + "codecov": "latest", + "documentation": "latest", "fs-extra": "^6.0.1", "http-server": "^14.1.1", "husky": "^7.0.0", "jest": "^29.4.3", "lint-staged": "^13.2.1", - "prettier": "*", + "prettier": "latest", "rollup": "^2.52.7", "rollup-plugin-terser": "^7.0.2", "uglify-js": "^3.13.10" diff --git a/src/impl/english.js b/src/impl/english.js index cf9379834..938730382 100644 --- a/src/impl/english.js +++ b/src/impl/english.js @@ -182,6 +182,7 @@ export function formatString(knownFormat) { ]), key = stringify(filtered), dateTimeHuge = "EEEE, LLLL d, yyyy, h:mm a"; + console.log(key); switch (key) { case stringify(Formats.DATE_SHORT): return "M/d/yyyy"; diff --git a/test/datetime/locale.test.js b/test/datetime/locale.test.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index 8b5c6a8d7..de10f9ab2 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -1086,14 +1086,10 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem expect(ex15.result).toBeInstanceOf(Object); expect(keyCount(ex15.result)).toBe(6); - const ex16 = DateTime.fromFormatExplain( - "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்", - "dd-MMMM-yyyy hh:mm:ss a", - { - locale: "ta", - numberingSystem: "tamldec", - } - ); + const ex16 = DateTime.fromFormatExplain("௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", "dd-MMMM-yyyy hh:mm:ss a", { + locale: "ta", + numberingSystem: "tamldec", + }); expect(ex16.rawMatches).toBeInstanceOf(Array); expect(ex16.matches).toBeInstanceOf(Object); expect(keyCount(ex16.matches)).toBe(7); diff --git a/test/impl/english.test.js b/test/impl/english.test.js index fe909f2c1..936cc0f1f 100644 --- a/test/impl/english.test.js +++ b/test/impl/english.test.js @@ -1,6 +1,15 @@ /* global test expect */ - -import { formatRelativeTime } from "../../src/impl/english"; +import * as Formats from "../../src/impl/formats"; +import { + formatRelativeTime, + formatString, + months, + monthsLong, + monthsNarrow, + monthsShort, + weekdays, + eras, +} from "../../src/impl/english"; test("today", () => { expect(formatRelativeTime("days", 0, "auto")).toBe("today"); @@ -79,3 +88,87 @@ test("1 hour ago", () => { expect(formatRelativeTime("hours", -1, "always")).toBe("1 hour ago"); expect(formatRelativeTime("hours", -1, "always", true)).toBe("1 hr. ago"); }); + +test("months", () => { + expect(months("narrow")).toStrictEqual([...monthsNarrow]); + expect(months("short")).toStrictEqual([...monthsShort]); + expect(months("long")).toStrictEqual([...monthsLong]); + expect(months("numeric")).toStrictEqual([ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + ]); + expect(months("2-digit")).toStrictEqual([ + "01", + "02", + "03", + "04", + "05", + "06", + "07", + "08", + "09", + "10", + "11", + "12", + ]); + expect(months("lets see default")).toBe(null); +}); + +test("formatString", () => { + expect(formatString(Formats.DATE_SHORT)).toBe("M/d/yyyy"); + expect(formatString(Formats.DATE_MED)).toBe("LLL d, yyyy"); + expect(formatString(Formats.DATE_MED_WITH_WEEKDAY)).toBe("EEE, LLL d, yyyy"); + expect(formatString(Formats.DATE_FULL)).toBe("LLLL d, yyyy"); + expect(formatString(Formats.DATE_HUGE)).toBe("EEEE, LLLL d, yyyy"); + expect(formatString(Formats.TIME_SIMPLE)).toBe("h:mm a"); + expect(formatString(Formats.TIME_WITH_SECONDS)).toBe("h:mm:ss a"); + expect(formatString(Formats.TIME_WITH_SHORT_OFFSET)).toBe("h:mm a"); + expect(formatString(Formats.TIME_WITH_LONG_OFFSET)).toBe("h:mm a"); + expect(formatString(Formats.TIME_24_SIMPLE)).toBe("HH:mm"); + expect(formatString(Formats.TIME_24_WITH_SECONDS)).toBe("HH:mm:ss"); + expect(formatString(Formats.TIME_24_WITH_SHORT_OFFSET)).toBe("HH:mm"); + expect(formatString(Formats.TIME_24_WITH_LONG_OFFSET)).toBe("HH:mm"); + expect(formatString(Formats.DATETIME_SHORT)).toBe("M/d/yyyy, h:mm a"); + expect(formatString(Formats.DATETIME_MED)).toBe("LLL d, yyyy, h:mm a"); + expect(formatString(Formats.DATETIME_FULL)).toBe("LLLL d, yyyy, h:mm a"); + expect(formatString(Formats.DATETIME_HUGE)).toBe("EEEE, LLLL d, yyyy, h:mm a"); + expect(formatString(Formats.DATETIME_SHORT_WITH_SECONDS)).toBe("M/d/yyyy, h:mm:ss a"); + expect(formatString(Formats.DATETIME_MED_WITH_SECONDS)).toBe("LLL d, yyyy, h:mm:ss a"); + expect(formatString(Formats.DATETIME_MED_WITH_WEEKDAY)).toBe("EEE, d LLL yyyy, h:mm a"); + expect(formatString(Formats.DATETIME_FULL_WITH_SECONDS)).toBe("LLLL d, yyyy, h:mm:ss a"); + expect(formatString(Formats.DATETIME_HUGE_WITH_SECONDS)).toBe("EEEE, LLLL d, yyyy, h:mm:ss a"); + expect(formatString("Give Me Default?")).toBe("EEEE, LLLL d, yyyy, h:mm a"); +}); + +test("weekdays", () => { + expect(weekdays("narrow")).toStrictEqual(["M", "T", "W", "T", "F", "S", "S"]); + expect(weekdays("short")).toStrictEqual(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]); + expect(weekdays("long")).toStrictEqual([ + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", + ]); + expect(weekdays("numeric")).toStrictEqual(["1", "2", "3", "4", "5", "6", "7"]); + expect(weekdays(null)).toStrictEqual(null); +}); + +test("eras", () => { + expect(eras("narrow")).toStrictEqual(["B", "A"]); + expect(eras("short")).toStrictEqual(["BC", "AD"]); + expect(eras("long")).toStrictEqual(["Before Christ", "Anno Domini"]); + expect(eras("default")).toStrictEqual(null); +}); From 86104202400b52982138920471ef42918ae81484 Mon Sep 17 00:00:00 2001 From: Daniel Wile Date: Tue, 10 Dec 2024 11:26:38 -0500 Subject: [PATCH 2/4] clean up before creating PR --- src/impl/english.js | 1 - test/datetime/locale.test.js | 0 test/impl/english.test.js | 46 +----------------------------------- 3 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 test/datetime/locale.test.js diff --git a/src/impl/english.js b/src/impl/english.js index 938730382..cf9379834 100644 --- a/src/impl/english.js +++ b/src/impl/english.js @@ -182,7 +182,6 @@ export function formatString(knownFormat) { ]), key = stringify(filtered), dateTimeHuge = "EEEE, LLLL d, yyyy, h:mm a"; - console.log(key); switch (key) { case stringify(Formats.DATE_SHORT): return "M/d/yyyy"; diff --git a/test/datetime/locale.test.js b/test/datetime/locale.test.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/impl/english.test.js b/test/impl/english.test.js index 936cc0f1f..adc794548 100644 --- a/test/impl/english.test.js +++ b/test/impl/english.test.js @@ -1,15 +1,6 @@ /* global test expect */ import * as Formats from "../../src/impl/formats"; -import { - formatRelativeTime, - formatString, - months, - monthsLong, - monthsNarrow, - monthsShort, - weekdays, - eras, -} from "../../src/impl/english"; +import { formatRelativeTime, formatString, weekdays, eras } from "../../src/impl/english"; test("today", () => { expect(formatRelativeTime("days", 0, "auto")).toBe("today"); @@ -89,41 +80,6 @@ test("1 hour ago", () => { expect(formatRelativeTime("hours", -1, "always", true)).toBe("1 hr. ago"); }); -test("months", () => { - expect(months("narrow")).toStrictEqual([...monthsNarrow]); - expect(months("short")).toStrictEqual([...monthsShort]); - expect(months("long")).toStrictEqual([...monthsLong]); - expect(months("numeric")).toStrictEqual([ - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - ]); - expect(months("2-digit")).toStrictEqual([ - "01", - "02", - "03", - "04", - "05", - "06", - "07", - "08", - "09", - "10", - "11", - "12", - ]); - expect(months("lets see default")).toBe(null); -}); - test("formatString", () => { expect(formatString(Formats.DATE_SHORT)).toBe("M/d/yyyy"); expect(formatString(Formats.DATE_MED)).toBe("LLL d, yyyy"); From 7cfe059cd262ab38c503c159b8aca46fdbb41c06 Mon Sep 17 00:00:00 2001 From: Daniel Wile Date: Tue, 10 Dec 2024 11:29:19 -0500 Subject: [PATCH 3/4] clean up before creating PR --- test/datetime/tokenParse.test.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index de10f9ab2..8b5c6a8d7 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -1086,10 +1086,14 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem expect(ex15.result).toBeInstanceOf(Object); expect(keyCount(ex15.result)).toBe(6); - const ex16 = DateTime.fromFormatExplain("௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", "dd-MMMM-yyyy hh:mm:ss a", { - locale: "ta", - numberingSystem: "tamldec", - }); + const ex16 = DateTime.fromFormatExplain( + "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்", + "dd-MMMM-yyyy hh:mm:ss a", + { + locale: "ta", + numberingSystem: "tamldec", + } + ); expect(ex16.rawMatches).toBeInstanceOf(Array); expect(ex16.matches).toBeInstanceOf(Object); expect(keyCount(ex16.matches)).toBe(7); From d72152f25cc786154c21c3845e4c3b8496a63b93 Mon Sep 17 00:00:00 2001 From: Daniel Wile Date: Tue, 10 Dec 2024 11:30:58 -0500 Subject: [PATCH 4/4] clean up --- test/impl/english.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/impl/english.test.js b/test/impl/english.test.js index adc794548..79690fda6 100644 --- a/test/impl/english.test.js +++ b/test/impl/english.test.js @@ -103,7 +103,7 @@ test("formatString", () => { expect(formatString(Formats.DATETIME_MED_WITH_WEEKDAY)).toBe("EEE, d LLL yyyy, h:mm a"); expect(formatString(Formats.DATETIME_FULL_WITH_SECONDS)).toBe("LLLL d, yyyy, h:mm:ss a"); expect(formatString(Formats.DATETIME_HUGE_WITH_SECONDS)).toBe("EEEE, LLLL d, yyyy, h:mm:ss a"); - expect(formatString("Give Me Default?")).toBe("EEEE, LLLL d, yyyy, h:mm a"); + expect(formatString("Default")).toBe("EEEE, LLLL d, yyyy, h:mm a"); }); test("weekdays", () => {