IntlIdentities.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. assert.throws(() => new staticMethods[i](), TypeError, "", `Function '${longNames[i]}' is not a constructor`);
  42. }
  43. }
  44. },
  45. {
  46. name: "toString of built-in static methods",
  47. body: function () {
  48. for (let i in staticMethods) {
  49. assert.areEqual('' + staticMethods[i], expectedToString);
  50. assert.areEqual(staticMethods[i].toString(), expectedToString);
  51. }
  52. }
  53. }
  54. ];
  55. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });