michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Check that JS inside HTML can be separated and parsed correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {}); michael@0: michael@0: let source = [ michael@0: "", michael@0: "
", michael@0: "", michael@0: "", michael@0: "", michael@0: "" michael@0: ].join("\n"); michael@0: let parser = new Parser(); michael@0: let parsed = parser.get(source); michael@0: michael@0: ok(parsed, michael@0: "HTML code should be parsed correctly."); michael@0: is(parser.errors.length, 0, michael@0: "There should be no errors logged when parsing."); michael@0: michael@0: is(parsed.scriptCount, 3, michael@0: "There should be 3 scripts parsed in the parent HTML source."); michael@0: michael@0: is(parsed.getScriptInfo(0).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "There is no script at the beginning of the parent source."); michael@0: is(parsed.getScriptInfo(source.length - 1).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "There is no script at the end of the parent source."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:31, length:13, index:0})", michael@0: "The first script was located correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:1})", michael@0: "The second script was located correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:151, length:13, index:2})", michael@0: "The third script was located correctly."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a") - 1).toSource(), "({start:31, length:13, index:0})", michael@0: "The left edge of the first script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b") - 1).toSource(), "({start:85, length:13, index:1})", michael@0: "The left edge of the second script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c") - 1).toSource(), "({start:151, length:13, index:2})", michael@0: "The left edge of the third script was interpreted correctly."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a") - 2).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The left outside of the first script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b") - 2).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The left outside of the second script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c") - 2).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The left outside of the third script was interpreted correctly."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a") + 12).toSource(), "({start:31, length:13, index:0})", michael@0: "The right edge of the first script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b") + 12).toSource(), "({start:85, length:13, index:1})", michael@0: "The right edge of the second script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c") + 12).toSource(), "({start:151, length:13, index:2})", michael@0: "The right edge of the third script was interpreted correctly."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a") + 13).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The right outside of the first script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b") + 13).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The right outside of the second script was interpreted correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c") + 13).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The right outside of the third script was interpreted correctly."); michael@0: michael@0: finish(); michael@0: }