Bug 1505911 - Add struct testing to test_mozTXTToHTMLConv.js. r=valentin
authorSimon Montagu <smontagu@smontagu.org>
Fri, 30 Nov 2018 18:41:55 +0100
changeset 449087 dec172d2c7fd901849b9496601f73483b31f12b0
parent 449086 f64d8eeab965ad962b09952d5e3978db0d4b8199
child 449088 b3085cd7b7c20a55894eb3dcd8c92ab2bc0f03f3
child 449120 4cea07e007eecd96330309c99b85b0b399d18023
push id35142
push userrgurzau@mozilla.com
push dateSat, 01 Dec 2018 14:30:25 +0000
treeherdermozilla-central@b3085cd7b7c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1505911
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505911 - Add struct testing to test_mozTXTToHTMLConv.js. r=valentin
netwerk/test/unit/test_mozTXTToHTMLConv.js
--- a/netwerk/test/unit/test_mozTXTToHTMLConv.js
+++ b/netwerk/test/unit/test_mozTXTToHTMLConv.js
@@ -147,16 +147,52 @@ function run_test() {
       results: ["moz-smiley-s1"]
     },
     {
       input: "this is a smiley :-(",
       results: ["moz-smiley-s2"]
     },
   ];
 
+  const scanTXTstrings = [
+    "underline",                                  // ASCII
+    "äöüßáéíóúî",                                 // Latin-1
+    "\u016B\u00F1\u0257\u0119\u0211\u0142\u00ED\u00F1\u0119",
+                                                  // Pseudo-ese ūñɗęȑłíñę
+    "\u01DDu\u0131\u0283\u0279\u01DDpun",         // Upside down ǝuıʃɹǝpun
+    "\u03C5\u03C0\u03BF\u03B3\u03C1\u03AC\u03BC\u03BC\u03B9\u03C3\u03B7",
+                                                  // Greek υπογράμμιση
+    "\u0441\u0438\u043B\u044C\u043D\u0443\u044E", // Russian сильную
+    "\u0C2C\u0C32\u0C2E\u0C46\u0C56\u0C28",       // Telugu బలమైన
+    "\u508D\u7DDA\u3059\u308B"                    // Japanese 傍線する
+  ];
+
+  const scanTXTstructs = [
+      {
+        delimiter: "/",
+        tag: "i",
+        class: "moz-txt-slash"
+      },
+      {
+        delimiter: "*",
+        tag: "b",
+        class: "moz-txt-star"
+      },
+      {
+        delimiter: "_",
+        tag: "span",
+        class: "moz-txt-underscore"
+      },
+      {
+        delimiter: "|",
+        tag: "code",
+        class: "moz-txt-verticalline"
+      }
+    ];
+
   const scanHTMLtests = [
     {
       input: "http://foo.example.com",
       shouldChange: true
     },
     {
       input: " <a href='http://a.example.com/'>foo</a>",
       shouldChange: false
@@ -224,16 +260,34 @@ function run_test() {
     let t = scanTXTglyph[i];
     let output = converter.scanTXT(t.input, Ci.mozITXTToHTMLConv.kGlyphSubstitution);
     for (let j = 0; j < t.results.length; j++)
       if (!output.includes(t.results[j]))
         do_throw("Unexpected conversion by scanTXT: input=" + t.input +
                  ", output=" + output + ", expected=" + t.results[j]);
   }
 
+  for (let i = 0; i < scanTXTstrings.length; ++i) {
+    for (let j = 0; j < scanTXTstructs.length; ++j) {
+      let input = scanTXTstructs[j].delimiter + scanTXTstrings[i] + scanTXTstructs[j].delimiter;
+      let expected = "<" + scanTXTstructs[j].tag +
+                     " class=\"" + scanTXTstructs[j].class + "\">" +
+                     "<span class=\"moz-txt-tag\">" +
+                     scanTXTstructs[j].delimiter +
+                     "</span>" +
+                     scanTXTstrings[i] +
+                     "<span class=\"moz-txt-tag\">" +
+                     scanTXTstructs[j].delimiter +
+                     "</span>" +
+                     "</" + scanTXTstructs[j].tag + ">";
+      let actual = converter.scanTXT(input, Ci.mozITXTToHTMLConv.kStructPhrase);
+      Assert.equal(encodeURIComponent(actual), encodeURIComponent(expected));
+    }
+  }
+
   for (let i = 0; i < scanHTMLtests.length; i++) {
     let t = scanHTMLtests[i];
     let output = converter.scanHTML(t.input, Ci.mozITXTToHTMLConv.kURLs);
     let changed = (t.input != output);
     if (changed != t.shouldChange) {
       do_throw("Unexpected change by scanHTML: changed=" + changed +
                ", shouldChange=" + t.shouldChange +
                ", \ninput=" + t.input +