CollatorSupportedLocales.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. var passed = true;
  6. function arrayEqual(arr1, arr2) {
  7. if (arr1.length !== arr2.length) return false;
  8. for (var i = 0; i < arr1.length; i++) {
  9. if (arr1[i] !== arr2[i]) return false;
  10. }
  11. return true;
  12. }
  13. function testSupportedLocales(locales, expectedResult) {
  14. try {
  15. var actual = Intl.Collator.supportedLocalesOf(locales, { localeMatcher: "best fit" });
  16. if (!arrayEqual(actual, expectedResult)) {
  17. throw new Error("Calling SupportedLocalesOf on '[" + locales.join(",") + "]' doesn't match expected result '[" + expectedResult.join(",") + "]' when using best fit. Actual:[" + actual.join(",") + "]");
  18. }
  19. actual = Intl.Collator.supportedLocalesOf(locales, { localeMatcher: "best fit" });
  20. if (!arrayEqual(actual, expectedResult)) {
  21. throw new Error("Calling SupportedLocalesOf on '[" + locales.join(",") + "]' doesn't match expected result '[" + expectedResult.join(",") + "]' when using lookup. Actual: [" + actual.join(",") + "]");
  22. }
  23. }
  24. catch (ex) {
  25. passed = false;
  26. WScript.Echo("Error testSupportedLocales: " + ex.message);
  27. }
  28. }
  29. testSupportedLocales(undefined, []);
  30. testSupportedLocales(["en-US"], ["en-US"]);
  31. testSupportedLocales([], []);
  32. if (passed === true) {
  33. WScript.Echo("Pass");
  34. }