From c6bdc743a4305af0f9e88921a03e993b9cbaf45b Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sun, 8 May 2016 18:02:40 +0100 Subject: [PATCH 1/7] Move the serializer testdata to html5lib-python as impl specific --- html5lib/tests/serializer-testdata/core.test | 125 +++ .../tests/serializer-testdata/injectmeta.test | 66 ++ .../serializer-testdata/optionaltags.test | 965 ++++++++++++++++++ .../tests/serializer-testdata/options.test | 60 ++ .../tests/serializer-testdata/whitespace.test | 51 + html5lib/tests/support.py | 4 +- html5lib/tests/test_serializer.py | 3 +- 7 files changed, 1271 insertions(+), 3 deletions(-) create mode 100644 html5lib/tests/serializer-testdata/core.test create mode 100644 html5lib/tests/serializer-testdata/injectmeta.test create mode 100644 html5lib/tests/serializer-testdata/optionaltags.test create mode 100644 html5lib/tests/serializer-testdata/options.test create mode 100644 html5lib/tests/serializer-testdata/whitespace.test diff --git a/html5lib/tests/serializer-testdata/core.test b/html5lib/tests/serializer-testdata/core.test new file mode 100644 index 00000000..c0b4222d --- /dev/null +++ b/html5lib/tests/serializer-testdata/core.test @@ -0,0 +1,125 @@ +{"tests": [ + +{"description": "proper attribute value escaping", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "test \"with\" ""}]]], + "expected": [""] +}, + +{"description": "proper attribute value non-quoting", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo"}]]], + "expected": [""], + "xhtml": [""] +}, + +{"description": "proper attribute value non-quoting (with <)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo"], + "xhtml": [""] +}, + +{"description": "proper attribute value quoting (with =)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo=bar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with >)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo>bar"}]]], + "expected": ["bar\">"] +}, + +{"description": "proper attribute value quoting (with \")", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\"bar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with ')", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo'bar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with both \" and ')", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo'bar\"baz"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with space)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo bar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with tab)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\tbar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with LF)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\nbar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value quoting (with CR)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\rbar"}]]], + "expected": [""] +}, + +{"description": "proper attribute value non-quoting (with linetab)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\u000Bbar"}]]], + "expected": [""], + "xhtml": [""] +}, + +{"description": "proper attribute value quoting (with form feed)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\u000Cbar"}]]], + "expected": [""] +}, + +{"description": "void element (as EmptyTag token)", + "input": [["EmptyTag", "img", {}]], + "expected": [""], + "xhtml": [""] +}, + +{"description": "void element (as StartTag token)", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "img", {}]], + "expected": [""], + "xhtml": [""] +}, + +{"description": "doctype in error", + "input": [["Doctype", "foo"]], + "expected": [""] +}, + +{"description": "character data", + "options": {"encoding":"utf-8"}, + "input": [["Characters", "ac&d"]], + "expected": ["a<b>c&d"] +}, + +{"description": "rcdata", + "input": [["StartTag", "http://www.w3.org/1999/xhtml", "script", {}], ["Characters", "ac&d"]], + "expected": [""] +}, + +{"description": "text within "] +} + +]} \ No newline at end of file diff --git a/html5lib/tests/support.py b/html5lib/tests/support.py index 54a64a85..6e6a916b 100644 --- a/html5lib/tests/support.py +++ b/html5lib/tests/support.py @@ -69,8 +69,8 @@ } -def get_data_files(subdirectory, files='*.dat'): - return sorted(glob.glob(os.path.join(test_dir, subdirectory, files))) +def get_data_files(subdirectory, files='*.dat', search_dir=test_dir): + return sorted(glob.glob(os.path.join(search_dir, subdirectory, files))) class DefaultDict(dict): diff --git a/html5lib/tests/test_serializer.py b/html5lib/tests/test_serializer.py index af76075e..c7e9d7ed 100644 --- a/html5lib/tests/test_serializer.py +++ b/html5lib/tests/test_serializer.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, division, unicode_literals +import os import json import unittest @@ -170,7 +171,7 @@ def testEntityNoResolve(self): def test_serializer(): - for filename in get_data_files('serializer', '*.test'): + for filename in get_data_files('serializer-testdata', '*.test', os.path.dirname(__file__)): with open(filename) as fp: tests = json.load(fp) for index, test in enumerate(tests['tests']): From b7a37d296562392170a406cf611adaf2821c9390 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sun, 8 May 2016 18:12:26 +0100 Subject: [PATCH 2/7] Reindent serializer testdata --- html5lib/tests/serializer-testdata/core.test | 552 ++- .../tests/serializer-testdata/injectmeta.test | 444 +- .../serializer-testdata/optionaltags.test | 4219 +++++++++++++---- .../tests/serializer-testdata/options.test | 265 +- .../tests/serializer-testdata/whitespace.test | 249 +- 5 files changed, 4462 insertions(+), 1267 deletions(-) diff --git a/html5lib/tests/serializer-testdata/core.test b/html5lib/tests/serializer-testdata/core.test index c0b4222d..0f3092bb 100644 --- a/html5lib/tests/serializer-testdata/core.test +++ b/html5lib/tests/serializer-testdata/core.test @@ -1,125 +1,427 @@ -{"tests": [ - -{"description": "proper attribute value escaping", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "test \"with\" ""}]]], - "expected": [""] -}, - -{"description": "proper attribute value non-quoting", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo"}]]], - "expected": [""], - "xhtml": [""] -}, - -{"description": "proper attribute value non-quoting (with <)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo"], - "xhtml": [""] -}, - -{"description": "proper attribute value quoting (with =)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo=bar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with >)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo>bar"}]]], - "expected": ["bar\">"] -}, - -{"description": "proper attribute value quoting (with \")", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\"bar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with ')", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo'bar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with both \" and ')", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo'bar\"baz"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with space)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo bar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with tab)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\tbar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with LF)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\nbar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value quoting (with CR)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\rbar"}]]], - "expected": [""] -}, - -{"description": "proper attribute value non-quoting (with linetab)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\u000Bbar"}]]], - "expected": [""], - "xhtml": [""] -}, - -{"description": "proper attribute value quoting (with form feed)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "span", [{"namespace": null, "name": "title", "value": "foo\u000Cbar"}]]], - "expected": [""] -}, - -{"description": "void element (as EmptyTag token)", - "input": [["EmptyTag", "img", {}]], - "expected": [""], - "xhtml": [""] -}, - -{"description": "void element (as StartTag token)", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "img", {}]], - "expected": [""], - "xhtml": [""] -}, - -{"description": "doctype in error", - "input": [["Doctype", "foo"]], - "expected": [""] -}, - -{"description": "character data", - "options": {"encoding":"utf-8"}, - "input": [["Characters", "ac&d"]], - "expected": ["a<b>c&d"] -}, - -{"description": "rcdata", - "input": [["StartTag", "http://www.w3.org/1999/xhtml", "script", {}], ["Characters", "ac&d"]], - "expected": [""] -}, - -{"description": "text within "] -} - -]} \ No newline at end of file +{ + "tests": [ + { + "expected": [ + " foo" + ], + "input": [ + [ + "Characters", + "\t\r\n\f foo" + ] + ], + "description": "bare text with leading spaces", + "options": { + "strip_whitespace": true + } + }, + { + "expected": [ + "foo " + ], + "input": [ + [ + "Characters", + "foo \t\r\n\f" + ] + ], + "description": "bare text with trailing spaces", + "options": { + "strip_whitespace": true + } + }, + { + "expected": [ + "foo bar" + ], + "input": [ + [ + "Characters", + "foo \t\r\n\f bar" + ] + ], + "description": "bare text with inner spaces", + "options": { + "strip_whitespace": true + } + }, + { + "expected": [ + "
\t\r\n\f foo \t\r\n\f bar \t\r\n\f
" + ], + "input": [ + [ + "StartTag", + "http://www.w3.org/1999/xhtml", + "pre", + {} + ], + [ + "Characters", + "\t\r\n\f foo \t\r\n\f bar \t\r\n\f" + ], + [ + "EndTag", + "http://www.w3.org/1999/xhtml", + "pre" + ] + ], + "description": "text within
",
+            "options": {
+                "strip_whitespace": true
+            }
+        },
+        {
+            "expected": [
+                "
\t\r\n\f foo \t\r\n\f bar \t\r\n\f
" + ], + "input": [ + [ + "StartTag", + "http://www.w3.org/1999/xhtml", + "pre", + {} + ], + [ + "Characters", + "\t\r\n\f fo" + ], + [ + "StartTag", + "http://www.w3.org/1999/xhtml", + "span", + {} + ], + [ + "Characters", + "o \t\r\n\f b" + ], + [ + "EndTag", + "http://www.w3.org/1999/xhtml", + "span" + ], + [ + "Characters", + "ar \t\r\n\f" + ], + [ + "EndTag", + "http://www.w3.org/1999/xhtml", + "pre" + ] + ], + "description": "text within
, with inner markup",
+            "options": {
+                "strip_whitespace": true
+            }
+        },
+        {
+            "expected": [
+                ""
+            ],
+            "input": [
+                [
+                    "StartTag",
+                    "http://www.w3.org/1999/xhtml",
+                    "textarea",
+                    {}
+                ],
+                [
+                    "Characters",
+                    "\t\r\n\f foo \t\r\n\f bar \t\r\n\f"
+                ],
+                [
+                    "EndTag",
+                    "http://www.w3.org/1999/xhtml",
+                    "textarea"
+                ]
+            ],
+            "description": "text within