@@ -69,27 +69,32 @@ def concatenateCharacterTokens(tokens):
69
69
return outputTokens
70
70
71
71
def normalizeTokens (tokens ):
72
- """ convert array of attributes to a dictionary """
73
72
# TODO: convert tests to reflect arrays
74
73
for i , token in enumerate (tokens ):
75
74
if token [0 ] == u'ParseError' :
76
75
tokens [i ] = token [0 ]
77
- #token[2] = dict(token[2][::-1])
78
76
return tokens
79
77
80
- def tokensMatch (expectedTokens , recievedTokens ):
78
+ def tokensMatch (expectedTokens , receivedTokens , ignoreErrorOrder ):
81
79
"""Test whether the test has passed or failed
82
80
83
- For brevity in the tests, the test has passed if the sequence of expected
84
- tokens appears anywhere in the sequence of returned tokens.
81
+ If the ignoreErrorOrder flag is set to true we don't test the relative
82
+ positions of parse errors and non parse errors
85
83
"""
86
- return expectedTokens == recievedTokens
87
- for i , token in enumerate (recievedTokens ):
88
- if expectedTokens [0 ] == token :
89
- if (len (expectedTokens ) <= len (recievedTokens [i :]) and
90
- recievedTokens [i :i + len (expectedTokens )]):
91
- return True
92
- return False
84
+ if not ignoreErrorOrder :
85
+ return expectedTokens == receivedTokens
86
+ else :
87
+ #Sort the tokens into two groups; non-parse errors and parse errors
88
+ tokens = {"expected" :[[],[]], "received" :[[],[]]}
89
+ for tokenType , tokenList in zip (tokens .keys (),
90
+ (expectedTokens , receivedTokens )):
91
+ for token in tokenList :
92
+ if token != "ParseError" :
93
+ tokens [tokenType ][0 ].append (token )
94
+ else :
95
+ tokens [tokenType ][1 ].append (token )
96
+
97
+ return tokens ["expected" ] == tokens ["received" ]
93
98
94
99
95
100
class TestCase (unittest .TestCase ):
@@ -107,9 +112,11 @@ def runTokenizerTest(self, test):
107
112
test ['contentModelFlag' ] ,
108
113
"\n Input:" , str (test ['input' ]),
109
114
"\n Expected:" , str (output ),
110
- "\n Recieved :" , str (tokens )])
115
+ "\n received :" , str (tokens )])
111
116
tokens = normalizeTokens (tokens )
112
- self .assertEquals (tokensMatch (tokens , output ), True , errorMsg )
117
+ ignoreErrorOrder = test .get ('ignoreErrorOrder' , False )
118
+ self .assertEquals (tokensMatch (tokens , output , ignoreErrorOrder ), True ,
119
+ errorMsg )
113
120
114
121
def buildTestSuite ():
115
122
for filename in html5lib_test_files ('tokenizer' , '*.test' ):
0 commit comments