1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?php
require_once '_inc.php';
require_once 'JSMinPlus.php';
function test_JSMinPlus()
{
global $thisDir;
$src = file_get_contents($thisDir . '/_test_files/js/condcomm.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/condcomm.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
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";
}
return;
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : 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_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : 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_JSMinPlus();
|