1
+ /* bender-tags: editor,unit,utils */
2
+
3
+ ( function ( ) {
4
+ 'use strict' ;
5
+
6
+ var compatHtmlArgs ,
7
+ originalCompatHtml = bender . tools . compatHtml ,
8
+ htmlTools = bender . tools . html ;
9
+
10
+ bender . tools . compatHtml = function ( html , noInterWS , sortAttributes , fixZWS , fixStyles , fixNbsp ) {
11
+ compatHtmlArgs = {
12
+ noInterWS : ! ! noInterWS ,
13
+ sortAttributes : ! ! sortAttributes ,
14
+ fixZWS : ! ! fixZWS ,
15
+ fixStyles : ! ! fixStyles ,
16
+ fixNbsp : ! ! fixNbsp
17
+ } ;
18
+
19
+ return originalCompatHtml . call ( bender . tools , html , noInterWS , sortAttributes , fixZWS , fixStyles , fixNbsp ) ;
20
+ } ;
21
+
22
+ function t ( ret , expected , actual , options , expectedCompatHtmlArgs ) {
23
+ return function ( ) {
24
+ // In case compatHtml was not called at all.
25
+ compatHtmlArgs = { } ;
26
+ assert . areSame ( ret , htmlTools . compareInnerHtml ( expected , actual , options ) , 'returned value' ) ;
27
+
28
+ if ( expectedCompatHtmlArgs ) {
29
+ for ( var arg in expectedCompatHtmlArgs ) {
30
+ assert . areSame ( expectedCompatHtmlArgs [ arg ] , compatHtmlArgs [ arg ] ,
31
+ 'compatHtml\'s argument: ' + arg ) ;
32
+ }
33
+ }
34
+ } ;
35
+ }
36
+
37
+ bender . test ( {
38
+ // Options ------------------------------------------------------------
39
+
40
+ 'opts.noInterWS defaults to false' : t ( true , '' , '' , null , { noInterWS : false } ) ,
41
+ 'opts.noInterWS defaults to false 2' : t ( true , '' , '' , { } , { noInterWS : false } ) ,
42
+ 'opts.noInterWS is passed' : t ( true , '' , '' , { noInterWS : true } , { noInterWS : true } ) ,
43
+
44
+ 'opts.fixStyles defaults to false' : t ( true , '' , '' , null , { fixStyles : false } ) ,
45
+ 'opts.fixStyles is passed' : t ( true , '' , '' , { fixStyles : true } , { fixStyles : true } ) ,
46
+
47
+ 'opts.sortAttributes defaults to true' : t ( true , '' , '' , null , { sortAttributes : true } ) ,
48
+ 'opts.fixZWS defaults to true' : t ( true , '' , '' , null , { fixZWS : true } ) ,
49
+ 'opts.fixNbsp defaults to true' : t ( true , '' , '' , null , { fixNbsp : true } ) ,
50
+
51
+ 'multiple opts' : t ( true , '' , '' , { fixNbsp : false , fixStyles : true } , { fixZWS : true , fixNbsp : false , fixStyles : true } ) ,
52
+
53
+ // Passing ------------------------------------------------------------
54
+
55
+ 'simple string' : t ( true , 'foo' , 'foo' ) ,
56
+ 'simple element' : t ( true , '<b>foo</b>' , '<B>foo</B>' ) ,
57
+ 'bogus expected, not exists' : t ( true , 'a@' , 'a' ) ,
58
+ 'bogus expected, exists' : t ( true , 'a@' , 'a<br />' ) ,
59
+ 'multiple boguses' : t ( true , '<p>a@</p><p>b@</p><p>c@</p>' , '<p>a<br /></p><p>b</p><p>c<br /></p>' ) ,
60
+ 'regexp conflict [' : t ( true , 'ba[r' , 'ba[r' ) ,
61
+
62
+ 'markers 1 - no opts.compareSelection' : t ( true , 'ba[r]' , 'ba[r]' ) ,
63
+ 'markers 2 - no opts.compareSelection' : t ( true , 'ba{}r' , 'ba{}r' ) ,
64
+ 'markers 3 - no opts.compareSelection' : t ( true , '<ul><li>[</li><li>a</li></ul>' , '<ul>[<li>a</li></ul>' ) ,
65
+
66
+ 'markers 1 - opts.compareSelection' : t ( true , 'ba[r}' , 'ba[r}' , { compareSelection : true } ) ,
67
+ 'markers 2 - opts.compareSelection' : t ( true , 'ba{}r' , 'ba{}r' , { compareSelection : true } ) ,
68
+ 'markers 3 - opts.compareSelection' : t ( true , 'ba[]r' , 'ba[]r' , { compareSelection : true } ) ,
69
+ 'markers 4 - opts.compareSelection' : t ( true , '<ul>[<li>a</li>]</ul>' , '<ul>[<li>a</li>]</ul>' , { compareSelection : true } ) ,
70
+
71
+ 'markers 1 - opts.compare&normalizeSelection' : t ( true , 'ba[r]' , 'ba{r}' , { compareSelection : true , normalizeSelection : true } ) ,
72
+ 'markers 2 - opts.compare&normalizeSelection' : t ( true , 'ba^r' , 'ba{}r' , { compareSelection : true , normalizeSelection : true } ) ,
73
+ 'markers 3 - opts.compare&normalizeSelection' : t ( true , 'ba^r' , 'ba[]r' , { compareSelection : true , normalizeSelection : true } ) ,
74
+ 'markers 4 - opts.compare&normalizeSelection' : t ( true , '<ul>[<li>a</li>]</ul>' , '<ul>[<li>a</li>]</ul>' , { compareSelection : true , normalizeSelection : true } ) ,
75
+
76
+ // Failing ------------------------------------------------------------
77
+
78
+ 'simple string - fail' : t ( false , 'foo' , 'bar' ) ,
79
+ 'simple element - fail' : t ( false , '<b>foo</b>' , '<I>foo</I>' ) ,
80
+ 'not expected bogus - fail' : t ( false , '<p>foo<br /></p>' , '<p>foo</p>' ) ,
81
+
82
+ // Expected part has to be regexified if special characters are not escaped
83
+ // bad things may happen.
84
+ 'regexp conflict * - fail' : t ( false , 'ba*r' , 'br' ) ,
85
+ 'regexp - partial match - start - fail' : t ( false , 'bar' , 'barx' ) ,
86
+ 'regexp - partial match - end - fail' : t ( false , 'bar' , 'xbar' ) ,
87
+
88
+ 'markers 1 - no opts.compareSelection - fail' : t ( false , 'bar' , 'ba[]r' ) ,
89
+ 'markers 2 - no opts.compareSelection - fail' : t ( false , 'ba{}r' , 'ba[]r' ) ,
90
+ 'markers - opts.compareSelection - fail' : t ( false , 'ba{}r' , 'ba[]r' , { compareSelection : true } ) ,
91
+ 'markers - opts.compare&normalizeSelection - fail' : t ( false , 'ba[]r' , 'ba[]r' , { compareSelection : true , normalizeSelection : true } ) ,
92
+ } ) ;
93
+ } ) ( ) ;
0 commit comments