forked from leafo/scssphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionTest.php
More file actions
139 lines (128 loc) · 2.57 KB
/
ExceptionTest.php
File metadata and controls
139 lines (128 loc) · 2.57 KB
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
<?php
/**
* SCSSPHP
*
* @copyright 2012-2015 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Tests;
use Leafo\ScssPhp\Compiler;
/**
* Exception test
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class ExceptionTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->scss = new Compiler();
}
/**
* @param string $scss
* @param string $expectedExceptionMessage
*
* @dataProvider provideScss
*/
public function testThrowError($scss, $expectedExceptionMessage)
{
try {
$this->compile($scss);
} catch (\Exception $e) {
if (strpos($e->getMessage(), $expectedExceptionMessage) !== false) {
return;
};
}
$this->fail('Expected exception to be raised: ' . $expectedExceptionMessage);
}
/**
* @return array
*/
public function provideScss()
{
return array(
array(<<<'END_OF_SCSS'
.test {
foo : bar;
END_OF_SCSS
,
'unclosed block'
),
array(<<<'END_OF_SCSS'
.test {
}}
END_OF_SCSS
,
'unexpected }'
),
array(<<<'END_OF_SCSS'
.test { color: #fff / 0; }
END_OF_SCSS
,
'color: Can\'t divide by zero'
),
array(<<<'END_OF_SCSS'
.test { left: 300px/0; }
END_OF_SCSS
,
'Division by zero'
),
array(<<<'END_OF_SCSS'
.test {
@include foo();
}
END_OF_SCSS
,
'Undefined mixin foo'
),
array(<<<'END_OF_SCSS'
@mixin do-nothing() {
}
.test {
@include do-nothing($a: "hello");
}
END_OF_SCSS
,
'Mixin or function doesn\'t have an argument named $a.'
),
array(<<<'END_OF_SCSS'
div {
color: darken(cobaltgreen, 10%);
}
END_OF_SCSS
,
'expecting color'
),
array(<<<'END_OF_SCSS'
BODY {
DIV {
$bg: red;
}
background: $bg;
}
END_OF_SCSS
,
'Undefined variable $bg'
),
array(<<<'END_OF_SCSS'
@mixin example {
background: $bg;
}
P {
$bg: red;
@include example;
}
END_OF_SCSS
,
'Undefined variable $bg'
),
);
}
private function compile($str)
{
return trim($this->scss->compile($str));
}
}