@@ -4,6 +4,52 @@ describe('HTML', function(){
44 return expect ( new HTML ( html ) . get ( ) ) ;
55 }
66
7+ describe ( 'htmlParser' , function ( ) {
8+ var handler , start , text ;
9+ beforeEach ( function ( ) {
10+ handler = {
11+ start : function ( tag , attrs , unary ) {
12+ start = {
13+ tag : tag ,
14+ attrs : attrs ,
15+ unary : unary
16+ } ;
17+ } ,
18+ chars : function ( text_ ) {
19+ text = text_ ;
20+ } ,
21+ end :function ( tag ) {
22+ expect ( tag ) . toEqual ( start . tag ) ;
23+ }
24+ } ;
25+ } ) ;
26+
27+ it ( 'should parse basic format' , function ( ) {
28+ htmlParser ( '<tag attr="value">text</tag>' , handler ) ;
29+ expect ( start ) . toEqual ( { tag :'tag' , attrs :{ attr :'value' } , unary :false } ) ;
30+ expect ( text ) . toEqual ( 'text' ) ;
31+ } ) ;
32+
33+ it ( 'should parse newlines in tags' , function ( ) {
34+ htmlParser ( '<\ntag\n attr="value"\n>text<\n/\ntag\n>' , handler ) ;
35+ expect ( start ) . toEqual ( { tag :'tag' , attrs :{ attr :'value' } , unary :false } ) ;
36+ expect ( text ) . toEqual ( 'text' ) ;
37+ } ) ;
38+
39+ it ( 'should parse newlines in attributes' , function ( ) {
40+ htmlParser ( '<tag attr="\nvalue\n">text</tag>' , handler ) ;
41+ expect ( start ) . toEqual ( { tag :'tag' , attrs :{ attr :'\nvalue\n' } , unary :false } ) ;
42+ expect ( text ) . toEqual ( 'text' ) ;
43+ } ) ;
44+
45+ it ( 'should parse namespace' , function ( ) {
46+ htmlParser ( '<ns:t-a-g ns:a-t-t-r="\nvalue\n">text</ns:t-a-g>' , handler ) ;
47+ expect ( start ) . toEqual ( { tag :'ns:t-a-g' , attrs :{ 'ns:a-t-t-r' :'\nvalue\n' } , unary :false } ) ;
48+ expect ( text ) . toEqual ( 'text' ) ;
49+ } ) ;
50+
51+ } ) ;
52+
753 it ( 'should echo html' , function ( ) {
854 expectHTML ( 'hello<b class="1\'23" align=\'""\'>world</b>.' ) .
955 toEqual ( 'hello<b class="1\'23" align="""">world</b>.' ) ;
0 commit comments