diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/string-lowering.js | 17 | ||||
-rw-r--r-- | test/lit/passes/string-lowering.wast | 23 |
2 files changed, 36 insertions, 4 deletions
diff --git a/test/lit/passes/string-lowering.js b/test/lit/passes/string-lowering.js new file mode 100644 index 000000000..105970bcc --- /dev/null +++ b/test/lit/passes/string-lowering.js @@ -0,0 +1,17 @@ +var filename = process.argv[2]; +var module = new WebAssembly.Module(require('fs').readFileSync(filename)); +var sections = WebAssembly.Module.customSections(module, 'string.consts'); +var array = new Uint8Array(sections[0]); +var string = new TextDecoder('utf-8').decode(array); + +function standardizeEncoding(s) { + // Different node.js versions print differently, so we must standardize to + // pass tests in all places. In particular at some point node.js started to + // abbreviate \u0000 as \x00 (both of which are valid). + return s.replace('\\u0000', '\\x00'); +} + +console.log("string:", standardizeEncoding(string)); + +var json = JSON.stringify(JSON.parse(string)); +console.log("JSON:", standardizeEncoding(json)); diff --git a/test/lit/passes/string-lowering.wast b/test/lit/passes/string-lowering.wast index 628092d1c..43d30fc64 100644 --- a/test/lit/passes/string-lowering.wast +++ b/test/lit/passes/string-lowering.wast @@ -2,8 +2,6 @@ ;; operations are tested in string-gathering.wast (which is auto-updated, unlike ;; this which is manual). -;; RUN: foreach %s %t wasm-opt --string-lowering -all -S -o - | filecheck %s - (module (func $consts (drop @@ -15,9 +13,26 @@ (drop (string.const "foo") ) + (drop + (string.const "needs\tescaping\00.'#%\"- .\r\n\\.ꙮ") + ) ) ) -;; The custom section should contain foo and bar, and foo only once. -;; CHECK: custom section "string.consts", size 13, contents: "[\"bar\",\"foo\"]" +;; The custom section should contain foo and bar, and foo only once, and the +;; string with \t should be escaped. +;; +;; RUN: wasm-opt %s --string-lowering -all -S -o - | filecheck %s +;; +;; CHECK: custom section "string.consts", size 59, contents: "[\"bar\",\"foo\",\"needs\\tescaping\\u0000.'#%\\\"- .\\r\\n\\\\.\\ua66e\"]" + +;; The custom section should parse OK using JSON.parse from node. +;; (Note we run --remove-unused-module-elements to remove externref-using +;; imports, which require a newer version of node.) +;; +;; RUN: wasm-opt %s --string-lowering --remove-unused-module-elements -all -o %t.wasm +;; RUN: node %S/string-lowering.js %t.wasm | filecheck %s --check-prefix=CHECK-JS +;; +;; CHECK-JS: string: ["bar","foo","needs\tescaping\x00.'#%\"- .\r\n\\.\ua66e"] +;; CHECK-JS: JSON: ["bar","foo","needs\tescaping\x00.'#%\"- .\r\n\\.ꙮ"] |