Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: 172a2b2338
...
compare: v0.2.1
  • 17 commits
  • 24 files changed
  • 0 commit comments
  • 4 contributors
Commits on Nov 14, 2012
Jay Merrifield fracmak added support for calc wherever <length> is expected 1845473
Jay Merrifield fracmak added support for + operator for calc functions e0be226
Jay Merrifield fracmak _operator is used for seperating multiple values for a property (ie. …
…box-shadow: 10px 10px 0, 2px 2px 0) as well as for mathematical operators inside functions. Since functions are the only place mathematical operators are allowed, we now pass in a boolean to distinguish which token is acceptable to not accidentally treat -10px -10px as an equation
ebf3f4a
Commits on Nov 16, 2012
Nicholas C. Zakas nzakas Fixed media query tests c476289
Nicholas C. Zakas nzakas Add travis build status to readme a2aed01
Nicholas C. Zakas nzakas Merge pull request #35 from fracmak/calc_support
added support for calc wherever <length> is expected
8ca2d38
Nicholas C. Zakas nzakas Fix readme a46e34d
Nicholas C. Zakas nzakas Merge branch 'master' of github.com:nzakas/parser-lib c33c670
Commits on Nov 20, 2012
Nick Schonning nschonni Add CSS2 system colors 126c692
Nicholas C. Zakas nzakas Merge pull request #40 from nschonni/fix-#38-CSS2-system-colors
Add CSS2 system colors #38
a9c6f1b
Nick Schonning nschonni Add test for underscore hack
Additional validation in star hack
aef2bec
Nick Schonning nschonni Add white-space vendor prefixed values 5acd9b2
Commits on Nov 21, 2012
Nicholas C. Zakas nzakas Merge pull request #41 from nschonni/more-hack-tests
Add test for underscore hack
54e11e1
Nicholas C. Zakas nzakas Merge pull request #42 from nschonni/white-space-vendor-prefixes
Add white-space vendor prefixed values
ff0e720
Nick Schonning nschonni Add missing values from CSS3 vertical-align 83ae904
Nicholas C. Zakas nzakas Merge pull request #46 from nschonni/fix-vertical-align-missing-values
Add missing values from CSS3 vertical-align
a028647
Commits on Dec 04, 2012
Nicholas C. Zakas nzakas Release 0.2.1 8cfc5a0
39 CHANGELOG
View
@@ -1,3 +1,40 @@
+December 4, 2012 - v0.2.1
+
+* Merge pull request #46 from nschonni/fix-vertical-align-missing-values (Nicholas C. Zakas)
+* Add missing values from CSS3 vertical-align (Nick Schonning)
+* Merge pull request #42 from nschonni/white-space-vendor-prefixes (Nicholas C. Zakas)
+* Merge pull request #41 from nschonni/more-hack-tests (Nicholas C. Zakas)
+* Add white-space vendor prefixed values (Nick Schonning)
+* Add test for underscore hack (Nick Schonning)
+* Merge pull request #40 from nschonni/fix-#38-CSS2-system-colors (Nicholas C. Zakas)
+* Add CSS2 system colors (Nick Schonning)
+* Merge branch 'master' of github.com:nzakas/parser-lib (Nicholas C. Zakas)
+* Fix readme (Nicholas C. Zakas)
+* Merge pull request #35 from fracmak/calc_support (Nicholas C. Zakas)
+* Add travis build status to readme (Nicholas C. Zakas)
+* Fixed media query tests (Nicholas C. Zakas)
+* Merge pull request #30 from mirceapiturca/master (Nicholas C. Zakas)
+* Merge pull request #37 from Unroll-Me/master (Nicholas C. Zakas)
+* Remove platform restrictions (Schabse Laks)
+* _operator is used for seperating multiple values for a property (ie. box-shadow: 10px 10px 0, 2px 2px 0) as well as for mathematical operators inside functions. Since functions are the only place mathematical operators are allowed, we now pass in a boolean to distinguish which token is acceptable to not accidentally treat -10px -10px as an equation (Jay Merrifield)
+* added support for + operator for calc functions (Merrifield, Jay)
+* added support for calc wherever <length> is expected (Merrifield, Jay)
+* Fixed YUI Test issues, bumped version (Nicholas C. Zakas)
+* Merge pull request #36 from mattiacci/border-radius (Nicholas C. Zakas)
+* Fix validation of border-radius (Michael Mattiacci)
+* Merge pull request #33 from mattiacci/bg-position (Nicholas C. Zakas)
+* Fix validation of background-position (Michael Mattiacci)
+* Update tests/css/Parser.js (mirceapiturca)
+* Merge pull request #31 from nightwing/master (Nicholas C. Zakas)
+* fix typo (nightwing)
+* Update src/css/MediaQuery.js (mirceapiturca)
+* Update build/node-parserlib.js (mirceapiturca)
+* v0.1.9 (Nicholas C. Zakas)
+* Expose vendor prefix for @keyframes (fixes #29) (Nicholas C. Zakas)
+* Add support for o-keyframes and remove ms-keyframes (Nicholas C. Zakas)
+* Fix changelog (Nicholas C. Zakas)
+
+
November 13, 2012 - v0.2.0
* Merge pull request #36 from mattiacci/border-radius (Nicholas C. Zakas)
@@ -269,3 +306,5 @@ November 28, 2011 - v0.1.0
+
+
3  README → README.md
View
@@ -1,5 +1,6 @@
+[![build status](https://secure.travis-ci.org/nzakas/parser-lib.png)](http://travis-ci.org/nzakas/parser-lib)
A collection of utilities, lexers, and parsers written in JavaScript.
* src - contains the JavaScript source code.
* build - contains the built files that are suitable for deployment.
-* templates - files used as part of the build system.
+* templates - files used as part of the build system.
2  build.xml
View
@@ -1,7 +1,7 @@
<project name="parserlib" default="build.all">
<!-- version number -->
- <property name="parserlib.version" value="0.2.0" />
+ <property name="parserlib.version" value="0.2.1" />
<!-- the directories containing the source files -->
<property name="src.dir" value="./src" />
64 build/node-parserlib.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
var parserlib = {};
(function(){
@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1080,7 +1080,36 @@ var Colors = {
white :"#ffffff",
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
- yellowgreen :"#9acd32"
+ yellowgreen :"#9acd32",
+ //CSS2 system colors http://www.w3.org/TR/css3-color/#css2-system
+ activeBorder :"Active window border.",
+ activecaption :"Active window caption.",
+ appworkspace :"Background color of multiple document interface.",
+ background :"Desktop background.",
+ buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttontext :"Text on push buttons.",
+ captiontext :"Text in caption, size box, and scrollbar arrow box.",
+ graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
+ highlight :"Item(s) selected in a control.",
+ highlighttext :"Text of item(s) selected in a control.",
+ inactiveborder :"Inactive window border.",
+ inactivecaption :"Inactive window caption.",
+ inactivecaptiontext :"Color of text in an inactive caption.",
+ infobackground :"Background color for tooltip controls.",
+ infotext :"Text color for tooltip controls.",
+ menu :"Menu background.",
+ menutext :"Text in menus.",
+ scrollbar :"Scroll bar gray area.",
+ threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ window :"Window background.",
+ windowframe :"Window frame.",
+ windowtext :"Text in windows."
};
/*global SyntaxUnit, Parser*/
/**
@@ -1169,7 +1198,7 @@ MediaFeature.prototype.constructor = MediaFeature;
*/
function MediaQuery(modifier, mediaType, features, line, col){
- SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
+ SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
/**
* The media modifier ("not" or "only")
@@ -1908,18 +1937,21 @@ Parser.prototype = function(){
});
},
- _operator: function(){
+ _operator: function(inFunction){
/*
- * operator
+ * operator (outside function)
* : '/' S* | ',' S* | /( empty )/
+ * operator (inside function)
+ * : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
- if (tokenStream.match([Tokens.SLASH, Tokens.COMMA])){
+ if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
+ (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
token = tokenStream.token();
this._readWhitespace();
}
@@ -2706,7 +2738,7 @@ Parser.prototype = function(){
return result;
},
- _expr: function(){
+ _expr: function(inFunction){
/*
* expr
* : term [ operator term ]*
@@ -2725,8 +2757,8 @@ Parser.prototype = function(){
values.push(value);
do {
- operator = this._operator();
-
+ operator = this._operator(inFunction);
+
//if there's an operator, keep building up the value parts
if (operator){
values.push(operator);
@@ -2862,7 +2894,7 @@ Parser.prototype = function(){
if (tokenStream.match(Tokens.FUNCTION)){
functionText = tokenStream.token().value;
this._readWhitespace();
- expr = this._expr();
+ expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
@@ -3888,7 +3920,7 @@ var Properties = {
"user-select" : "none | text | toggle | element | elements | all | inherit",
//V
- "vertical-align" : "<percentage> | <length> | baseline | sub | super | top | text-top | middle | bottom | text-bottom | inherit",
+ "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
"visibility" : "visible | hidden | collapse | inherit",
"voice-balance" : 1,
"voice-duration" : 1,
@@ -3901,7 +3933,7 @@ var Properties = {
"volume" : 1,
//W
- "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit",
+ "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", //http://perishablepress.com/wrapping-content/
"white-space-collapse" : 1,
"widows" : "<integer> | inherit",
"width" : "<length> | <percentage> | auto | inherit" ,
@@ -6061,7 +6093,11 @@ var ValidationTypes = {
},
"<length>": function(part){
- return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
+ return true;
+ }else{
+ return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ }
},
"<color>": function(part){
64 build/npm/lib/node-parserlib.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
var parserlib = {};
(function(){
@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1080,7 +1080,36 @@ var Colors = {
white :"#ffffff",
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
- yellowgreen :"#9acd32"
+ yellowgreen :"#9acd32",
+ //CSS2 system colors http://www.w3.org/TR/css3-color/#css2-system
+ activeBorder :"Active window border.",
+ activecaption :"Active window caption.",
+ appworkspace :"Background color of multiple document interface.",
+ background :"Desktop background.",
+ buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttontext :"Text on push buttons.",
+ captiontext :"Text in caption, size box, and scrollbar arrow box.",
+ graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
+ highlight :"Item(s) selected in a control.",
+ highlighttext :"Text of item(s) selected in a control.",
+ inactiveborder :"Inactive window border.",
+ inactivecaption :"Inactive window caption.",
+ inactivecaptiontext :"Color of text in an inactive caption.",
+ infobackground :"Background color for tooltip controls.",
+ infotext :"Text color for tooltip controls.",
+ menu :"Menu background.",
+ menutext :"Text in menus.",
+ scrollbar :"Scroll bar gray area.",
+ threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ window :"Window background.",
+ windowframe :"Window frame.",
+ windowtext :"Text in windows."
};
/*global SyntaxUnit, Parser*/
/**
@@ -1169,7 +1198,7 @@ MediaFeature.prototype.constructor = MediaFeature;
*/
function MediaQuery(modifier, mediaType, features, line, col){
- SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType + " " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
+ SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
/**
* The media modifier ("not" or "only")
@@ -1908,18 +1937,21 @@ Parser.prototype = function(){
});
},
- _operator: function(){
+ _operator: function(inFunction){
/*
- * operator
+ * operator (outside function)
* : '/' S* | ',' S* | /( empty )/
+ * operator (inside function)
+ * : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
- if (tokenStream.match([Tokens.SLASH, Tokens.COMMA])){
+ if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
+ (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
token = tokenStream.token();
this._readWhitespace();
}
@@ -2706,7 +2738,7 @@ Parser.prototype = function(){
return result;
},
- _expr: function(){
+ _expr: function(inFunction){
/*
* expr
* : term [ operator term ]*
@@ -2725,8 +2757,8 @@ Parser.prototype = function(){
values.push(value);
do {
- operator = this._operator();
-
+ operator = this._operator(inFunction);
+
//if there's an operator, keep building up the value parts
if (operator){
values.push(operator);
@@ -2862,7 +2894,7 @@ Parser.prototype = function(){
if (tokenStream.match(Tokens.FUNCTION)){
functionText = tokenStream.token().value;
this._readWhitespace();
- expr = this._expr();
+ expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
@@ -3888,7 +3920,7 @@ var Properties = {
"user-select" : "none | text | toggle | element | elements | all | inherit",
//V
- "vertical-align" : "<percentage> | <length> | baseline | sub | super | top | text-top | middle | bottom | text-bottom | inherit",
+ "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
"visibility" : "visible | hidden | collapse | inherit",
"voice-balance" : 1,
"voice-duration" : 1,
@@ -3901,7 +3933,7 @@ var Properties = {
"volume" : 1,
//W
- "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit",
+ "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", //http://perishablepress.com/wrapping-content/
"white-space-collapse" : 1,
"widows" : "<integer> | inherit",
"width" : "<length> | <percentage> | auto | inherit" ,
@@ -6061,7 +6093,11 @@ var ValidationTypes = {
},
"<length>": function(part){
- return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
+ return true;
+ }else{
+ return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ }
},
"<color>": function(part){
2  build/parserlib-core.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
var parserlib = {};
(function(){
62 build/parserlib-css.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 14-November-2012 10:32:32 */
+/* Version v@VERSION@, Build time: 4-December-2012 11:58:48 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -170,7 +170,36 @@ var Colors = {
white :"#ffffff",
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
- yellowgreen :"#9acd32"
+ yellowgreen :"#9acd32",
+ //CSS2 system colors http://www.w3.org/TR/css3-color/#css2-system
+ activeBorder :"Active window border.",
+ activecaption :"Active window caption.",
+ appworkspace :"Background color of multiple document interface.",
+ background :"Desktop background.",
+ buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
+ buttontext :"Text on push buttons.",
+ captiontext :"Text in caption, size box, and scrollbar arrow box.",
+ graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
+ highlight :"Item(s) selected in a control.",
+ highlighttext :"Text of item(s) selected in a control.",
+ inactiveborder :"Inactive window border.",
+ inactivecaption :"Inactive window caption.",
+ inactivecaptiontext :"Color of text in an inactive caption.",
+ infobackground :"Background color for tooltip controls.",
+ infotext :"Text color for tooltip controls.",
+ menu :"Menu background.",
+ menutext :"Text in menus.",
+ scrollbar :"Scroll bar gray area.",
+ threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
+ window :"Window background.",
+ windowframe :"Window frame.",
+ windowtext :"Text in windows."
};
/*global SyntaxUnit, Parser*/
/**
@@ -259,7 +288,7 @@ MediaFeature.prototype.constructor = MediaFeature;
*/
function MediaQuery(modifier, mediaType, features, line, col){
- SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType + " " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
+ SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
/**
* The media modifier ("not" or "only")
@@ -998,18 +1027,21 @@ Parser.prototype = function(){
});
},
- _operator: function(){
+ _operator: function(inFunction){
/*
- * operator
+ * operator (outside function)
* : '/' S* | ',' S* | /( empty )/
+ * operator (inside function)
+ * : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
- if (tokenStream.match([Tokens.SLASH, Tokens.COMMA])){
+ if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
+ (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
token = tokenStream.token();
this._readWhitespace();
}
@@ -1796,7 +1828,7 @@ Parser.prototype = function(){
return result;
},
- _expr: function(){
+ _expr: function(inFunction){
/*
* expr
* : term [ operator term ]*
@@ -1815,8 +1847,8 @@ Parser.prototype = function(){
values.push(value);
do {
- operator = this._operator();
-
+ operator = this._operator(inFunction);
+
//if there's an operator, keep building up the value parts
if (operator){
values.push(operator);
@@ -1952,7 +1984,7 @@ Parser.prototype = function(){
if (tokenStream.match(Tokens.FUNCTION)){
functionText = tokenStream.token().value;
this._readWhitespace();
- expr = this._expr();
+ expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
@@ -2978,7 +3010,7 @@ var Properties = {
"user-select" : "none | text | toggle | element | elements | all | inherit",
//V
- "vertical-align" : "<percentage> | <length> | baseline | sub | super | top | text-top | middle | bottom | text-bottom | inherit",
+ "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
"visibility" : "visible | hidden | collapse | inherit",
"voice-balance" : 1,
"voice-duration" : 1,
@@ -2991,7 +3023,7 @@ var Properties = {
"volume" : 1,
//W
- "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit",
+ "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", //http://perishablepress.com/wrapping-content/
"white-space-collapse" : 1,
"widows" : "<integer> | inherit",
"width" : "<length> | <percentage> | auto | inherit" ,
@@ -5151,7 +5183,11 @@ var ValidationTypes = {
},
"<length>": function(part){
- return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
+ return true;
+ }else{
+ return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ }
},
"<color>": function(part){
855 build/parserlib-tests.js
View
<
@@ -1,26 +1,26 @@
(function(){
-
+
var Assert = YUITest.Assert,
MediaQuery = parserlib.css.MediaQuery,
Selector = parserlib.css.Selector,
Combinator = parserlib.css.Combinator,
SelectorPart = parserlib.css.SelectorPart,
Parser = parserlib.css.Parser;
-
+
//-------------------------------------------------------------------------
// Base Test Suite
//-------------------------------------------------------------------------
-
+
var suite = new YUITest.TestSuite("Selector Parsing");
-
+
suite.add(new YUITest.TestCase({
-
+
name: "Type Selector Tests",
-
+
testSimpleTypeSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("li");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(Parser.SELECTOR_TYPE, result.type);
Assert.areEqual(1, result.line, "Line start should be 1");
@@ -32,11 +32,11 @@
Assert.areEqual(0, result.parts[0].modifiers, "Element should have zero modifiers.");
Assert.areEqual(1, result.specificity.valueOf());
},
-
+
testSimpleTypeSelectorPlusNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("svg|rect");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(Parser.SELECTOR_TYPE, result.type);
Assert.areEqual(1, result.line, "Line start should be 1");
@@ -47,11 +47,11 @@
Assert.areEqual(0, result.parts[0].modifiers, "Element should have zero modifiers.");
Assert.areEqual(1, result.specificity.valueOf());
},
-
+
testSimpleTypeSelectorPlusBlankNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("|rect");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -61,11 +61,11 @@
Assert.areEqual(0, result.parts[0].modifiers, "Element should have zero modifiers.");
Assert.areEqual(1, result.specificity.valueOf());
},
-
+
testSimpleTypeSelectorPlusUniversalNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("*|rect");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -74,17 +74,17 @@
Assert.areEqual("*|rect", result.parts[0].elementName, "Element name should be '*|rect'.");
Assert.areEqual(0, result.parts[0].modifiers, "Element should have zero modifiers.");
Assert.areEqual(1, result.specificity.valueOf());
- }
+ }
}));
-
+
suite.add(new YUITest.TestCase({
-
- name: "Universal Selector Tests",
-
+
+ name: "Universal Selector Tests",
+
testSimpleUniversalSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("*");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -94,11 +94,11 @@
Assert.areEqual(0, result.parts[0].modifiers.length, "Element should have zero modifiers.");
Assert.areEqual(0, result.specificity.valueOf());
},
-
+
testSimpleUniversalSelectorPlusNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("svg|*");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -108,11 +108,11 @@
Assert.areEqual(0, result.parts[0].modifiers.length, "Element should have zero modifiers.");
Assert.areEqual(0, result.specificity.valueOf());
},
-
+
testSimpleUniversalSelectorPlusBlankNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("|*");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -122,11 +122,11 @@
Assert.areEqual(0, result.parts[0].modifiers.length, "Element should have zero modifiers.");
Assert.areEqual(0, result.specificity.valueOf());
},
-
+
testSimpleUniversalSelectorPlusUniversalNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("*|*");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -135,18 +135,18 @@
Assert.areEqual("*|*", result.parts[0].elementName, "Element name should be '*|*'.");
Assert.areEqual(0, result.parts[0].modifiers.length, "Element should have zero modifiers.");
Assert.areEqual(0, result.specificity.valueOf());
- }
-
+ }
+
}));
suite.add(new YUITest.TestCase({
-
- name: "Attribute Selector Tests",
-
+
+ name: "Attribute Selector Tests",
+
testAttributePresenceSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("li[class]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -159,13 +159,13 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
-
+
testAttributeEquivalenceSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("li[class=\"selected\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -177,11 +177,11 @@
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
},
-
+
testAttributeEquivalenceSelectorNoString: function(){
var parser = new Parser();
var result = parser.parseSelector("li[class=selected]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -192,13 +192,13 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
-
+
testAttributeContainsSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("li[class~=\"selected\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -209,13 +209,13 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
-
+
testAttributeDashMatchSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("li[class|=\"selected\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -226,20 +226,20 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
testAttributeStartMatchSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("object[type^=\"image/\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("object", result.parts[0].elementName, "Element name should be 'object'.");
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("attribute", result.parts[0].modifiers[0].type, "Modifier type should be 'attribute'.");
- Assert.areEqual("[type^=\"image/\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[type^=\"image/\"]'.");
+ Assert.areEqual("[type^=\"image/\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[type^=\"image/\"]'.");
Assert.areEqual(7, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
@@ -248,14 +248,14 @@
testAttributeEndMatchSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("a[href$=\".html\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("a", result.parts[0].elementName, "Element name should be 'a'.");
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("attribute", result.parts[0].modifiers[0].type, "Modifier type should be 'attribute'.");
- Assert.areEqual("[href$=\".html\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[href$=\".html\"]'.");
+ Assert.areEqual("[href$=\".html\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[href$=\".html\"]'.");
Assert.areEqual(2, result.parts[0].modifiers[0].col, "Modifier column should be 2.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
@@ -264,14 +264,14 @@
testAttributeContainsMatchSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("p[title*=\"hello\"]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("p", result.parts[0].elementName, "Element name should be 'p'.");
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("attribute", result.parts[0].modifiers[0].type, "Modifier type should be 'attribute'.");
- Assert.areEqual("[title*=\"hello\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[title*=\"hello\"]'.");
+ Assert.areEqual("[title*=\"hello\"]", result.parts[0].modifiers[0].text, "Modifier text should be '[title*=\"hello\"]'.");
Assert.areEqual(2, result.parts[0].modifiers[0].col, "Modifier column should be 2.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
@@ -280,7 +280,7 @@
testAttributeEquivalenceSelectorNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("li[html|class=selected]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -291,13 +291,13 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
-
+
testAttributeEquivalenceSelectorUniversalNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("li[*|class=selected]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -308,13 +308,13 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
},
-
+
testAttributeEquivalenceSelectorDefaultNamespace: function(){
var parser = new Parser();
var result = parser.parseSelector("li[|class=selected]");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -325,19 +325,19 @@
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Modifier column should be 3.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line should be 1.");
Assert.areEqual(11, result.specificity.valueOf());
-
+
}
}));
-
-
+
+
suite.add(new YUITest.TestCase({
-
- name: "Class Selector Tests",
-
+
+ name: "Class Selector Tests",
+
testSimpleClassSelector: function(){
var parser = new Parser();
var result = parser.parseSelector(".selected");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -349,13 +349,13 @@
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("class", result.parts[0].modifiers[0].type, "Modifier type should be 'class'.");
Assert.areEqual(".selected", result.parts[0].modifiers[0].text, "Modifier text should be '.selected'.");
-
+
},
-
+
testCompoundClassSelector: function(){
var parser = new Parser();
var result = parser.parseSelector(".selected.foo");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.line, "Line start should be 1");
Assert.areEqual(1, result.col, "Column start should be 1");
@@ -366,13 +366,13 @@
Assert.areEqual("class", result.parts[0].modifiers[0].type, "Modifier type should be 'class'.");
Assert.areEqual(".selected", result.parts[0].modifiers[0].text, "Modifier text should be '.selected'.");
Assert.areEqual("class", result.parts[0].modifiers[1].type, "Modifier type should be 'class'.");
- Assert.areEqual(".foo", result.parts[0].modifiers[1].text, "Modifier text should be '.foo'.");
+ Assert.areEqual(".foo", result.parts[0].modifiers[1].text, "Modifier text should be '.foo'.");
},
-
+
testSimpleClassSelectorWithElementName: function(){
var parser = new Parser();
var result = parser.parseSelector("li.selected");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -382,13 +382,13 @@
Assert.areEqual(".selected", result.parts[0].modifiers[0].text, "Modifier text should be '.selected'.");
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line start should be 1");
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Column start should be 3");
-
+
},
-
+
testCompoundClassSelectorWithElementName: function(){
var parser = new Parser();
var result = parser.parseSelector("li.selected.foo");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
@@ -399,424 +399,424 @@
Assert.areEqual(1, result.parts[0].modifiers[0].line, "Line start should be 1");
Assert.areEqual(3, result.parts[0].modifiers[0].col, "Column start should be 3");
Assert.areEqual("class", result.parts[0].modifiers[1].type, "Modifier type should be 'class'.");
- Assert.areEqual(".foo", result.parts[0].modifiers[1].text, "Modifier text should be '.foo'.");
+ Assert.areEqual(".foo", result.parts[0].modifiers[1].text, "Modifier text should be '.foo'.");
Assert.areEqual(1, result.parts[0].modifiers[1].line, "Line start should be 1");
Assert.areEqual(12, result.parts[0].modifiers[1].col, "Column start should be 12");
}
-
+
}));
suite.add(new YUITest.TestCase({
-
- name: "ID Selector Tests",
-
+
+ name: "ID Selector Tests",
+
testSimpleIDSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("#header");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.isNull(result.parts[0].elementName, "Element name should be null.");
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("id", result.parts[0].modifiers[0].type, "Modifier type should be 'id'.");
- Assert.areEqual("#header", result.parts[0].modifiers[0].text, "Modifier text should be '#header'.");
+ Assert.areEqual("#header", result.parts[0].modifiers[0].text, "Modifier text should be '#header'.");
},
-
+
testSimpleIDSelectorWithElementName: function(){
var parser = new Parser();
var result = parser.parseSelector("div#header");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("div", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("id", result.parts[0].modifiers[0].type, "Modifier type should be 'id'.");
- Assert.areEqual("#header", result.parts[0].modifiers[0].text, "Modifier text should be '#header'.");
+ Assert.areEqual("#header", result.parts[0].modifiers[0].text, "Modifier text should be '#header'.");
}
}));
suite.add(new YUITest.TestCase({
-
- name: "Pseudo Class Selector Tests",
-
+
+ name: "Pseudo Class Selector Tests",
+
testSimplePseudoClassSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("a:hover");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("a", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":hover", result.parts[0].modifiers[0].text, "Modifier text should be ':hover'.");
+ Assert.areEqual(":hover", result.parts[0].modifiers[0].text, "Modifier text should be ':hover'.");
},
-
+
testMultiplePseudoClassSelectors: function(){
var parser = new Parser();
var result = parser.parseSelector("a:focus:hover");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("a", result.parts[0].elementName);
Assert.areEqual(2, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":focus", result.parts[0].modifiers[0].text, "Modifier text should be ':focus'.");
+ Assert.areEqual(":focus", result.parts[0].modifiers[0].text, "Modifier text should be ':focus'.");
Assert.areEqual("pseudo", result.parts[0].modifiers[1].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":hover", result.parts[0].modifiers[1].text, "Modifier text should be ':hover'.");
+ Assert.areEqual(":hover", result.parts[0].modifiers[1].text, "Modifier text should be ':hover'.");
},
-
+
testPseudoClassFunctionSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("html:lang(fr-be)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("html", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":lang(fr-be)", result.parts[0].modifiers[0].text, "Modifier text should be ':lang(fr-be)'.");
+ Assert.areEqual(":lang(fr-be)", result.parts[0].modifiers[0].text, "Modifier text should be ':lang(fr-be)'.");
},
-
+
testPseudoClassNthSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:nth-child(2n+1)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("tr", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":nth-child(2n+1)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(2n+1)'.");
+ Assert.areEqual(":nth-child(2n+1)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(2n+1)'.");
},
-
+
testPseudoClassNthSelector2: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:nth-child(even)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("tr", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":nth-child(even)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(even)'.");
+ Assert.areEqual(":nth-child(even)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(even)'.");
},
-
+
testPseudoClassNthSelector3: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:nth-child(5)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("tr", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":nth-child(5)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(5)'.");
+ Assert.areEqual(":nth-child(5)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-child(5)'.");
},
-
+
testPseudoClassNthSelector4: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:nth-of-type(5)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("tr", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":nth-of-type(5)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-of-type(5)'.");
+ Assert.areEqual(":nth-of-type(5)", result.parts[0].modifiers[0].text, "Modifier text should be ':nth-of-type(5)'.");
},
-
+
testPseudoClassLastChildSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:last-child");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("tr", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":last-child", result.parts[0].modifiers[0].text, "Modifier text should be ':last-child'.");
+ Assert.areEqual(":last-child", result.parts[0].modifiers[0].text, "Modifier text should be ':last-child'.");
},
-
+
testPseudoClassNotSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("button:not([DISABLED])");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("button", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("not", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":not([DISABLED])", result.parts[0].modifiers[0].text, "Modifier text should be ':not([DISABLED])'.");
+ Assert.areEqual(":not([DISABLED])", result.parts[0].modifiers[0].text, "Modifier text should be ':not([DISABLED])'.");
Assert.areEqual(1, result.parts[0].modifiers[0].args.length, "Modifier should have one argument.");
-
+
var arg = result.parts[0].modifiers[0].args[0];
-
+
Assert.isInstanceOf(SelectorPart, arg, "Result should be an instance of Selector.");
Assert.areEqual("[DISABLED]", arg.toString());
Assert.isNull(arg.elementName);
Assert.areEqual(1, arg.modifiers.length);
Assert.areEqual("attribute", arg.modifiers[0].type);
},
-
+
testPseudoClassNotSelector2: function(){
var parser = new Parser();
var result = parser.parseSelector("button:not(foo)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("button", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("not", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual(":not(foo)", result.parts[0].modifiers[0].text, "Modifier text should be ':not(foo)'.");
+ Assert.areEqual(":not(foo)", result.parts[0].modifiers[0].text, "Modifier text should be ':not(foo)'.");
Assert.areEqual(1, result.parts[0].modifiers[0].args.length, "Modifier should have one argument.");
var arg = result.parts[0].modifiers[0].args[0];
-
+
Assert.isInstanceOf(SelectorPart, arg, "Result should be an instance of Selector.");
Assert.areEqual("foo", arg.toString());
Assert.areEqual("foo", arg.elementName, "Element name should be 'foo'.");
Assert.areEqual(0, arg.modifiers.length);
- }
+ }
}));
suite.add(new YUITest.TestCase({
-
- name: "Pseudo Element Selector Tests",
-
+
+ name: "Pseudo Element Selector Tests",
+
testSimplePseudoElementSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("p::first-line");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(1, result.parts.length, "Selector should have one parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("p", result.parts[0].elementName);
Assert.areEqual(1, result.parts[0].modifiers.length, "Element should have one modifier.");
Assert.areEqual("pseudo", result.parts[0].modifiers[0].type, "Modifier type should be 'pseudo'.");
- Assert.areEqual("::first-line", result.parts[0].modifiers[0].text, "Modifier text should be '::first-line'.");
+ Assert.areEqual("::first-line", result.parts[0].modifiers[0].text, "Modifier text should be '::first-line'.");
}
}));
suite.add(new YUITest.TestCase({
-
+
name: "Combinators",
-
-
+
+
testChildCombinator: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover > p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(">", result.parts[1].text);
Assert.areEqual("child", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testChildCombinatorNoSpaces: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover>p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(">", result.parts[1].text);
Assert.areEqual("child", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testChildCombinatorOneSpaceBefore: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover >p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(">", result.parts[1].text);
Assert.areEqual("child", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testChildCombinatorOneSpaceAfter: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover> p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(">", result.parts[1].text);
Assert.areEqual("child", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testAdjacentSiblingCombinator: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover + p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual("+", result.parts[1].text);
Assert.areEqual("adjacent-sibling", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testGeneralSiblingCombinator: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover ~ p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual("~", result.parts[1].text);
Assert.areEqual("sibling", result.parts[1].type);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testDescendantCombinator: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
- Assert.areEqual(1, result.parts[0].modifiers[0].line, "The line should be 1.");
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual(1, result.parts[0].modifiers[0].line, "The line should be 1.");
Assert.areEqual(3, result.parts[0].modifiers[0].col, "The column should be 3.");
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
- Assert.areEqual(1, result.parts[0].modifiers[1].line, "The line should be 1.");
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual(1, result.parts[0].modifiers[1].line, "The line should be 1.");
Assert.areEqual(10, result.parts[0].modifiers[1].col, "The column should be 10.");
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(" ", result.parts[1].text);
Assert.areEqual("descendant", result.parts[1].type);
Assert.areEqual(1, result.parts[1].line, "Line should be 1.");
Assert.areEqual(16, result.parts[1].col, "Column should be 16.");
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
Assert.areEqual(1, result.parts[2].elementName.line, "Line should be 1.");
- Assert.areEqual(17, result.parts[2].elementName.col, "Column should be 17.");
+ Assert.areEqual(17, result.parts[2].elementName.col, "Column should be 17.");
},
-
+
testDescendantCombinatorWithTrailingWhitespace: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover p ");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.areEqual("li", result.parts[0].elementName);
Assert.areEqual(".inline", result.parts[0].modifiers[0].text);
- Assert.areEqual("class", result.parts[0].modifiers[0].type);
+ Assert.areEqual("class", result.parts[0].modifiers[0].type);
Assert.areEqual(":hover", result.parts[0].modifiers[1].text);
- Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
+ Assert.areEqual("pseudo", result.parts[0].modifiers[1].type);
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(" ", result.parts[1].text);
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual("p", result.parts[2].elementName);
},
-
+
testWithCombinator: function(){
var parser = new Parser();
var result = parser.parseSelector("li.inline:hover > p");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(1, result.parts[1].line, "Line should be 1.");
Assert.areEqual(17, result.parts[1].col, "Column should be 17.");
- Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
+ Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
},
-
+
testWithNthChild: function(){
var parser = new Parser();
var result = parser.parseSelector("tr:nth-child(2n+1) a");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
Assert.areEqual(3, result.parts.length, "Should be three parts.");
-
+
}
-
-
+
+
//body > h2:nth-of-type(n+2):nth-last-of-type(n+2)
- //body > h2:not(:first-of-type):not(:last-of-type)
+ //body > h2:not(:first-of-type):not(:last-of-type)
//html|*:not(:link):not(:visited)
}));
suite.add(new YUITest.TestCase({
-
+
name: "Complex Cases",
-
+
testWithComplexSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("body > h2:nth-of-type(n+2):nth-last-of-type(n+2)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
- Assert.areEqual(3, result.parts.length, "Should be three parts.");
-
+ Assert.areEqual(3, result.parts.length, "Should be three parts.");
+
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.areEqual(1, result.parts[1].line, "Line should be 1.");
@@ -825,41 +825,41 @@
Assert.areEqual(1, result.parts[2].line, "Line should be 1.");
Assert.areEqual(8, result.parts[2].col, "Column should be 8.");
},
-
+
testWithComplexSelector2: function(){
var parser = new Parser();
var result = parser.parseSelector("body > h2:not(:first-of-type):not(:last-of-type)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
- Assert.areEqual(3, result.parts.length, "Should be three parts.");
-
+ Assert.areEqual(3, result.parts.length, "Should be three parts.");
+
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
},
-
+
testWithComplexSelector3: function(){
var parser = new Parser();
var result = parser.parseSelector("html|*:not(:link):not(:visited)");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
- Assert.areEqual(1, result.parts.length, "Should be one part.");
-
+ Assert.areEqual(1, result.parts.length, "Should be one part.");
+
Assert.isInstanceOf(SelectorPart, result.parts[0], "First part should be a SelectorPart.");
//Assert.isInstanceOf(Combinator, result.parts[1], "Second part should be a Combinator.");
//Assert.isInstanceOf(SelectorPart, result.parts[2], "Third part should be a SelectorPart.");
},
-
+
testWithMultipartSelector: function(){
var parser = new Parser();
var result = parser.parseSelector("ul li a span");
-
+
Assert.isInstanceOf(Selector, result, "Result should be an instance of Selector.");
- Assert.areEqual(7, result.parts.length, "Should be four parts.");
-
+ Assert.areEqual(7, result.parts.length, "Should be four parts.");
+
Assert.isInstanceOf(SelectorPart, result.parts[0], "Part should be a SelectorPart.");
Assert.areEqual("ul", result.parts[0].elementName);
-
+
Assert.isInstanceOf(SelectorPart, result.parts[2], "Part should be a SelectorPart.");
Assert.areEqual("li", result.parts[2].elementName);
@@ -868,59 +868,62 @@
Assert.isInstanceOf(SelectorPart, result.parts[6], "Part should be a SelectorPart.");
Assert.areEqual("span", result.parts[6].elementName);
-
+
}
-
-
-
+
+
+
}));
-
-
+
+
suite.add(new YUITest.TestCase({
-
+
name: "Media Queries",
-
-
+
+
testSimpleMediaQuery: function(){
var parser = new Parser();
var result = parser.parseMediaQuery("print");
-
+
Assert.isInstanceOf(MediaQuery, result, "Result should be an instance of MediaQuery.");
Assert.areEqual(1, result.line, "Line should be 1");
Assert.areEqual(1, result.col, "Column should be 1");
Assert.isNull(result.modifier);
Assert.areEqual("print", result.mediaType);
Assert.areEqual(0, result.features.length, "Should be zero parts.");
+ Assert.areEqual("print", result.text);
},
-
+
testSimpleMediaQueryNot: function(){
var parser = new Parser();
var result = parser.parseMediaQuery("not print");
-
+
Assert.isInstanceOf(MediaQuery, result, "Result should be an instance of MediaQuery.");
Assert.areEqual(1, result.line, "Line should be 1");
Assert.areEqual(1, result.col, "Column should be 1");
Assert.areEqual("not", result.modifier);
Assert.areEqual("print", result.mediaType);
Assert.areEqual(0, result.features.length, "Should be zero parts.");
+ Assert.areEqual("not print", result.text);
},
-
+
testSimpleMediaQueryOnly: function(){
var parser = new Parser();
var result = parser.parseMediaQuery("only print");
-
+
Assert.isInstanceOf(MediaQuery, result, "Result should be an instance of MediaQuery.");
Assert.areEqual(1, result.line, "Line should be 1");
Assert.areEqual(1, result.col, "Column should be 1");
Assert.areEqual("only", result.modifier);
Assert.areEqual("print", result.mediaType);
Assert.areEqual(0, result.features.length, "Should be zero parts.");
+ Assert.areEqual("only print", result.text);
},
-
+
testComplexMediaQuery: function(){
var parser = new Parser();
var result = parser.parseMediaQuery("screen and (max-weight: 3kg) and (color)");
-
+
Assert.isInstanceOf(MediaQuery, result, "Result should be an instance of MediaQuery.");
Assert.areEqual(1, result.line, "Line should be 1");
Assert.areEqual(1, result.col, "Column should be 1");
@@ -933,13 +936,14 @@
Assert.areEqual("color", result.features[1].name);
Assert.isNull(result.features[1].value);
Assert.areEqual(35, result.features[1].name.col);
-
+ Assert.areEqual("screen and (max-weight:3kg) and (color)", result.text);
+
},
-
+
testComplexMediaQuery2: function(){
var parser = new Parser();
var result = parser.parseMediaQuery("only screen and (max-device-width: 768px) and (orientation:portrait)");
-
+
Assert.isInstanceOf(MediaQuery, result, "Result should be an instance of MediaQuery.");
Assert.areEqual(1, result.line, "Line should be 1");
Assert.areEqual(1, result.col, "Column should be 1");
@@ -950,330 +954,340 @@
Assert.areEqual("768px", result.features[0].value);
Assert.areEqual("orientation", result.features[1].name);
Assert.areEqual("portrait", result.features[1].value);
+ Assert.areEqual("only screen and (max-device-width:768px) and (orientation:portrait)", result.text);
}
-
-
+
+
}));
suite.add(new YUITest.TestCase({
-
+
name: "Property Values",
-
+
testDimensionValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("1px");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("length", result.parts[0].type);
+ Assert.areEqual("length", result.parts[0].type);
Assert.areEqual(1, result.parts[0].value);
Assert.areEqual("px", result.parts[0].units);
},
-
+
testDimensionValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("1ch");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("length", result.parts[0].type);
+ Assert.areEqual("length", result.parts[0].type);
Assert.areEqual(1, result.parts[0].value);
Assert.areEqual("ch", result.parts[0].units);
},
-
+
testPercentageValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("25.4%");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("percentage", result.parts[0].type);
+ Assert.areEqual("percentage", result.parts[0].type);
Assert.areEqual(25.4, result.parts[0].value);
},
-
+
testIntegerValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("25");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("integer", result.parts[0].type);
+ Assert.areEqual("integer", result.parts[0].type);
Assert.areEqual(25, result.parts[0].value);
},
-
+
testNumberValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("25.0");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("number", result.parts[0].type);
+ Assert.areEqual("number", result.parts[0].type);
Assert.areEqual(25, result.parts[0].value);
},
-
+
testHexColorValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("#ffeedd");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(255, result.parts[0].red);
Assert.areEqual(238, result.parts[0].green);
Assert.areEqual(221, result.parts[0].blue);
},
-
+
testRGBColorValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("rgb(255, 238 , 221)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(255, result.parts[0].red);
Assert.areEqual(238, result.parts[0].green);
Assert.areEqual(221, result.parts[0].blue);
},
-
+
testRGBColorValue2: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("rgb(100%,50%, 75%)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(255, result.parts[0].red);
Assert.areEqual(127.5, result.parts[0].green);
Assert.areEqual(191.25, result.parts[0].blue);
},
-
+
testRGBAColorValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("rgba(255, 238 , 221, 0.3)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(255, result.parts[0].red);
Assert.areEqual(238, result.parts[0].green);
Assert.areEqual(221, result.parts[0].blue);
Assert.areEqual(0.3, result.parts[0].alpha);
},
-
+
testRGBAColorValue2: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("rgba(100%,50%, 75%, 0.5)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(255, result.parts[0].red);
Assert.areEqual(127.5, result.parts[0].green);
Assert.areEqual(191.25, result.parts[0].blue);
Assert.areEqual(0.5, result.parts[0].alpha);
},
-
+
testHSLColorValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("hsl(100,50%, 75%)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(100, result.parts[0].hue);
Assert.areEqual(0.5, result.parts[0].saturation);
Assert.areEqual(0.75, result.parts[0].lightness);
},
-
+
testHSLAColorValue: function(){
var parser = new Parser();
var result = parser.parsePropertyValue("hsla(100,50%, 75%, 0.5)");
-
+
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
Assert.areEqual(1, result.parts.length);
- Assert.areEqual("color", result.parts[0].type);
+ Assert.areEqual("color", result.parts[0].type);
Assert.areEqual(100, result.parts[0].hue);
Assert.areEqual(0.5, result.parts[0].saturation);
Assert.areEqual(0.75, result.parts[0].lightness);
Assert.areEqual(0.5, result.parts[0].alpha);
- },
-
+ },
+
testColorValue: function(){
var parser = new Parser();