diff options
author | Craig Andrews <candrews@integralblue.com> | 2009-12-04 18:44:26 -0500 |
---|---|---|
committer | Craig Andrews <candrews@integralblue.com> | 2009-12-04 18:44:26 -0500 |
commit | aab7344002fd390e5b62a3eb82f3a418fd294617 (patch) | |
tree | b214e7d4b3e9f0ca9818fea9e3d9efa0249c00c6 /plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php | |
parent | 1fd7e5e3794621993b01a5833faa8b6fa26c3847 (diff) | |
parent | 01b089d9be046db1253cb3bb90e8635b50fddd84 (diff) |
Merge branch 'minify' into 0.9.x
Diffstat (limited to 'plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php')
-rw-r--r-- | plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php b/plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php new file mode 100644 index 000000000..56d07a2b5 --- /dev/null +++ b/plugins/Minify/extlib/minify/min_unit_tests/test_JSMin.php @@ -0,0 +1,63 @@ +<?php +require_once '_inc.php'; + +require_once 'JSMin.php'; + +function test_JSMin() +{ + global $thisDir; + + $src = file_get_contents($thisDir . '/_test_files/js/before.js'); + $minExpected = file_get_contents($thisDir . '/_test_files/js/before.min.js'); + $minOutput = JSMin::minify($src); + + $passed = assertTrue($minExpected == $minOutput, 'JSMin : Overall'); + + if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n"; + echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n"; + echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n"; + } + + $src = file_get_contents($thisDir . '/_test_files/js/issue74.js'); + $minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js'); + $minOutput = JSMin::minify($src); + + $passed = assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)'); + + if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n"; + echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n"; + echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n"; + + test_JSMin_exception('"Hello' + ,'Unterminated String' + ,'JSMin_UnterminatedStringException' + ,"Unterminated String: '\"Hello'"); + test_JSMin_exception("return /regexp\n}" + ,'Unterminated RegExp' + ,'JSMin_UnterminatedRegExpException' + ,"Unterminated RegExp: '/regexp\n'"); + test_JSMin_exception("/* Comment " + ,'Unterminated Comment' + ,'JSMin_UnterminatedCommentException' + ,"Unterminated Comment: '/* Comment '"); + } +} + +function test_JSMin_exception($js, $label, $expClass, $expMessage) { + $eClass = $eMsg = ''; + try { + JSMin::minify($js); + } catch (Exception $e) { + $eClass = get_class($e); + $eMsg = $e->getMessage(); + } + $passed = assertTrue($eClass === $expClass && $eMsg === $expMessage, + 'JSMin : throw on ' . $label); + if (! $passed && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + echo "\n ---" , $e, "\n\n"; + } +} + +test_JSMin(); |