IntlIdentities.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. let staticMethods = [
  7. Intl.getCanonicalLocales,
  8. Intl.Collator.supportedLocalesOf,
  9. Intl.DateTimeFormat.supportedLocalesOf,
  10. Intl.NumberFormat.supportedLocalesOf
  11. ];
  12. let longNames = [
  13. "Intl.getCanonicalLocales",
  14. "Intl.Collator.supportedLocalesOf",
  15. "Intl.DateTimeFormat.supportedLocalesOf",
  16. "Intl.NumberFormat.supportedLocalesOf"
  17. ];
  18. let shortNames = [
  19. "getCanonicalLocales",
  20. "supportedLocalesOf",
  21. "supportedLocalesOf",
  22. "supportedLocalesOf"
  23. ];
  24. let expectedToString =
  25. `function() {
  26. [native code]
  27. }`;
  28. let tests = [
  29. {
  30. name: "Short names",
  31. body: function () {
  32. for (let i in staticMethods) {
  33. assert.areEqual(staticMethods[i].name, shortNames[i]);
  34. }
  35. }
  36. },
  37. {
  38. name: "Invoking built-in static methods with `new` fails (check name in error message)",
  39. body: function () {
  40. for (let i in staticMethods) {
  41. const expectedMessage = WScript.Platform.INTL_LIBRARY === "icu"
  42. ? "Function is not a constructor"
  43. : `Function '${longNames[i]}' is not a constructor`;
  44. assert.throws(() => new staticMethods[i](), TypeError, "", expectedMessage);
  45. }
  46. }
  47. },
  48. {
  49. name: "toString of built-in static methods",
  50. body: function () {
  51. for (let i in staticMethods) {
  52. const expectedMessage = WScript.Platform.INTL_LIBRARY === "icu"
  53. ? `function ${shortNames[i]}() { [native code] }`
  54. : expectedToString;
  55. assert.areEqual(expectedMessage, "" + staticMethods[i]);
  56. assert.areEqual(expectedMessage, staticMethods[i].toString());
  57. }
  58. }
  59. }
  60. ];
  61. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });