all repos — wp-autoless @ 90b7e3d3bcc402e14d377c16a5e7f91a488a6917

vendor/leafo/lessphp/tests/ApiTest.php (view raw)

 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
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
<?php

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");
	}

	public function testPreserveComments() {
		$input = <<<EOD
// what is going on?

/** what the heck **/

/**

Here is a block comment

**/


// this is a comment

/*hello*/div /*yeah*/ { //surew
	border: 1px solid red; // world
	/* comment above the first occurrence of a duplicated rule */
	color: url('http://mage-page.com');
	string: "hello /* this is not a comment */";
	world: "// neither is this";
	/* comment above the second occurrence of a duplicated rule */
	color: url('http://mage-page.com');
	string: 'hello /* this is not a comment */' /*what if this is a comment */;
	world: '// neither is this' // hell world;
	;
	/* duplicate comments are retained */
	/* duplicate comments are retained */
	what-ever: 100px;
	background: url(/*this is not a comment?*/); // uhh what happens here
}
EOD;


		$outputWithComments = <<<EOD
/** what the heck **/
/**

Here is a block comment

**/
/*hello*/
/*yeah*/
div /*yeah*/ {
  border: 1px solid red;
  /* comment above the first occurrence of a duplicated rule */
  /* comment above the second occurrence of a duplicated rule */
  color: url('http://mage-page.com');
  string: "hello /* this is not a comment */";
  world: "// neither is this";
  /*what if this is a comment */
  string: 'hello /* this is not a comment */';
  world: '// neither is this';
  /* duplicate comments are retained */
  /* duplicate comments are retained */
  what-ever: 100px;
  /*this is not a comment?*/
  background: url();
}
EOD;

		$outputWithoutComments = <<<EOD
div {
  border: 1px solid red;
  color: url('http://mage-page.com');
  string: "hello /* this is not a comment */";
  world: "// neither is this";
  string: 'hello /* this is not a comment */';
  world: '// neither is this';
  what-ever: 100px;
  background: url(/*this is not a comment?*/);
}
EOD;

		$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('
div:before {
  content: "hi!";
}'));

	}

	public function testInjectVars() {
		$out = $this->less->parse(".magic { color: @color;  width: @base - 200; }",
			array(
				'color' => 'red',
				'base' => '960px'
			));

		$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 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;");

		return $this->less;
	}

	/**
	 * @depends testUserFunction
	 */
	public function testUnregisterFunction($less) {
		$less->unregisterFunction("add-two");

		$this->assertEquals(
			$this->compile("result: add-two(10, 20);"),
			"result: add-two(10,20);");
	}



	public function testFormatters() {
		$src = "
			div, pre {
				color: blue;
				span, .big, hello.world {
					height: 20px;
					color:#ffffff + #000;
				}
			}";

		$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),
"div,
pre {
  color: blue;
}
div span,
div .big,
div hello.world,
pre span,
pre .big,
pre hello.world {
  height: 20px;
  color: #ffffff;
}");

		$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;
  color:#ffffff;
}
"));

	}

	public function compile($str) {
		return trim($this->less->parse($str));
	}

}