|
1 | 1 | from __future__importabsolute_import,division,unicode_literals |
2 | 2 |
|
3 | | -fromsiximportPY2,text_type |
| 3 | +fromsiximportPY2,text_type,unichr |
4 | 4 |
|
5 | 5 | importio |
6 | 6 |
|
7 | 7 | from .importsupport# noqa |
8 | 8 |
|
9 | | -fromhtml5lib.constantsimportnamespaces |
| 9 | +fromhtml5lib.constantsimportnamespaces,tokenTypes |
10 | 10 | fromhtml5libimportparse,parseFragment,HTMLParser |
11 | 11 |
|
12 | 12 |
|
@@ -53,13 +53,42 @@ def test_unicode_file(): |
53 | 53 | assertparse(io.StringIO("a"))isnotNone |
54 | 54 |
|
55 | 55 |
|
| 56 | +deftest_maintain_attribute_order(): |
| 57 | +# This is here because we impl it in parser and not tokenizer |
| 58 | +p=HTMLParser() |
| 59 | +# generate loads to maximize the chance a hash-based mutation will occur |
| 60 | +attrs= [(unichr(x),i)fori,xinenumerate(range(ord('a'),ord('z')))] |
| 61 | +token= {'name':'html', |
| 62 | +'selfClosing':False, |
| 63 | +'selfClosingAcknowledged':False, |
| 64 | +'type':tokenTypes["StartTag"], |
| 65 | +'data':attrs} |
| 66 | +out=p.normalizeToken(token) |
| 67 | +attr_order=list(out["data"].keys()) |
| 68 | +assertattr_order== [xforx,iinattrs] |
| 69 | + |
| 70 | + |
56 | 71 | deftest_duplicate_attribute(): |
57 | 72 | # This is here because we impl it in parser and not tokenizer |
58 | 73 | doc=parse('<p class=a class=b>') |
59 | 74 | el=doc[1][0] |
60 | 75 | assertel.get("class")=="a" |
61 | 76 |
|
62 | 77 |
|
| 78 | +deftest_maintain_duplicate_attribute_order(): |
| 79 | +# This is here because we impl it in parser and not tokenizer |
| 80 | +p=HTMLParser() |
| 81 | +attrs= [(unichr(x),i)fori,xinenumerate(range(ord('a'),ord('z')))] |
| 82 | +token= {'name':'html', |
| 83 | +'selfClosing':False, |
| 84 | +'selfClosingAcknowledged':False, |
| 85 | +'type':tokenTypes["StartTag"], |
| 86 | +'data':attrs+ [('a',len(attrs))]} |
| 87 | +out=p.normalizeToken(token) |
| 88 | +attr_order=list(out["data"].keys()) |
| 89 | +assertattr_order== [xforx,iinattrs] |
| 90 | + |
| 91 | + |
63 | 92 | deftest_debug_log(): |
64 | 93 | parser=HTMLParser(debug=True) |
65 | 94 | parser.parse("<!doctype html><title>a</title><p>b<script>c</script>d</p>e") |
|