@@ -33,16 +33,38 @@ var total = TESTS.length, failures = 0,
33
33
for ( i = 0 ; i < total ; i ++ ) {
34
34
test = TESTS [ i ] ;
35
35
tokens = parseCss . tokenize ( test . css ) ;
36
- parser = parseCss [ typeof test . parser === 'string' ? test . parser : 'parseAStylesheet' ] ;
37
- result = ( typeof parser === 'function' ) ? parser ( tokens ) : tokens ;
38
- dump = JSON . stringify ( result , null , ' ' ) ;
39
- expected_dump = JSON . stringify ( test . expected , null , ' ' ) ;
40
- if ( dump == expected_dump ) {
41
- log ( `Test ${ i } of ${ total } : PASS` ) ;
42
- } else {
43
- log ( `Test ${ i } of ${ total } : FAIL\nCSS: ${ test . css } \nTokens: ${ tokens . join ( ' ' ) } ` ) ;
44
- log ( ansidiff . lines ( expected_dump , dump ) ) ;
45
- failures ++ ;
36
+ try {
37
+ parser = parseCss [ typeof test . parser === 'string' ? test . parser : 'parseAStylesheet' ] ;
38
+ result = ( typeof parser === 'function' ) ? parser ( tokens ) : tokens ;
39
+ if ( test . expectedThrow ) {
40
+ log ( `Test ${ i } of ${ total } : FAIL\nCSS: ${ test . css } \nTokens: ${ tokens . join ( ' ' ) } ` ) ;
41
+ log ( `Expected error not thrown: ` + ansidiff . words ( test . expectedThrow . name , '' ) ) ;
42
+ failures ++ ;
43
+ continue ;
44
+ }
45
+ dump = JSON . stringify ( result , null , ' ' ) ;
46
+ expected_dump = JSON . stringify ( test . expected , null , ' ' ) ;
47
+ if ( dump == expected_dump ) {
48
+ log ( `Test ${ i } of ${ total } : PASS` ) ;
49
+ } else {
50
+ log ( `Test ${ i } of ${ total } : FAIL\nCSS: ${ test . css } \nTokens: ${ tokens . join ( ' ' ) } ` ) ;
51
+ log ( ansidiff . lines ( expected_dump , dump ) ) ;
52
+ failures ++ ;
53
+ }
54
+ } catch ( ex ) {
55
+ if ( test . expectedThrow ) {
56
+ if ( ex . name === test . expectedThrow . name ) {
57
+ log ( `Test ${ i } of ${ total } : PASS` ) ;
58
+ } else {
59
+ log ( `Test ${ i } of ${ total } : FAIL\nCSS: ${ test . css } \nTokens: ${ tokens . join ( ' ' ) } ` ) ;
60
+ log ( `Expected error not thrown: ` + ansidiff . words ( test . expectedThrow . name , ex . name ) ) ;
61
+ failures ++ ;
62
+ }
63
+ } else {
64
+ log ( `Test ${ i } of ${ total } : FAIL\nCSS: ${ test . css } \nTokens: ${ tokens . join ( ' ' ) } ` ) ;
65
+ log ( ansidiff . words ( `Unexpected error: ${ ex } ` , `` ) ) ;
66
+ failures ++ ;
67
+ }
46
68
}
47
69
}
48
70
0 commit comments