Skip to content

Commit dee8822

Browse files
authored
Merge pull request #126 from tedious/even_better_keywords
Better Keyword Support and Testing
2 parents 439459e + 363b391 commit dee8822

10 files changed

+20655
-9
lines changed

src/JShrink/Minifier.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ protected function saveString()
618618
*/
619619
protected function saveRegex()
620620
{
621-
$this->echo($this->a . $this->b);
621+
if ($this->a != " ") {
622+
$this->echo($this->a);
623+
}
624+
625+
$this->echo($this->b);
622626

623627
while (($this->a = $this->getChar()) !== false) {
624628
if ($this->a === '/') {
@@ -656,10 +660,7 @@ protected function endsInKeyword() {
656660
$testOutput = $this->output . $this->a;
657661

658662
foreach(static::$keywords as $keyword) {
659-
if (str_ends_with($testOutput, $keyword)) {
660-
return true;
661-
}
662-
if (str_ends_with($testOutput, $keyword . " ")) {
663+
if (preg_match('/[^\w]'.$keyword.'[ ]?$/i', $testOutput) === 1) {
663664
return true;
664665
}
665666
}

tests/JShrink/Test/JShrinkTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ public function testRequests($testName, $input, $output)
6565
$this->assertEquals($output, \JShrink\Minifier::minify($input), 'Running User Requested Test: ' . $testName);
6666
}
6767

68+
/**
69+
* @dataProvider librariesProvider
70+
*/
71+
public function testLibraries($testName, $input)
72+
{
73+
$this->expectNotToPerformAssertions();
74+
\JShrink\Minifier::minify($input);
75+
}
76+
6877
// /**
6978
// * @group development
7079
// * @dataProvider developmentProvider
@@ -111,6 +120,23 @@ public static function getTestFiles($group)
111120
return $returnData;
112121
}
113122

123+
public static function getTestLibraries()
124+
{
125+
$testDir = __DIR__ . '/../../Resources/libraries/';
126+
127+
$returnData = array();
128+
129+
$testFiles = scandir($testDir);
130+
foreach ($testFiles as $testFile) {
131+
if (substr($testFile, -3) !== '.js') {
132+
continue;
133+
}
134+
$returnData["Libraries:" . $testFile] = [$testFile, file_get_contents($testDir . $testFile)];
135+
}
136+
137+
return $returnData;
138+
}
139+
114140
public static function uglifyProvider()
115141
{
116142
return self::getTestFiles('uglify');
@@ -130,4 +156,9 @@ public static function developmentProvider()
130156
{
131157
return self::getTestFiles('development');
132158
}
159+
160+
public static function librariesProvider()
161+
{
162+
return self::getTestLibraries();
163+
}
133164
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function test (string) {
2+
return (string || '').replace(
3+
/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g,
4+
'\\$1'
5+
)
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aboveMin = Math.round(aboveMin / options.step) * options.step
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function test(string){return(string||'').replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g,
2+
'\\$1'
3+
)
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aboveMin=Math.round(aboveMin / options.step)*options.step
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
return /'/
2-
typeof /'/
1+
return/'/
2+
typeof/'/
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function airplaneIsCarrierBased(model){return /^(FI-167|Swordfish|Fulmar|Firefly|F4F Wildcat|F6F-[35] Hellcat|Latécoère 298|A[567]M)$/.test(model)}
1+
function airplaneIsCarrierBased(model){return/^(FI-167|Swordfish|Fulmar|Firefly|F4F Wildcat|F6F-[35] Hellcat|Latécoère 298|A[567]M)$/.test(model)}
22
console.log(airplaneIsCarrierBased('F6F-5 Hellcat'))
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
function test(input){return /^(אחה"צ|אחרי הצהריים|בערב)$/.test(input)}
1+
function test(input){return/^(אחה"צ|אחרי הצהריים|בערב)$/.test(input)}

0 commit comments

Comments
 (0)