Fix #1927 string * float error in leafo/lessphp

- dev-master 태그로 업데이트
- PHP 8.0 이상 버전에서 오류를 일으키는 {0} 문법 4군데 재수정
This commit is contained in:
Kijin Sung 2022-07-03 00:00:52 +09:00
parent e258cf7525
commit 1f9056fc08
31 changed files with 4558 additions and 4326 deletions

View file

@ -2,14 +2,14 @@
require_once __DIR__ . "/../lessc.inc.php";
class ApiTest extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->less = new lessc();
$this->less->importDir = array(__DIR__ . "/inputs/test-imports");
}
class ApiTest extends PHPUnit\Framework\TestCase {
public function setUp() {
$this->less = new lessc();
$this->less->importDir = array(__DIR__ . "/inputs/test-imports");
}
public function testPreserveComments() {
$input = <<<EOD
public function testPreserveComments() {
$input = <<<EOD
// what is going on?
/** what the heck **/
@ -42,7 +42,7 @@ Here is a block comment
EOD;
$outputWithComments = <<<EOD
$outputWithComments = <<<EOD
/** what the heck **/
/**
@ -69,7 +69,7 @@ div /*yeah*/ {
}
EOD;
$outputWithoutComments = <<<EOD
$outputWithoutComments = <<<EOD
div {
border: 1px solid red;
color: url('http://mage-page.com');
@ -82,71 +82,71 @@ div {
}
EOD;
$this->assertEquals($this->compile($input), trim($outputWithoutComments));
$this->less->setPreserveComments(true);
$this->assertEquals($this->compile($input), trim($outputWithComments));
}
$this->assertEquals($this->compile($input), trim($outputWithoutComments));
$this->less->setPreserveComments(true);
$this->assertEquals($this->compile($input), trim($outputWithComments));
}
public function testOldInterface() {
$this->less = new lessc(__DIR__ . "/inputs/hi.less");
$out = $this->less->parse(array("hello" => "10px"));
$this->assertEquals(trim($out), trim('
public function testOldInterface() {
$this->less = new lessc(__DIR__ . "/inputs/hi.less");
$out = $this->less->parse(array("hello" => "10px"));
$this->assertEquals(trim($out), trim('
div:before {
content: "hi!";
}'));
}
}
public function testInjectVars() {
$out = $this->less->parse(".magic { color: @color; width: @base - 200; }",
array(
'color' => 'red',
'base' => '960px'
));
public function testInjectVars() {
$out = $this->less->parse(".magic { color: @color; width: @base - 200; }",
array(
'color' => 'red',
'base' => '960px'
));
$this->assertEquals(trim($out), trim("
$this->assertEquals(trim($out), trim("
.magic {
color: red;
width: 760px;
}"));
}
}
public function testDisableImport() {
$this->less->importDisabled = true;
$this->assertEquals(
"/* import disabled */",
$this->compile("@import 'file3';"));
}
public function testDisableImport() {
$this->less->importDisabled = true;
$this->assertEquals(
"/* import disabled */",
$this->compile("@import 'file3';"));
}
public function testUserFunction() {
$this->less->registerFunction("add-two", function($list) {
list($a, $b) = $list[2];
return $a[1] + $b[1];
});
public function testUserFunction() {
$this->less->registerFunction("add-two", function($list) {
list($a, $b) = $list[2];
return $a[1] + $b[1];
});
$this->assertEquals(
$this->compile("result: add-two(10, 20);"),
"result: 30;");
$this->assertEquals(
$this->compile("result: add-two(10, 20);"),
"result: 30;");
return $this->less;
}
return $this->less;
}
/**
* @depends testUserFunction
*/
public function testUnregisterFunction($less) {
$less->unregisterFunction("add-two");
/**
* @depends testUserFunction
*/
public function testUnregisterFunction($less) {
$less->unregisterFunction("add-two");
$this->assertEquals(
$this->compile("result: add-two(10, 20);"),
"result: add-two(10,20);");
}
$this->assertEquals(
$this->compile("result: add-two(10, 20);"),
"result: add-two(10,20);");
}
public function testFormatters() {
$src = "
public function testFormatters() {
$src = "
div, pre {
color: blue;
span, .big, hello.world {
@ -155,14 +155,14 @@ div:before {
}
}";
$this->less->setFormatter("compressed");
$this->assertEquals(
$this->compile($src), "div,pre{color:blue;}div span,div .big,div hello.world,pre span,pre .big,pre hello.world{height:20px;color:#fff;}");
$this->less->setFormatter("compressed");
$this->assertEquals(
$this->compile($src), "div,pre{color:blue;}div span,div .big,div hello.world,pre span,pre .big,pre hello.world{height:20px;color:#fff;}");
// TODO: fix the output order of tags
$this->less->setFormatter("lessjs");
$this->assertEquals(
$this->compile($src),
// TODO: fix the output order of tags
$this->less->setFormatter("lessjs");
$this->assertEquals(
$this->compile($src),
"div,
pre {
color: blue;
@ -177,9 +177,9 @@ pre hello.world {
color: #ffffff;
}");
$this->less->setFormatter("classic");
$this->assertEquals(
$this->compile($src),
$this->less->setFormatter("classic");
$this->assertEquals(
$this->compile($src),
trim("div, pre { color:blue; }
div span, div .big, div hello.world, pre span, pre .big, pre hello.world {
height:20px;
@ -187,10 +187,10 @@ div span, div .big, div hello.world, pre span, pre .big, pre hello.world {
}
"));
}
}
public function compile($str) {
return trim($this->less->parse($str));
}
public function compile($str) {
return trim($this->less->parse($str));
}
}

View file

@ -1,81 +1,81 @@
<?php
require_once __DIR__ . "/../lessc.inc.php";
class ErrorHandlingTest extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->less = new lessc();
}
class ErrorHandlingTest extends PHPUnit\Framework\TestCase {
public function setUp() {
$this->less = new lessc();
}
public function compile() {
$source = join("\n", func_get_args());
return $this->less->compile($source);
}
public function compile() {
$source = join("\n", func_get_args());
return $this->less->compile($source);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .parametric-mixin is undefined
*/
public function testRequiredParametersMissing() {
$this->compile(
'.parametric-mixin (@a, @b) { a: @a; b: @b; }',
'.selector { .parametric-mixin(12px); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .parametric-mixin is undefined
*/
public function testRequiredParametersMissing() {
$this->compile(
'.parametric-mixin (@a, @b) { a: @a; b: @b; }',
'.selector { .parametric-mixin(12px); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .parametric-mixin is undefined
*/
public function testTooManyParameters() {
$this->compile(
'.parametric-mixin (@a, @b) { a: @a; b: @b; }',
'.selector { .parametric-mixin(12px, 13px, 14px); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .parametric-mixin is undefined
*/
public function testTooManyParameters() {
$this->compile(
'.parametric-mixin (@a, @b) { a: @a; b: @b; }',
'.selector { .parametric-mixin(12px, 13px, 14px); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage unrecognised input
*/
public function testRequiredArgumentsMissing() {
$this->compile('.selector { rule: e(); }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage unrecognised input
*/
public function testRequiredArgumentsMissing() {
$this->compile('.selector { rule: e(); }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage variable @missing is undefined
*/
public function testVariableMissing() {
$this->compile('.selector { rule: @missing; }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage variable @missing is undefined
*/
public function testVariableMissing() {
$this->compile('.selector { rule: @missing; }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage .missing-mixin is undefined
*/
public function testMixinMissing() {
$this->compile('.selector { .missing-mixin; }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage .missing-mixin is undefined
*/
public function testMixinMissing() {
$this->compile('.selector { .missing-mixin; }');
}
/**
* @expectedException Exception
* @expectedExceptionMessage .flipped is undefined
*/
public function testGuardUnmatchedValue() {
$this->compile(
'.flipped(@x) when (@x =< 10) { rule: value; }',
'.selector { .flipped(12); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .flipped is undefined
*/
public function testGuardUnmatchedValue() {
$this->compile(
'.flipped(@x) when (@x =< 10) { rule: value; }',
'.selector { .flipped(12); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .colors-only is undefined
*/
public function testGuardUnmatchedType() {
$this->compile(
'.colors-only(@x) when (iscolor(@x)) { rule: value; }',
'.selector { .colors-only("string value"); }'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage .colors-only is undefined
*/
public function testGuardUnmatchedType() {
$this->compile(
'.colors-only(@x) when (iscolor(@x)) { rule: value; }',
'.selector { .colors-only("string value"); }'
);
}
}

View file

@ -5,85 +5,86 @@ require_once __DIR__ . "/../lessc.inc.php";
// Runs all the tests in inputs/ and compares their output to ouputs/
function _dump($value) {
fwrite(STDOUT, print_r($value, true));
fwrite(STDOUT, print_r($value, true));
}
function _quote($str) {
return preg_quote($str, "/");
return preg_quote($str, "/");
}
class InputTest extends PHPUnit_Framework_TestCase {
protected static $importDirs = array("inputs/test-imports");
class InputTest extends PHPUnit\Framework\TestCase {
protected static $importDirs = array("inputs/test-imports");
protected static $testDirs = array(
"inputs" => "outputs",
"inputs_lessjs" => "outputs_lessjs",
);
protected static $testDirs = array(
"inputs" => "outputs",
"inputs_lessjs" => "outputs_lessjs",
);
public function setUp() {
$this->less = new lessc();
$this->less->importDir = array_map(function($path) {
return __DIR__ . "/" . $path;
}, self::$importDirs);
}
public function setUp() {
$this->less = new lessc();
$this->less->importDir = array_map(function($path) {
return __DIR__ . "/" . $path;
}, self::$importDirs);
}
/**
* @dataProvider fileNameProvider
*/
public function testInputFile($inFname) {
if ($pattern = getenv("BUILD")) {
return $this->buildInput($inFname);
}
/**
* @dataProvider fileNameProvider
*/
public function testInputFile($inFname) {
if ($pattern = getenv("BUILD")) {
return $this->buildInput($inFname);
}
$outFname = self::outputNameFor($inFname);
$outFname = self::outputNameFor($inFname);
if (!is_readable($outFname)) {
$this->fail("$outFname is missing, ".
"consider building tests with BUILD=true");
}
if (!is_readable($outFname)) {
$this->fail("$outFname is missing, ".
"consider building tests with BUILD=true");
}
$input = file_get_contents($inFname);
$output = file_get_contents($outFname);
$input = file_get_contents($inFname);
$output = file_get_contents($outFname);
$this->assertEquals($output, $this->less->parse($input));
}
$this->assertEquals($output, $this->less->parse($input));
}
public function fileNameProvider() {
return array_map(function($a) { return array($a); },
self::findInputNames());
}
public function fileNameProvider() {
return array_map(
function($a) { return array($a); },
self::findInputNames()
);
}
// only run when env is set
public function buildInput($inFname) {
$css = $this->less->parse(file_get_contents($inFname));
file_put_contents(self::outputNameFor($inFname), $css);
}
// only run when env is set
public function buildInput($inFname) {
$css = $this->less->parse(file_get_contents($inFname));
file_put_contents(self::outputNameFor($inFname), $css);
}
static public function findInputNames($pattern="*.less") {
$files = array();
foreach (self::$testDirs as $inputDir => $outputDir) {
$files = array_merge($files, glob(__DIR__ . "/" . $inputDir . "/" . $pattern));
}
public static function findInputNames($pattern="*.less") {
$files = array();
foreach (self::$testDirs as $inputDir => $outputDir) {
$files = array_merge($files, glob(__DIR__ . "/" . $inputDir . "/" . $pattern));
}
return array_filter($files, "is_file");
}
return array_filter($files, "is_file");
}
static public function outputNameFor($input) {
$front = _quote(__DIR__ . "/");
$out = preg_replace("/^$front/", "", $input);
public static function outputNameFor($input) {
$front = _quote(__DIR__ . "/");
$out = preg_replace("/^$front/", "", $input);
foreach (self::$testDirs as $inputDir => $outputDir) {
$in = _quote($inputDir . "/");
$rewritten = preg_replace("/$in/", $outputDir . "/", $out);
if ($rewritten != $out) {
$out = $rewritten;
break;
}
}
foreach (self::$testDirs as $inputDir => $outputDir) {
$in = _quote($inputDir . "/");
$rewritten = preg_replace("/$in/", $outputDir . "/", $out);
if ($rewritten != $out) {
$out = $rewritten;
break;
}
}
$out = preg_replace("/.less$/", ".css", $out);
$out = preg_replace("/.less$/", ".css", $out);
return __DIR__ . "/" . $out;
}
return __DIR__ . "/" . $out;
}
}

View file

@ -1,4 +1,4 @@
lessphp uses [phpunit](https://github.com/sebastianbergmann/phpunit/) for its tests
lessphp uses [PHPUnit](https://github.com/sebastianbergmann/phpunit/) for its tests
* `InputTest.php` iterates through all the less files in `inputs/`, compiles
them, then compares the result with the respective file in `outputs/`.

0
vendor/leafo/lessphp/tests/bootstrap.sh vendored Normal file → Executable file
View file

View file

@ -37,6 +37,11 @@ body {
two1: fadeout(#029f23, 10%);
two2: fadein(#029f23, -10%);
tint1: tint(#e0e0e0);
tint2: tint(#e0e0e0, 40%);
shade1: shade(#e0e0e0);
shade2: shade(#e0e0e0, 40%);
three1: fadein(rgba(1,2,3, 0.5), 10%);
three2: fadeout(rgba(1,2,3, 0.5), -10%);
@ -95,6 +100,10 @@ fade {
color2: contrast(#fff, red, blue);
}
.luma {
color: luma(rgb(100, 200, 30));
}
.percent {
per: percentage(0.5);
}

View file

@ -26,6 +26,10 @@ body {
one2: #abcdef;
two1: rgba(2,159,35,0.9);
two2: rgba(2,159,35,0.9);
tint1: #f0f0f0;
tint2: #ececec;
shade1: #707070;
shade2: #868686;
three1: rgba(1,2,3,0.6);
three2: rgba(1,2,3,0.6);
four1: rgba(1,2,3,0);
@ -65,6 +69,9 @@ fade {
color1: #ff0000;
color2: #0000ff;
}
.luma {
color: 44.11161568%;
}
.percent {
per: 50%;
}

View file

@ -1,57 +1,56 @@
<?php
error_reporting(E_ALL);
require realpath(dirname(__FILE__)).'/../lessc.inc.php';
require realpath(dirname(__FILE__)) . '/../lessc.inc.php';
// sorts the selectors in stylesheet in order to normalize it for comparison
$exe = array_shift($argv); // remove filename
if (!$fname = array_shift($argv)) {
$fname = "php://stdin";
$fname = "php://stdin";
}
class lesscNormalized extends lessc {
public $numberPrecision = 3;
public $numberPrecision = 3;
public function compileValue($value) {
if ($value[0] == "raw_color") {
$value = $this->coerceColor($value);
}
public function compileValue($value) {
if ($value[0] === "raw_color") {
$value = $this->coerceColor($value);
}
return parent::compileValue($value);
}
return parent::compileValue($value);
}
}
class SortingFormatter extends lessc_formatter_lessjs {
function sortKey($block) {
if (!isset($block->sortKey)) {
sort($block->selectors, SORT_STRING);
$block->sortKey = implode(",", $block->selectors);
}
public function sortKey($block) {
if (!isset($block->sortKey)) {
sort($block->selectors, SORT_STRING);
$block->sortKey = implode(",", $block->selectors);
}
return $block->sortKey;
}
return $block->sortKey;
}
function sortBlock($block) {
usort($block->children, function($a, $b) {
$sort = strcmp($this->sortKey($a), $this->sortKey($b));
if ($sort == 0) {
// TODO
}
return $sort;
});
public function sortBlock($block) {
usort($block->children, function($a, $b) {
$sort = strcmp($this->sortKey($a), $this->sortKey($b));
if ($sort == 0) {
// TODO
}
return $sort;
});
}
}
function block($block) {
$this->sortBlock($block);
return parent::block($block);
}
public function block($block) {
$this->sortBlock($block);
return parent::block($block);
}
}
$less = new lesscNormalized();
$less->setFormatter(new SortingFormatter);
echo $less->parse(file_get_contents($fname));