1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-11 00:24:11 +02:00

+ JSMinPlus.php + testing cond. comment support

This commit is contained in:
Steve Clay
2009-04-14 18:10:50 +00:00
parent 46b009e07a
commit 24418803da
6 changed files with 2031 additions and 0 deletions

1902
min/lib/JSMinPlus.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
/* is.js
(c) 2001 Douglas Crockford
2001 June 3
*/
var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
/**
* preserve this comment, too
*/
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}/*@cc_on
/*@if (@_win32)
if (is.ie && is.win)
document.write("PASS: IE/win honored conditional comment.<br>");
@else @*/if(is.ie&&is.win)
document.write("FAIL: IE/win did not honor multi-line conditional comment.<br>");else
document.write("PASS: Non-IE/win browser ignores multi-line conditional comment.<br>");/*@end
@*/var recognizesCondComm=true;//@cc_on/*
recognizesCondComm=false;//@cc_on*/
if((is.ie&&is.win)==recognizesCondComm)
document.write("PASS: IE/win honored single-line conditional comment.<br>");else
document.write("FAIL: Non-IE/win browser did not ignore single-line conditional comment.<br>");

View File

@@ -0,0 +1,13 @@
var isWin;
/*@cc_on
@if (@_win32)
isWin = true;
@else @*/
isWin = false;
/*@end
@*/
var recognizesCondComm = true;
//@cc_on/*
recognizesCondComm = false;
//@cc_on*/

View File

@@ -0,0 +1,13 @@
var isWin;
/*@cc_on
@if (@_win32)
isWin = true;
@else @*/
isWin = false;
/*@end
@*/
var recognizesCondComm = true;
//@cc_on/*
recognizesCondComm = false;
//@cc_on*/

View File

@@ -0,0 +1 @@
function testIssue74(){return /'/}

View File

@@ -0,0 +1,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();