Bug 1275474 - Part 2. Add nsIUnicodeNormalizer unit test. r?jfkthame draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 16 May 2016 17:18:54 +0900
changeset 370597 2a7944cf50d8380a1c5693a8aa2613d0ef231f22
parent 370596 686a7ecc81d3d8113c838689d076d9c6fe321e54
child 521802 92968142a2b6f983a905dedeefbb3b7cb83fc4ee
push id19119
push userm_kato@ga2.so-net.ne.jp
push dateWed, 25 May 2016 04:47:19 +0000
reviewersjfkthame
bugs1275474
milestone49.0a1
Bug 1275474 - Part 2. Add nsIUnicodeNormalizer unit test. r?jfkthame MozReview-Commit-ID: 1vSFQrVrcB3
intl/unicharutil/tests/moz.build
intl/unicharutil/tests/unit/test_unicodenormalizer.js
intl/unicharutil/tests/unit/xpcshell.ini
--- a/intl/unicharutil/tests/moz.build
+++ b/intl/unicharutil/tests/moz.build
@@ -3,9 +3,11 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     'NormalizationTest.cpp',
 ]
 
+XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
+
 FINAL_LIBRARY = 'xul-gtest'
new file mode 100644
--- /dev/null
+++ b/intl/unicharutil/tests/unit/test_unicodenormalizer.js
@@ -0,0 +1,37 @@
+var Ci = Components.interfaces;
+var Cc = Components.classes;
+
+function run_testitem(normalizer, item)
+{
+  let dest = {};
+  normalizer.NormalizeUnicodeNFC(item.src, dest);
+  equal(dest.value, item.nfc);
+
+  normalizer.NormalizeUnicodeNFD(item.src, dest);
+  equal(dest.value, item.nfd);
+
+  normalizer.NormalizeUnicodeNFKC(item.src, dest);
+  equal(dest.value, item.nfkc);
+
+  normalizer.NormalizeUnicodeNFKD(item.src, dest);
+  equal(dest.value, item.nfkd);
+}
+
+function run_test()
+{
+  let normalizer = Cc['@mozilla.org/intl/unicodenormalizer;1'].
+      getService(Ci.nsIUnicodeNormalizer);
+
+  let tests = [
+    { src: "\u339c", nfc: "\u339c", nfd: "\u339c", nfkc: "mm", nfkd: "mm"},
+    { src: "\u30e2\u30b8\u30e9",
+      nfc: "\u30e2\u30b8\u30e9", nfd: "\u30e2\u30b7\u3099\u30e9",
+      nfkc: "\u30e2\u30b8\u30e9", nfkd: "\u30e2\u30b7\u3099\u30e9"},
+    { src: "\u30e2\u30b7\u3099\uff97",
+      nfc: "\u30e2\u30b8\uff97", nfd: "\u30e2\u30b7\u3099\uff97",
+      nfkc: "\u30e2\u30b8\u30e9", nfkd: "\u30e2\u30b7\u3099\u30e9"},
+  ];
+  for (let item of tests) {
+    run_testitem(normalizer, item);
+  }
+}
old mode 100755
new mode 100644
--- a/intl/unicharutil/tests/unit/xpcshell.ini
+++ b/intl/unicharutil/tests/unit/xpcshell.ini
@@ -1,4 +1,6 @@
 [DEFAULT]
 head = 
 tail = 
 skip-if = toolkit == 'gonk'
+
+[test_unicodenormalizer.js]