diff --git a/tests/resources/controlchars.js b/tests/resources/controlchars.js new file mode 100644 index 0000000..8402bf1 Binary files /dev/null and b/tests/resources/controlchars.js differ diff --git a/tests/resources/controlchars/controlchars_ascii_ok.js b/tests/resources/controlchars/controlchars_ascii_ok.js new file mode 100644 index 0000000..d4497f2 --- /dev/null +++ b/tests/resources/controlchars/controlchars_ascii_ok.js @@ -0,0 +1 @@ +function test() {} \ No newline at end of file diff --git a/tests/resources/controlchars/controlchars_ascii_warn.js b/tests/resources/controlchars/controlchars_ascii_warn.js new file mode 100644 index 0000000..33ea849 Binary files /dev/null and b/tests/resources/controlchars/controlchars_ascii_warn.js differ diff --git a/tests/resources/controlchars/controlchars_bad.js b/tests/resources/controlchars/controlchars_bad.js new file mode 100644 index 0000000..8402bf1 Binary files /dev/null and b/tests/resources/controlchars/controlchars_bad.js differ diff --git a/tests/resources/controlchars/controlchars_utf-8_ok.js b/tests/resources/controlchars/controlchars_utf-8_ok.js new file mode 100644 index 0000000..acea215 --- /dev/null +++ b/tests/resources/controlchars/controlchars_utf-8_ok.js @@ -0,0 +1 @@ +function täst() {} \ No newline at end of file diff --git a/tests/resources/controlchars/controlchars_utf-8_warn.js b/tests/resources/controlchars/controlchars_utf-8_warn.js new file mode 100644 index 0000000..8c3c6d7 Binary files /dev/null and b/tests/resources/controlchars/controlchars_utf-8_warn.js differ diff --git a/tests/test_controlchars.py b/tests/test_controlchars.py new file mode 100644 index 0000000..89f36f4 --- /dev/null +++ b/tests/test_controlchars.py @@ -0,0 +1,42 @@ +import os + +import validator.testcases.charsethelper +import validator.testcases.scripting + +# Originated from bug 626496 + +def _do_test(path): + "Performs a test on a JS file" + script = validator.testcases.charsethelper.decode(open(path, "rb").read()) + + err = validator.testcases.scripting.traverser.MockBundler() + validator.testcases.scripting.test_js_file(err, path, script) + + return err + +def test_controlchars_ascii_ok(): + """Tests that multi-byte characters are decoded properly (utf-8)""" + + errs = _do_test("tests/resources/controlchars/controlchars_ascii_ok.js") + assert len(errs.ids) == 0 + +def test_controlchars_ascii_warn(): + """Tests that multi-byte characters are decoded properly (utf-8) + but remaining non ascii characters raise warnings""" + + errs = _do_test("tests/resources/controlchars/controlchars_ascii_warn.js") + assert len(errs.ids) == 1 and errs.ids[0][2] == "control_char_filter" + +def test_controlchars_utf8_ok(): + """Tests that multi-byte characters are decoded properly (utf-8)""" + + errs = _do_test("tests/resources/controlchars/controlchars_utf-8_ok.js") + assert len(errs.ids) == 0 + +def test_controlchars_utf8_warn(): + """Tests that multi-byte characters are decoded properly (utf-8) + but remaining non ascii characters raise warnings""" + + errs = _do_test("tests/resources/controlchars/controlchars_utf-8_warn.js") + assert len(errs.ids) == 1 and errs.ids[0][2] == "control_char_filter" +