Skip to content
Browse files

Added additional Nth selector with odd spacing

  • Loading branch information...
1 parent dc5999c commit 572a14e76b3f5a789b676962dd1f327755b29f9a @bmavity committed Sep 22, 2010
Showing with 25 additions and 15 deletions.
  1. +6 −4 src/cssSelector.ometa
  2. +19 −11 tests/test.js
View
10 src/cssSelector.ometa
@@ -92,11 +92,13 @@ ometa CssSelector <: Parser {
equals_match = '=' -> { '=' },
pseudo = ':' ':' (functional_pseudo | IDENT):i -> { '::' + i }
| ':' (functional_pseudo | IDENT):i -> { ':' + i },
- functional_pseudo = FUNCTION:f S* expression:e ')' -> { f + e + ')' },
+ functional_pseudo = FUNCTION:f S* full_expression:e ')' -> { f + e + ')' },
- expression_content = (PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT):e S+ -> { e + ' ' }
- | (PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT):e -> { e },
- expression = (expression_content)+:ea -> { ea.join('') },
+ expression_content = (PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT):e -> { e },
+ expression = expression_content:ec S+ expression:e -> { ec + ' ' + e }
+ | expression_content:ec expression:e -> { ec + e }
+ | expression_content:ec S* -> { ec },
+ full_expression = (expression)+:ea -> { ea.join('') },
negation = NOT S* negation_arg S* ')',
negation_arg = type_selector | universal | HASH | class | attrib | pseudo
}
View
30 tests/test.js
@@ -18,6 +18,21 @@ var shouldParse = function() {
return context;
};
+var shouldParseTo = function(expectedSelector) {
+ var context = {
+ topic: function() {
+ var selector = this.context.name;
+ selectorGrammar.parse(selector, this.callback);
+ }
+ };
+
+ context['should parse selector'] = function(err, parsedSelector) {
+ assert.equal(parsedSelector, expectedSelector);
+ };
+
+ return context;
+};
+
vows.describe('Summarized Selectors').addBatch({
// Taken from http://www.w3.org/TR/css3-selectors/#selectors
@@ -133,17 +148,10 @@ vows.describe('Nth Selectors').addBatch({
':nth-child(2n-3)': shouldParse(),
':nth-child(+2n-3)': shouldParse(),
':nth-child(-2n+3)': shouldParse(),
- ':nth-child(-2n+ 3)': shouldParse()
-/*
- assert_equal(<<CSS, render(<<SCSS))
-
-:nth-child(2n + 3) {
-a: b; }
-CSS
-:nth-child( 2n + 3 ) {
-a: b; }
-SCSS
-*/
+ ':nth-child(-2n+ 3)': shouldParse(),
+ ':nth-child(-2n+ 3)': shouldParse(),
+ ':nth-child(-2n+ 3)': shouldParse(),
+ ':nth-child( 2n + 3 )': shouldParseTo(':nth-child(2n + 3)')
}).run();

0 comments on commit 572a14e

Please sign in to comment.
Something went wrong with that request. Please try again.