Skip to content

Commit cc48510

Browse files
committed
Merge pull request #197 from cscott/syntax-errors
Add mechanism to test invalid properties which trigger SyntaxErrors.
2 parents bc0d8fc + 03bdebb commit cc48510

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/css/Validation.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
//-------------------------------------------------------------------------
99

1010
function ValidationTestCase(info){
11-
var i, len, prop;
11+
var i, len, prop, msg;
1212

1313
YUITest.TestCase.call(this, info);
1414
this.valid = info.valid;
1515
this.invalid = info.invalid;
1616
this.property = info.property;
1717
this.name = "Tests for " + this.property;
18+
this._should.error = {};
1819

1920
for (i=0, len=this.valid.length; i < len; i++){
2021
this["'" + this.valid[i] + "' is a valid value for '" + this.property + "'"] = function(value){
@@ -33,6 +34,18 @@
3334
}(prop, this.invalid[prop]);
3435
}
3536
}
37+
38+
for (prop in this.error){
39+
if (this.error.hasOwnProperty(prop)){
40+
msg = "'" + prop + "' is an invalid value for '" + this.property + "'";
41+
this[msg] = function(value){
42+
return function(){
43+
this._testSyntaxError(value);
44+
};
45+
}(prop);
46+
this._should.error[msg] = this.error[prop];
47+
}
48+
}
3649
}
3750

3851
ValidationTestCase.prototype = new YUITest.TestCase();
@@ -54,6 +67,11 @@
5467
var result = parser.parse(".foo { " + this.property + ":" + value + "}");
5568
};
5669

70+
ValidationTestCase.prototype._testSyntaxError = function(value){
71+
var parser = new Parser({ strict: true, starHack: true, underscoreHack: true });
72+
var result = parser.parse(".foo { " + this.property + ":" + value + "}");
73+
};
74+
5775

5876
//-------------------------------------------------------------------------
5977
// Validation Tests

0 commit comments

Comments
 (0)