@@ -21,6 +21,81 @@ test('element', function(t) {
2121 st . end ( )
2222 } )
2323
24+ t . test ( 'should transform attributes' , function ( st ) {
25+ var actual = toParse5 ( {
26+ type : 'element' ,
27+ tagName : 'div' ,
28+ properties : { } ,
29+ children : [
30+ {
31+ type : 'element' ,
32+ tagName : 'h1' ,
33+ properties : { id : 'a' , className : [ 'b' , 'c' ] , hidden : true , height : 2 } ,
34+ children : [
35+ { type : 'text' , value : 'alpha ' } ,
36+ {
37+ type : 'element' ,
38+ tagName : 'strong' ,
39+ properties : {
40+ style : 'color:red;' ,
41+ // Unknown booleans are ignored.
42+ ignored : false ,
43+ // Falsey known booleans are ignored.
44+ disabled : 0 ,
45+ // Unknown props are left as-is.
46+ foo : 'bar' ,
47+ // Unknown lists are space-separated.
48+ // Note: you’d expect `camelCase` here, but p5 lowercases
49+ // attributes on HTML, so it drops the camelcase.
50+ camelcase : [ 'on' , 'off' ] ,
51+ // Numeric-start data properties.
52+ data123 : '456' ,
53+ // Data properties.
54+ dataSome : 'yes' ,
55+ // ARIA props.
56+ ariaValuenow : '1'
57+ } ,
58+ children : [ { type : 'text' , value : 'bravo' } ]
59+ } ,
60+ { type : 'text' , value : ' charlie' }
61+ ]
62+ } ,
63+ {
64+ type : 'element' ,
65+ tagName : 'input' ,
66+ properties : {
67+ checked : true ,
68+ type : 'file' ,
69+ // Known comma-separated lists:
70+ accept : [ '.jpg' , '.jpeg' ]
71+ } ,
72+ children : [ ]
73+ }
74+ ]
75+ } )
76+
77+ var expected = parse5 . parseFragment (
78+ [
79+ '<div>' ,
80+ '<h1 id="a" class="b c" hidden height="2">' ,
81+ 'alpha ' ,
82+ '<strong style="color:red;" foo="bar" camelCase="on off" data-123="456" data-some="yes" aria-valuenow="1">' ,
83+ 'bravo' ,
84+ '</strong>' ,
85+ ' charlie' ,
86+ '</h1>' ,
87+ '<input checked type="file" accept=".jpg, .jpeg">' ,
88+ '</div>'
89+ ] . join ( '' )
90+ ) . childNodes [ 0 ]
91+
92+ delete expected . parentNode
93+
94+ st . deepEqual ( json ( actual ) , json ( expected ) )
95+
96+ st . end ( )
97+ } )
98+
2499 t . test ( 'should transform void elements' , function ( st ) {
25100 var actual = toParse5 ( {
26101 type : 'element' ,
0 commit comments