From bf43ab6d30846b1ac856ae5c033019f50fe3a152 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Sat, 21 Feb 2009 11:34:08 +0000 Subject: [PATCH] Added diffs to static and visual markup side-by-side tests --- external/jsdiff/jsdiff.js | 159 ++++++++++++++++++ tests/index.html | 84 +++------ tests/slider.html | 63 +++++++ tests/static/draggable/default.html | 6 +- tests/static/droppable/default.html | 4 +- tests/static/slider/default.html | 4 +- tests/static/slider/default_vertical.html | 4 +- tests/static/slider/slider_horizontal.html | 4 +- .../slider/slider_horizontal_range.html | 6 +- .../slider/slider_horizontal_range_max.html | 5 +- .../slider/slider_horizontal_range_min.html | 5 +- tests/static/slider/slider_vertical.html | 4 +- .../static/slider/slider_vertical_range.html | 6 +- .../slider/slider_vertical_range_max.html | 5 +- .../slider/slider_vertical_range_min.html | 5 +- tests/static/sortable/default.html | 6 +- tests/static/tabs/default.html | 6 +- tests/tests.css | 8 + tests/tests.js | 56 ++++++ tests/visual/dialog/default.html | 4 +- tests/visual/draggable/default.html | 8 +- tests/visual/droppable/default.html | 8 +- tests/visual/resizable/default.html | 6 +- tests/visual/selectable/default.html | 1 - tests/visual/slider/default.html | 4 +- tests/visual/slider/default_vertical.html | 23 +++ tests/visual/slider/slider_horizontal.html | 4 +- .../slider/slider_horizontal_range.html | 4 +- .../slider/slider_horizontal_range_max.html | 4 +- .../slider/slider_horizontal_range_min.html | 4 +- tests/visual/slider/slider_vertical.html | 4 +- .../visual/slider/slider_vertical_range.html | 4 +- .../slider/slider_vertical_range_max.html | 4 +- .../slider/slider_vertical_range_min.html | 4 +- tests/visual/sortable/default.html | 9 +- 35 files changed, 381 insertions(+), 154 deletions(-) create mode 100644 external/jsdiff/jsdiff.js create mode 100644 tests/slider.html create mode 100644 tests/tests.css create mode 100644 tests/tests.js create mode 100644 tests/visual/slider/default_vertical.html diff --git a/external/jsdiff/jsdiff.js b/external/jsdiff/jsdiff.js new file mode 100644 index 000000000..31c3a273e --- /dev/null +++ b/external/jsdiff/jsdiff.js @@ -0,0 +1,159 @@ +/* + * Javascript Diff Algorithm + * By John Resig (http://ejohn.org/) + * Modified by Chu Alan "sprite" + * + * More Info: + * http://ejohn.org/projects/javascript-diff-algorithm/ + */ + +function escape(s) { + var n = s; + n = n.replace(/&/g, "&"); + n = n.replace(//g, ">"); + n = n.replace(/"/g, """); + + return n; +} + +function diffString( o, n ) { + o = o.replace(/\s+$/, ''); + n = n.replace(/\s+$/, ''); + + var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) ); + var str = ""; + + var oSpace = o.match(/\s+/g); + if (oSpace == null) { + oSpace = ["\n"]; + } else { + oSpace.push("\n"); + } + var nSpace = n.match(/\s+/g); + if (nSpace == null) { + nSpace = ["\n"]; + } else { + nSpace.push("\n"); + } + + if (out.n.length == 0) { + for (var i = 0; i < out.o.length; i++) { + str += '' + escape(out.o[i]) + oSpace[i] + ""; + } + } else { + if (out.n[0].text == null) { + for (n = 0; n < out.o.length && out.o[n].text == null; n++) { + str += '' + escape(out.o[n]) + oSpace[n] + ""; + } + } + + for ( var i = 0; i < out.n.length; i++ ) { + if (out.n[i].text == null) { + str += '' + escape(out.n[i]) + nSpace[i] + ""; + } else { + var pre = ""; + + for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { + pre += '' + escape(out.o[n]) + oSpace[n] + ""; + } + str += " " + out.n[i].text + nSpace[i] + pre; + } + } + } + + return str; +} + +function randomColor() { + return "rgb(" + (Math.random() * 100) + "%, " + + (Math.random() * 100) + "%, " + + (Math.random() * 100) + "%)"; +} +function diffString2( o, n ) { + o = o.replace(/\s+$/, ''); + n = n.replace(/\s+$/, ''); + + var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) ); + + var oSpace = o.match(/\s+/g); + if (oSpace == null) { + oSpace = ["\n"]; + } else { + oSpace.push("\n"); + } + var nSpace = n.match(/\s+/g); + if (nSpace == null) { + nSpace = ["\n"]; + } else { + nSpace.push("\n"); + } + + var os = ""; + var colors = new Array(); + for (var i = 0; i < out.o.length; i++) { + colors[i] = randomColor(); + + if (out.o[i].text != null) { + os += '' + + escape(out.o[i].text) + oSpace[i] + ""; + } else { + os += "" + escape(out.o[i]) + oSpace[i] + ""; + } + } + + var ns = ""; + for (var i = 0; i < out.n.length; i++) { + if (out.n[i].text != null) { + ns += '' + + escape(out.n[i].text) + nSpace[i] + ""; + } else { + ns += "" + escape(out.n[i]) + nSpace[i] + ""; + } + } + + return { o : os , n : ns }; +} + +function diff( o, n ) { + var ns = new Object(); + var os = new Object(); + + for ( var i = 0; i < n.length; i++ ) { + if ( ns[ n[i] ] == null ) + ns[ n[i] ] = { rows: new Array(), o: null }; + ns[ n[i] ].rows.push( i ); + } + + for ( var i = 0; i < o.length; i++ ) { + if ( os[ o[i] ] == null ) + os[ o[i] ] = { rows: new Array(), n: null }; + os[ o[i] ].rows.push( i ); + } + + for ( var i in ns ) { + if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) { + n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] }; + o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] }; + } + } + + for ( var i = 0; i < n.length - 1; i++ ) { + if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && + n[i+1] == o[ n[i].row + 1 ] ) { + n[i+1] = { text: n[i+1], row: n[i].row + 1 }; + o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 }; + } + } + + for ( var i = n.length - 1; i > 0; i-- ) { + if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && + n[i-1] == o[ n[i].row - 1 ] ) { + n[i-1] = { text: n[i-1], row: n[i].row - 1 }; + o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 }; + } + } + + return { o: o, n: n }; +} + diff --git a/tests/index.html b/tests/index.html index 2c2968408..da3700d93 100644 --- a/tests/index.html +++ b/tests/index.html @@ -4,16 +4,10 @@ jQuery UI Tests - - - + + + - @@ -22,75 +16,37 @@ + + + - - - - - + + + + + + + + - - - - - - + + + + + +
Interaction Static VisualStaticVisualDiff
Draggable
Droppable
Resizable
Selectable
Sortable
Draggable
Droppable
Resizable
Sortable
Widget Static VisualStaticVisualDiff
Accordion
Datepicker
Dialog
Progressbar
slider
Tabs
Accordion
Datepicker
Dialog
Progressbar
slider
Tabs
-
- -
- - - diff --git a/tests/slider.html b/tests/slider.html new file mode 100644 index 000000000..78d86d95c --- /dev/null +++ b/tests/slider.html @@ -0,0 +1,63 @@ + + + + jQuery UI Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Slider TestsStaticVisualStaticVisualDiff
Default
Vertical
Horizontal Slider TestsStaticVisualStaticVisualDiff
Horizontal
Horizontal range
Horizontal range max
Horizontal range min
Vertical Slider TestsStaticVisualStaticVisualDiff
Vertical
Vertical range
Vertical range max
Vertical range min
+ + + diff --git a/tests/static/draggable/default.html b/tests/static/draggable/default.html index 3bf844b18..d5d92ef25 100644 --- a/tests/static/draggable/default.html +++ b/tests/static/draggable/default.html @@ -10,11 +10,7 @@ -
-

- Draggable -

-
+

Draggable

diff --git a/tests/static/droppable/default.html b/tests/static/droppable/default.html index c010ab767..61504bc18 100644 --- a/tests/static/droppable/default.html +++ b/tests/static/droppable/default.html @@ -10,9 +10,7 @@ -
- Droppable -
+

Droppable

diff --git a/tests/static/slider/default.html b/tests/static/slider/default.html index 2bda5f322..fba92d9eb 100644 --- a/tests/static/slider/default.html +++ b/tests/static/slider/default.html @@ -10,9 +10,7 @@ -
- -
+
diff --git a/tests/static/slider/default_vertical.html b/tests/static/slider/default_vertical.html index b47dc4bbb..208c3c77c 100644 --- a/tests/static/slider/default_vertical.html +++ b/tests/static/slider/default_vertical.html @@ -10,9 +10,7 @@ -
- -
+
diff --git a/tests/static/slider/slider_horizontal.html b/tests/static/slider/slider_horizontal.html index c4275d608..de510a835 100644 --- a/tests/static/slider/slider_horizontal.html +++ b/tests/static/slider/slider_horizontal.html @@ -10,9 +10,7 @@ -
- -
+
diff --git a/tests/static/slider/slider_horizontal_range.html b/tests/static/slider/slider_horizontal_range.html index 7ab6e6cd7..d19babde8 100644 --- a/tests/static/slider/slider_horizontal_range.html +++ b/tests/static/slider/slider_horizontal_range.html @@ -10,11 +10,7 @@ -
-
- - -
+
diff --git a/tests/static/slider/slider_horizontal_range_max.html b/tests/static/slider/slider_horizontal_range_max.html index 03466e3f8..e0f3d0080 100644 --- a/tests/static/slider/slider_horizontal_range_max.html +++ b/tests/static/slider/slider_horizontal_range_max.html @@ -10,10 +10,7 @@ -
-
- -
+
diff --git a/tests/static/slider/slider_horizontal_range_min.html b/tests/static/slider/slider_horizontal_range_min.html index 72741b0dc..7c553668d 100644 --- a/tests/static/slider/slider_horizontal_range_min.html +++ b/tests/static/slider/slider_horizontal_range_min.html @@ -10,10 +10,7 @@ -
-
- -
+
diff --git a/tests/static/slider/slider_vertical.html b/tests/static/slider/slider_vertical.html index 75579caea..dc729cf40 100644 --- a/tests/static/slider/slider_vertical.html +++ b/tests/static/slider/slider_vertical.html @@ -10,9 +10,7 @@ -
- -
+
diff --git a/tests/static/slider/slider_vertical_range.html b/tests/static/slider/slider_vertical_range.html index deb839c0b..f0a772b13 100644 --- a/tests/static/slider/slider_vertical_range.html +++ b/tests/static/slider/slider_vertical_range.html @@ -10,11 +10,7 @@ -
-
- - -
+
diff --git a/tests/static/slider/slider_vertical_range_max.html b/tests/static/slider/slider_vertical_range_max.html index e7bac01a1..d35e1e455 100644 --- a/tests/static/slider/slider_vertical_range_max.html +++ b/tests/static/slider/slider_vertical_range_max.html @@ -10,10 +10,7 @@ -
-
- -
+
diff --git a/tests/static/slider/slider_vertical_range_min.html b/tests/static/slider/slider_vertical_range_min.html index 6494688ee..946428f2d 100644 --- a/tests/static/slider/slider_vertical_range_min.html +++ b/tests/static/slider/slider_vertical_range_min.html @@ -10,10 +10,7 @@ -
-
- -
+
diff --git a/tests/static/sortable/default.html b/tests/static/sortable/default.html index 88d150aa5..bd70859f6 100644 --- a/tests/static/sortable/default.html +++ b/tests/static/sortable/default.html @@ -10,11 +10,7 @@ -
-
Sortable 1
-
Sortable 2
-
Sortable 3
-
+
Sortable 1
Sortable 2
Sortable 3
diff --git a/tests/static/tabs/default.html b/tests/static/tabs/default.html index 66dd06da9..d99e8b75c 100644 --- a/tests/static/tabs/default.html +++ b/tests/static/tabs/default.html @@ -1,15 +1,15 @@ - jQuery UI Tabs Static Markup Test Page + Tabs Static Test : Default + - + -