Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 240 lines (184 sloc) 9.426 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "TDMiniCSSAssemblerTest.h"
16
17 @implementation TDMiniCSSAssemblerTest
18
19 - (void)setUp {
20 path = [[NSBundle bundleForClass:[self class]] pathForResource:@"mini_css" ofType:@"grammar"];
21 grammarString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
22 ass = [[TDMiniCSSAssembler alloc] init];
23 factory = [PKParserFactory factory];
eb778c5 @itod merging changes from Google Code SVN repo
authored
24 lp = [factory parserFromGrammar:grammarString assembler:ass error:nil];
05eedb5 @itod initial add
authored
25 }
26
27
28 - (void)tearDown {
29 [ass release];
30 }
31
32
33 - (void)testColor {
34 TDNotNil(lp);
35
36 s = @"bar { color:rgb(10, 200, 30); }";
37 a = [PKTokenAssembly assemblyWithString:s];
38 a = [lp bestMatchFor:a];
39 TDEqualObjects(@"[]bar/{/color/:/rgb/(/10/,/200/,/30/)/;/}^", [a description]);
40 TDNotNil(ass.attributes);
41 id props = [ass.attributes objectForKey:@"bar"];
42 TDNotNil(props);
43
44 NSColor *color = [props objectForKey:NSForegroundColorAttributeName];
45 TDNotNil(color);
46 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
47 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
48 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
49 }
50
51
52 - (void)testMultiSelectorColor {
53 TDNotNil(lp);
54
55 s = @"foo, bar { color:rgb(10, 200, 30); }";
56 a = [PKTokenAssembly assemblyWithString:s];
57 a = [lp bestMatchFor:a];
58 TDEqualObjects(@"[]foo/,/bar/{/color/:/rgb/(/10/,/200/,/30/)/;/}^", [a description]);
59 TDNotNil(ass.attributes);
60
61 id props = [ass.attributes objectForKey:@"bar"];
62 TDNotNil(props);
63
64 NSColor *color = [props objectForKey:NSForegroundColorAttributeName];
65 TDNotNil(color);
66 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
67 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
68 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
69
70 props = [ass.attributes objectForKey:@"foo"];
71 TDNotNil(props);
72
73 color = [props objectForKey:NSForegroundColorAttributeName];
74 TDNotNil(color);
75 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
76 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
77 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
78 }
79
80
81 - (void)testBackgroundColor {
82 TDNotNil(lp);
83
84 s = @"foo { background-color:rgb(255.0, 0.0, 255.0) }";
85 a = [PKTokenAssembly assemblyWithString:s];
86 a = [lp bestMatchFor:a];
87 TDEqualObjects(@"[]foo/{/background-color/:/rgb/(/255.0/,/0.0/,/255.0/)/}^", [a description]);
88 TDNotNil(ass.attributes);
89
90 id props = [ass.attributes objectForKey:@"foo"];
91 TDNotNil(props);
92
93 NSColor *color = [props objectForKey:NSBackgroundColorAttributeName];
94 TDNotNil(color);
95 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(255.0/255.0), 0.001, @"");
96 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(0.0/255.0), 0.001, @"");
97 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(255.0/255.0), 0.001, @"");
98 }
99
100
101 - (void)testFontSize {
102 TDNotNil(lp);
103
104 s = @"decl { font-size:12px }";
105 a = [PKTokenAssembly assemblyWithString:s];
106 a = [lp bestMatchFor:a];
107 TDEqualObjects(@"[]decl/{/font-size/:/12/px/}^", [a description]);
108 TDNotNil(ass.attributes);
109
110 id props = [ass.attributes objectForKey:@"decl"];
111 TDNotNil(props);
112
113 NSFont *font = [props objectForKey:NSFontAttributeName];
114 TDNotNil(font);
115 TDEquals((CGFloat)[font pointSize], (CGFloat)12.0);
116 TDEqualObjects([font familyName], @"Monaco");
117 }
118
119
120 - (void)testSmallFontSize {
121 TDNotNil(lp);
122
123 s = @"decl { font-size:8px }";
124 a = [PKTokenAssembly assemblyWithString:s];
125 a = [lp bestMatchFor:a];
126 TDEqualObjects(@"[]decl/{/font-size/:/8/px/}^", [a description]);
127 TDNotNil(ass.attributes);
128
129 id props = [ass.attributes objectForKey:@"decl"];
130 TDNotNil(props);
131
132 NSFont *font = [props objectForKey:NSFontAttributeName];
133 TDNotNil(font);
134 TDEquals((CGFloat)[font pointSize], (CGFloat)9.0);
135 TDEqualObjects([font familyName], @"Monaco");
136 }
137
138
139 - (void)testFont {
140 TDNotNil(lp);
141
142 s = @"expr { font-size:16px; font-family:'Helvetica' }";
143 a = [PKTokenAssembly assemblyWithString:s];
144 a = [lp bestMatchFor:a];
145 TDEqualObjects(@"[]expr/{/font-size/:/16/px/;/font-family/:/'Helvetica'/}^", [a description]);
146 TDNotNil(ass.attributes);
147
148 id props = [ass.attributes objectForKey:@"expr"];
149 TDNotNil(props);
150
151 NSFont *font = [props objectForKey:NSFontAttributeName];
152 TDNotNil(font);
153 TDEqualObjects([font familyName], @"Helvetica");
154 TDEquals((CGFloat)[font pointSize], (CGFloat)16.0);
155 }
156
157
158 - (void)testAll {
159 TDNotNil(lp);
160
161 s = @"expr { font-size:9.0px; font-family:'Courier'; background-color:rgb(255.0, 0.0, 255.0) ; color:rgb(10, 200, 30);}";
162 a = [PKTokenAssembly assemblyWithString:s];
163 a = [lp bestMatchFor:a];
164 TDEqualObjects(@"[]expr/{/font-size/:/9.0/px/;/font-family/:/'Courier'/;/background-color/:/rgb/(/255.0/,/0.0/,/255.0/)/;/color/:/rgb/(/10/,/200/,/30/)/;/}^", [a description]);
165 TDNotNil(ass.attributes);
166
167 id props = [ass.attributes objectForKey:@"expr"];
168 TDNotNil(props);
169
170 NSFont *font = [props objectForKey:NSFontAttributeName];
171 TDNotNil(font);
172 TDEqualObjects([font familyName], @"Courier");
173 TDEquals((CGFloat)[font pointSize], (CGFloat)9.0);
174
175 NSColor *bgColor = [props objectForKey:NSBackgroundColorAttributeName];
176 TDNotNil(bgColor);
177 STAssertEqualsWithAccuracy([bgColor redComponent], (CGFloat)(255.0/255.0), 0.001, @"");
178 STAssertEqualsWithAccuracy([bgColor greenComponent], (CGFloat)(0.0/255.0), 0.001, @"");
179 STAssertEqualsWithAccuracy([bgColor blueComponent], (CGFloat)(255.0/255.0), 0.001, @"");
180
181 NSColor *color = [props objectForKey:NSForegroundColorAttributeName];
182 TDNotNil(color);
183 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
184 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
185 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
186 }
187
188
189 - (void)testMultiAll {
190 TDNotNil(lp);
191
192 s = @"expr, decl { font-size:9.0px; font-family:'Courier'; background-color:rgb(255.0, 0.0, 255.0) ; color:rgb(10, 200, 30);}";
193 a = [PKTokenAssembly assemblyWithString:s];
194 a = [lp bestMatchFor:a];
195 TDEqualObjects(@"[]expr/,/decl/{/font-size/:/9.0/px/;/font-family/:/'Courier'/;/background-color/:/rgb/(/255.0/,/0.0/,/255.0/)/;/color/:/rgb/(/10/,/200/,/30/)/;/}^", [a description]);
196 TDNotNil(ass.attributes);
197
198 id props = [ass.attributes objectForKey:@"expr"];
199 TDNotNil(props);
200
201 NSFont *font = [props objectForKey:NSFontAttributeName];
202 TDNotNil(font);
203 TDEqualObjects([font familyName], @"Courier");
204 TDEquals((CGFloat)[font pointSize], (CGFloat)9.0);
205
206 NSColor *bgColor = [props objectForKey:NSBackgroundColorAttributeName];
207 TDNotNil(bgColor);
208 STAssertEqualsWithAccuracy([bgColor redComponent], (CGFloat)(255.0/255.0), 0.001, @"");
209 STAssertEqualsWithAccuracy([bgColor greenComponent], (CGFloat)(0.0/255.0), 0.001, @"");
210 STAssertEqualsWithAccuracy([bgColor blueComponent], (CGFloat)(255.0/255.0), 0.001, @"");
211
212 NSColor *color = [props objectForKey:NSForegroundColorAttributeName];
213 TDNotNil(color);
214 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
215 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
216 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
217
218 props = [ass.attributes objectForKey:@"decl"];
219 TDNotNil(props);
220
221 font = [props objectForKey:NSFontAttributeName];
222 TDNotNil(font);
223 TDEqualObjects([font familyName], @"Courier");
224 TDEquals((CGFloat)[font pointSize], (CGFloat)9.0);
225
226 bgColor = [props objectForKey:NSBackgroundColorAttributeName];
227 TDNotNil(bgColor);
228 STAssertEqualsWithAccuracy([bgColor redComponent], (CGFloat)(255.0/255.0), 0.001, @"");
229 STAssertEqualsWithAccuracy([bgColor greenComponent], (CGFloat)(0.0/255.0), 0.001, @"");
230 STAssertEqualsWithAccuracy([bgColor blueComponent], (CGFloat)(255.0/255.0), 0.001, @"");
231
232 color = [props objectForKey:NSForegroundColorAttributeName];
233 TDNotNil(color);
234 STAssertEqualsWithAccuracy([color redComponent], (CGFloat)(10.0/255.0), 0.001, @"");
235 STAssertEqualsWithAccuracy([color greenComponent], (CGFloat)(200.0/255.0), 0.001, @"");
236 STAssertEqualsWithAccuracy([color blueComponent], (CGFloat)(30.0/255.0), 0.001, @"");
237 }
238
239 @end
Something went wrong with that request. Please try again.