Skip to content

Commit 2e8aaec

Browse files
big fix: delimiter was not being replaced
add unit test for delimiter fail unit test if crushed is larger
1 parent 44d4d6b commit 2e8aaec

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

β€ŽJSONCrush.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function JSONCrush(string)
132132
}
133133

134134
// remove delimiter if it is found in the string
135-
string = string.replace(new RegExp(delimiter,'g'));
135+
string = string.replace(new RegExp(delimiter,'g'),'');
136136

137137
// swap out common json characters
138138
string = JSONCrushSwap(string);

β€ŽJSONCrush.min.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žindex.htmlβ€Ž

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<br>
4343
<br>
4444
<br><div id=div_unit_test_results></div>
45-
<script src="JSONCrush.js?8"></script>
45+
<script src="JSONCrush.js?9"></script>
4646
<script>
4747

4848
"use strict"; // strict mode
@@ -100,10 +100,18 @@
100100
let percent = (100*length2/length1).toFixed(2) + '%';
101101

102102
output += '<pre>' + test + '</pre>';
103-
if (test == uncrushed)
104-
output += 'PASS!' + ' Size Difference: ' + percent;
103+
if (test != uncrushed)
104+
{
105+
output += 'FAIL! '
106+
if (error)
107+
output += 'Error: ' + error;
108+
else
109+
output += "Crushed string doesn't match: '" + uncrushed + "'";
110+
}
111+
else if (length2 > length1)
112+
output += 'FAIL! Compressed is larger. ' + ' Size Difference: ' + percent;
105113
else
106-
output += 'FAIL! ' + error;
114+
output += 'PASS!' + ' Size Difference: ' + percent;
107115
output += '<br><br>';
108116
}
109117

@@ -119,6 +127,7 @@
119127
'emojis: πŸ˜„πŸ°πŸ’ β˜‚πŸ‘β˜• Β©Β₯Γ± ✌β™₯☻␌',
120128
'compressed emojis: aaπŸ˜„aaπŸ˜„aaπŸ˜„aaπŸ˜„aa🐰🐒🐰🐒🐰🐒🐰🐒🐰🐰🐒🐰🐒🐰🐒🐰🐒🐰🐰🐒🐰🐒🐰🐒🐰🐒🐰',
121129
'aaaaaaaa',
130+
'This test should fail because delimiters \u0001\u0001\u0001\u0001 (\\u0001) will be removed.',
122131
];
123132

124133
</script>

0 commit comments

Comments
Β (0)