Index: utils/tests/css/src/ExpressionTest.dart |
diff --git a/utils/tests/css/src/ExpressionTest.dart b/utils/tests/css/src/ExpressionTest.dart |
index 777b40e88980fd7ec27e5bf258473593d175a38a..b4f03182c6d74471b56703053d6d79673b7aae11 100644 |
--- a/utils/tests/css/src/ExpressionTest.dart |
+++ b/utils/tests/css/src/ExpressionTest.dart |
@@ -2,10 +2,10 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-#import('../../../../frog/lang.dart', prefix:'lang'); |
#import("../../../css/css.dart"); |
+#import('../../../../frog/lang.dart', prefix:'lang'); |
-class SelectorLiteralTest { |
+class ExpressionTest { |
static testMain() { |
initCssWorld(); |
@@ -24,239 +24,298 @@ class SelectorLiteralTest { |
static void testClass() { |
Parser parser = new Parser(new lang.SourceFile( |
- lang.SourceFile.IN_MEMORY_FILE, ".foobar")); |
- |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- Expect.equals(selectorGroup.selectors.length, 1); |
- for (selector in selectorGroup.selectors) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "foobar"); |
- } |
+ lang.SourceFile.IN_MEMORY_FILE, ".foobar {}")); |
+ |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ Expect.equals(simpleSeqs.length, 1); |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "foobar"); |
} |
parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- ".foobar .bar .no-story")); |
+ ".foobar .bar .no-story {}")); |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- if (idx == 0) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "foobar"); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "bar"); |
- } else if (idx == 2) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "no-story"); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
- idx++; |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ var idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "foobar"); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "bar"); |
+ } else if (idx == 2) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "no-story"); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
+ |
+ Expect.equals(simpleSeqs.length, idx); |
} |
static void testId() { |
Parser parser = new Parser(new lang.SourceFile( |
- lang.SourceFile.IN_MEMORY_FILE, "#elemId")); |
- |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- Expect.isNotNull(exprTree); |
- for (selectorGroup in exprTree) { |
- Expect.equals(selectorGroup.selectors.length, 1); |
- for (selector in selectorGroup.selectors) { |
- Expect.isTrue(selector is IdSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "elemId"); |
- } |
+ lang.SourceFile.IN_MEMORY_FILE, "#elemId {}")); |
+ |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ Expect.isTrue(simpSelector is IdSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "elemId"); |
} |
} |
static void testElement() { |
Parser parser = new Parser(new lang.SourceFile( |
- lang.SourceFile.IN_MEMORY_FILE, "div")); |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- Expect.equals(selectorGroup.selectors.length, 1); |
- for (selector in selectorGroup.selectors) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "div"); |
- } |
+ lang.SourceFile.IN_MEMORY_FILE, "div {}")); |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "div"); |
} |
parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- "div div span")); |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- if (idx == 0) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "div"); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "div"); |
- } else if (idx == 2) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "span"); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
- |
- idx++; |
+ "div div span {}")); |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ var idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "div"); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "div"); |
+ } else if (idx == 2) { |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "span"); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
+ Expect.equals(simpleSeqs.length, idx); |
} |
static void testNamespace() { |
Parser parser = new Parser(new lang.SourceFile( |
- lang.SourceFile.IN_MEMORY_FILE, "ns1|div")); |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- Expect.equals(selectorGroup.selectors.length, 1); |
- for (selector in selectorGroup.selectors) { |
- Expect.isTrue(selector is NamespaceSelector); |
+ lang.SourceFile.IN_MEMORY_FILE, "ns1|div {}")); |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.isFalse(simpSelector.isNamespaceWildcard()); |
+ Expect.equals(simpSelector.namespace, "ns1"); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
+ Expect.isTrue(elementSelector is ElementSelector); |
+ Expect.isFalse(elementSelector.isWildcard()); |
+ Expect.equals(elementSelector.name, "div"); |
+ } |
+ |
+ parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
+ "ns1|div div ns2|span .foobar {}")); |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ var idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.isFalse(selector.isNamespaceWildcard()); |
- Expect.equals(selector.namespace, "ns1"); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
+ Expect.equals(simpSelector.namespace, "ns1"); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
Expect.isTrue(elementSelector is ElementSelector); |
Expect.isFalse(elementSelector.isWildcard()); |
Expect.equals(elementSelector.name, "div"); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "div"); |
+ } else if (idx == 2) { |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.namespace, "ns2"); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
+ Expect.isTrue(elementSelector is ElementSelector); |
+ Expect.isFalse(elementSelector.isWildcard()); |
+ Expect.equals(elementSelector.name, "span"); |
+ } else if (idx == 3) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "foobar"); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
- } |
- |
- parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- "ns1|div div ns2|span .foobar")); |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- if (idx == 0) { |
- Expect.isTrue(selector is NamespaceSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.namespace, "ns1"); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
- Expect.isTrue(elementSelector is ElementSelector); |
- Expect.isFalse(elementSelector.isWildcard()); |
- Expect.equals(elementSelector.name, "div"); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "div"); |
- } else if (idx == 2) { |
- Expect.isTrue(selector is NamespaceSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.namespace, "ns2"); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
- Expect.isTrue(elementSelector is ElementSelector); |
- Expect.isFalse(elementSelector.isWildcard()); |
- Expect.equals(elementSelector.name, "span"); |
- } else if (idx == 3) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "foobar"); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
- idx++; |
- } |
+ idx++; |
} |
+ |
+ Expect.equals(simpleSeqs.length, idx); |
} |
static void testSelectorGroups() { |
Parser parser = new Parser(new lang.SourceFile( |
lang.SourceFile.IN_MEMORY_FILE, |
- "div, .foobar ,#elemId, .xyzzy .test, ns1|div div #elemId .foobar")); |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 5); |
+ "div, .foobar ,#elemId, .xyzzy .test, ns1|div div #elemId .foobar {}")); |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 5); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
var groupIdx = 0; |
- for (selectorGroup in exprTree) { |
+ for (final selectorGroup in ruleset.selectorGroup.selectors) { |
var idx = 0; |
- for (selector in selectorGroup.selectors) { |
+ for (final selector in selectorGroup.simpleSelectorSequences) { |
+ final simpSelector = selector.simpleSelector; |
switch (groupIdx) { |
case 0: // First selector group. |
- Expect.equals(selectorGroup.selectors.length, 1); |
- Expect.isTrue(selector is ElementSelector); |
+ Expect.isTrue(simpSelector is ElementSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "div"); |
+ Expect.equals(simpSelector.name, "div"); |
break; |
case 1: // Second selector group. |
- Expect.equals(selectorGroup.selectors.length, 1); |
- Expect.isTrue(selector is ClassSelector); |
+ Expect.isTrue(simpSelector is ClassSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "foobar"); |
+ Expect.equals(simpSelector.name, "foobar"); |
break; |
case 2: // Third selector group. |
- Expect.equals(selectorGroup.selectors.length, 1); |
- Expect.isTrue(selector is IdSelector); |
+ Expect.isTrue(simpSelector is IdSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "elemId"); |
+ Expect.equals(simpSelector.name, "elemId"); |
break; |
case 3: // Fourth selector group. |
- Expect.equals(selectorGroup.selectors.length, 2); |
+ Expect.equals(selectorGroup.simpleSelectorSequences.length, 2); |
if (idx == 0) { |
- Expect.isTrue(selector is ClassSelector); |
+ Expect.isTrue(simpSelector is ClassSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "xyzzy"); |
+ Expect.equals(simpSelector.name, "xyzzy"); |
} else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
+ Expect.isTrue(simpSelector is ClassSelector); |
Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "test"); |
+ Expect.equals(simpSelector.name, "test"); |
} else { |
Expect.fail("unexpected expression"); |
} |
break; |
case 4: // Fifth selector group. |
- Expect.equals(selectorGroup.selectors.length, 4); |
+ Expect.equals(selectorGroup.simpleSelectorSequences.length, 4); |
if (idx == 0) { |
- Expect.isTrue(selector is NamespaceSelector); |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.namespace, "ns1"); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
+ Expect.equals(simpSelector.namespace, "ns1"); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
Expect.isTrue(elementSelector is ElementSelector); |
Expect.isFalse(elementSelector.isWildcard()); |
Expect.equals(elementSelector.name, "div"); |
} else if (idx == 1) { |
- Expect.isTrue(selector is ElementSelector); |
+ Expect.isTrue(simpSelector is ElementSelector); |
Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "div"); |
+ Expect.equals(simpSelector.name, "div"); |
} else if (idx == 2) { |
- Expect.isTrue(selector is IdSelector); |
+ Expect.isTrue(simpSelector is IdSelector); |
Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "elemId"); |
+ Expect.equals(simpSelector.name, "elemId"); |
} else if (idx == 3) { |
- Expect.isTrue(selector is ClassSelector); |
+ Expect.isTrue(simpSelector is ClassSelector); |
Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "foobar"); |
+ Expect.equals(simpSelector.name, "foobar"); |
} else { |
Expect.fail("unexpected expression"); |
} |
@@ -271,150 +330,185 @@ class SelectorLiteralTest { |
static void testCombinator() { |
Parser parser = new Parser(new lang.SourceFile( |
lang.SourceFile.IN_MEMORY_FILE, |
- ".foobar > .bar + .no-story ~ myNs|div #elemId")); |
- |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- Expect.equals(selectorGroup.selectors.length, 5); |
- for (selector in selectorGroup.selectors) { |
- if (idx == 0) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "foobar"); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorGreater()); |
- Expect.equals(selector.name, "bar"); |
- } else if (idx == 2) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorPlus()); |
- Expect.equals(selector.name, "no-story"); |
- } else if (idx == 3) { |
- Expect.isTrue(selector is NamespaceSelector); |
- Expect.isTrue(selector.isCombinatorTilde()); |
- Expect.equals(selector.namespace, "myNs"); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
- Expect.isTrue(elementSelector is ElementSelector); |
- Expect.isFalse(elementSelector.isWildcard()); |
- Expect.equals(elementSelector.name, "div"); |
- } else if (idx == 4) { |
- Expect.isTrue(selector is IdSelector); |
- Expect.isTrue(selector.isCombinatorDescendant()); |
- Expect.equals(selector.name, "elemId"); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
- |
- idx++; |
+ ".foobar > .bar + .no-story ~ myNs|div #elemId {}")); |
+ |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ Expect.equals(simpleSeqs.length, 5); |
+ var idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "foobar"); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorGreater()); |
+ Expect.equals(simpSelector.name, "bar"); |
+ } else if (idx == 2) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorPlus()); |
+ Expect.equals(simpSelector.name, "no-story"); |
+ } else if (idx == 3) { |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
+ Expect.isTrue(selector.isCombinatorTilde()); |
+ Expect.equals(simpSelector.namespace, "myNs"); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
+ Expect.isTrue(elementSelector is ElementSelector); |
+ Expect.isFalse(elementSelector.isWildcard()); |
+ Expect.equals(elementSelector.name, "div"); |
+ } else if (idx == 4) { |
+ Expect.isTrue(simpSelector is IdSelector); |
+ Expect.isTrue(selector.isCombinatorDescendant()); |
+ Expect.equals(simpSelector.name, "elemId"); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
} |
static void testWildcard() { |
Parser parser = new Parser(new lang.SourceFile( |
- lang.SourceFile.IN_MEMORY_FILE, "*")); |
- |
- List<SelectorGroup> exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- Expect.equals(selectorGroup.selectors.length, 1); |
- for (selector in selectorGroup.selectors) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.isTrue(selector.isWildcard()); |
- Expect.equals(selector.name, "*"); |
- } |
+ lang.SourceFile.IN_MEMORY_FILE, "* {}")); |
+ |
+ Stylesheet stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ RuleSet ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ List<SimpleSelectorSequence> simpleSeqs = |
+ ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.isTrue(simpSelector.isWildcard()); |
+ Expect.equals(simpSelector.name, "*"); |
} |
parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- "*.foobar")); |
- |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- Expect.equals(selectorGroup.selectors.length, 2); |
- if (idx == 0) { |
- Expect.isTrue(selector is ElementSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.isTrue(selector.isWildcard()); |
- Expect.equals(selector.name, "*"); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals(selector.name, "foobar"); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
- |
- idx++; |
+ "*.foobar {}")); |
+ |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ Expect.equals(simpleSeqs.length, 2); |
+ var idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is ElementSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.isTrue(simpSelector.isWildcard()); |
+ Expect.equals(simpSelector.name, "*"); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals(simpSelector.name, "foobar"); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- "myNs|*.foobar")); |
+ "myNs|*.foobar {}")); |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- Expect.equals(selectorGroup.selectors.length, 2); |
- if (idx == 0) { |
- Expect.isTrue(selector is NamespaceSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.isFalse(selector.isNamespaceWildcard()); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
- Expect.equals("myNs", selector.namespace); |
- Expect.isTrue(elementSelector.isWildcard()); |
- Expect.equals("*", elementSelector.name); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals("foobar", selector.name); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ Expect.equals(stylesheet.topLevels.length, 1); |
- idx++; |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ Expect.equals(simpleSeqs.length, 2); |
+ idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.isFalse(simpSelector.isNamespaceWildcard()); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
+ Expect.equals("myNs", simpSelector.namespace); |
+ Expect.isTrue(elementSelector.isWildcard()); |
+ Expect.equals("*", elementSelector.name); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals("foobar", simpSelector.name); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
parser = new Parser(new lang.SourceFile(lang.SourceFile.IN_MEMORY_FILE, |
- "*|*.foobar")); |
- |
- exprTree = parser.parse(); |
- Expect.isNotNull(exprTree); |
- Expect.equals(exprTree.length, 1); |
- for (selectorGroup in exprTree) { |
- var idx = 0; |
- for (selector in selectorGroup.selectors) { |
- Expect.equals(selectorGroup.selectors.length, 2); |
- if (idx == 0) { |
- Expect.isTrue(selector is NamespaceSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.isTrue(selector.isNamespaceWildcard()); |
- Expect.equals("*", selector.namespace); |
- ElementSelector elementSelector = selector.nameAsSimpleSelector; |
- Expect.isTrue(elementSelector.isWildcard()); |
- Expect.equals("*", elementSelector.name); |
- } else if (idx == 1) { |
- Expect.isTrue(selector is ClassSelector); |
- Expect.isTrue(selector.isCombinatorNone()); |
- Expect.equals("foobar", selector.name); |
- } else { |
- Expect.fail("unexpected expression"); |
- } |
- |
- idx++; |
+ "*|*.foobar {}")); |
+ |
+ stylesheet = parser.parse(); |
+ Expect.isNotNull(stylesheet); |
+ |
+ Expect.isTrue(stylesheet.topLevels[0] is RuleSet); |
+ ruleset = stylesheet.topLevels[0]; |
+ Expect.equals(ruleset.selectorGroup.selectors.length, 1); |
+ Expect.equals(ruleset.declarationGroup.declarations.length, 0); |
+ |
+ simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences; |
+ |
+ Expect.equals(simpleSeqs.length, 2); |
+ idx = 0; |
+ for (final selector in simpleSeqs) { |
+ final simpSelector = selector.simpleSelector; |
+ if (idx == 0) { |
+ Expect.isTrue(simpSelector is NamespaceSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.isTrue(simpSelector.isNamespaceWildcard()); |
+ Expect.equals("*", simpSelector.namespace); |
+ ElementSelector elementSelector = simpSelector.nameAsSimpleSelector; |
+ Expect.isTrue(elementSelector.isWildcard()); |
+ Expect.equals("*", elementSelector.name); |
+ } else if (idx == 1) { |
+ Expect.isTrue(simpSelector is ClassSelector); |
+ Expect.isTrue(selector.isCombinatorNone()); |
+ Expect.equals("foobar", simpSelector.name); |
+ } else { |
+ Expect.fail("unexpected expression"); |
} |
+ |
+ idx++; |
} |
} |
@@ -435,5 +529,5 @@ class SelectorLiteralTest { |
main() { |
- SelectorLiteralTest.testMain(); |
+ ExpressionTest.testMain(); |
} |