cz.vutbr.web.css.StyleSheet Java Examples
The following examples show how to use
cz.vutbr.web.css.StyleSheet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPseudoFunc() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PSEUDO_FUNC, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf.createPseudoClass("lang", "fr")); SelectorsUtil.appendChild(cslist, "Q"); assertArrayEquals("Rule contains one combined pseudoselector :lang(fr)>Q", cslist.toArray(), rule.getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createString("« ")); DeclarationsUtil.appendSpaceTerm(terms, tf.createString(" »")); assertEquals("Rule contains one declaration { quotes: '« ' ' »' }", DeclarationsUtil.appendDeclaration(null, "quotes", terms), rule .asList()); }
Example #2
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testDescendant() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_DESCENDANT, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "H1", null); SelectorsUtil.appendDescendant(cslist, "P"); assertArrayEquals("Rule contains one combined selectors H1 P ", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration {display:inline;}", DeclarationsUtil.appendDeclaration(null, "display", tf .createIdent("inline")), rule.asList()); }
Example #3
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static List<RuleBlock<?>> getAtRuleBlocks(StyleSheet styles, StylesEmbeddingOptions options) { List<RuleBlock<?>> rules = new ArrayList<>(); if (styles != null) { for (RuleBlock<?> ruleBlock : styles) { if (ruleBlock instanceof RuleMedia) { RuleMedia block = (RuleMedia) ruleBlock; for (RuleSet set : block) { set.forEach(HtmlUtils::resolveUris); } resolveMediaType(block.getMediaQueries(), options.getMediaType()); rules.add(block); } else if (ruleBlock instanceof RuleFontFace) { rules.add(ruleBlock); } } } return rules; }
Example #4
Source File: DOMAnalyzer.java From CSSBox with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a new DOM analyzer. * @param doc the document to be analyzed * @param baseUrl the base URL for loading the style sheets. If <code>detectBase</code>, this URL may be redefined by the <code><base></code> tag used in the * document header. * @param detectBase sets whether to try to accept the <code><base></code> tags in the document header. */ public DOMAnalyzer(org.w3c.dom.Document doc, URL baseUrl, boolean detectBase) { this.doc = doc; this.encoding = null; this.media = new MediaSpec(DEFAULT_MEDIA); styles = new Vector<StyleSheet>(); this.baseUrl = baseUrl; if (detectBase) { String docbase = getDocumentBase(); if (docbase != null) { try { this.baseUrl = new URL(baseUrl, docbase); log.info("Using specified document base " + this.baseUrl); } catch (MalformedURLException e) { log.warn("Malformed base URL " + docbase); } } } stylemap = null; istylemap = null; }
Example #5
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAttributePresence() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ATTRIB_PRESENCE, null); assertEquals("One rule is set", 1, ss.size()); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "*", null, rf .createAttribute(null, false, Selector.Operator.NO_OPERATOR, "href")); assertArrayEquals("Rule 1 contains one combined selector *[href]", cslist.toArray(), ((RuleSet) ss.get(0)).getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createIdent("Verdana")); DeclarationsUtil.appendCommaTerm(terms, tf.createIdent("monospace")); assertEquals( "Rule contains one declaration { text-decoration: underline }", DeclarationsUtil.appendDeclaration(null, "text-decoration", tf .createIdent("underline")), ((RuleSet) ss.get(0)) .asList()); }
Example #6
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void pseudoClassDirect() throws SAXException, IOException { DOMSource ds = new DOMSource(getClass().getResourceAsStream("/simple/pseudo.html")); Document doc = ds.parse(); ElementMap elements = new ElementMap(doc); MatchConditionOnElements cond = new MatchConditionOnElements("a", PseudoClassType.LINK); cond.addMatch(elements.getElementById("l2"), PseudoClassType.HOVER); cond.addMatch(elements.getElementById("l3"), PseudoClassType.VISITED); CSSFactory.registerDefaultMatchCondition(cond); StyleSheet style = CSSFactory.getUsedStyles(doc, null, createBaseFromFilename("data/simple/selectors.html"),"screen"); DirectAnalyzer da = new DirectAnalyzer(style); NodeData l1 = getStyleById(elements, da, "l1"); NodeData l2 = getStyleById(elements, da, "l2"); NodeData l3 = getStyleById(elements, da, "l3"); assertThat(l1.getValue(TermColor.class, "color"), is(tf.createColor(0,255,0))); assertThat(l2.getValue(TermColor.class, "color"), is(tf.createColor(0,255,255))); assertThat(l3.getValue(TermColor.class, "color"), is(tf.createColor(0,0,170))); }
Example #7
Source File: FontFaceTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testFFMultiSrc2() throws IOException, CSSException { log.info("input:\n\n\n" + TEST_STRING3 + "\n\n\n"); StyleSheet ss; ss = CSSFactory.parseString(TEST_STRING3, null); assertEquals("Two rules are set", 2, ss.size()); RuleFontFace rule = (RuleFontFace) ss.get(0); assertEquals("Rule contains 3 declarations ", 3, rule.size()); assertEquals("Rule contains font-family declaration", "font-family: 'MyWebFont';\n", rule.get(0).toString()); // assertEquals("Rule contains scr declaration", // "src: url('myfont.woff2') format('woff2'), url('myfont.woff') format('woff'), url('myfont.ttf') format('truetype');\n", // rule.get(1).toString()); }
Example #8
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testClass() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_CLASS, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createClass("fit")); assertArrayEquals("Rule contains one class selector .fit", cslist.toArray(), rule .getSelectors()); assertEquals("Rule contains one declaration { width: 80%;}", DeclarationsUtil.appendDeclaration(null, "width", tf .createPercent(80.0f)), rule.asList()); }
Example #9
Source File: GradientTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testMultipleGradients() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_LINEAR_GRADIENT_MULTIPLE, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector div ", SelectorsUtil.createSelectors("div"), rule.getSelectors()); assertEquals("Rule contains one declaration for background ", "background", rule.get(0).getProperty()); assertEquals("Rule contains two terms ", 2, rule.get(0).size()); TermFunction func = (TermFunction) rule.get(0).get(0); List<List<Term<?>>> separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("First function name is linear-gradient ", "linear-gradient", func.getFunctionName()); assertEquals("First function has 2 comma-separated arguments ", 2, separatedArguments.size()); assertEquals("The first argument is red ", Arrays.asList(tf.createColor(tf.createIdent("red"))), separatedArguments.get(0)); assertEquals("The second argument is blue ", Arrays.asList(tf.createColor(tf.createIdent("blue"))), separatedArguments.get(1)); func = (TermFunction) rule.get(0).get(1); separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("Second function name is linear-gradient ", "linear-gradient", func.getFunctionName()); assertEquals("Second function has 3 comma-separated arguments ", 3, separatedArguments.size()); assertEquals("The first argument is to right ", Arrays.asList(tf.createIdent("to"), tf.createIdent("right")), separatedArguments.get(0)); assertEquals("The second argument is yellow ", Arrays.asList(tf.createColor(tf.createIdent("yellow"))), separatedArguments.get(1)); assertEquals("The third argument is green ", Arrays.asList(tf.createColor(tf.createIdent("green"))), separatedArguments.get(2)); }
Example #10
Source File: GradientTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testSampleGradients() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(SAMPLE_LINEAR_GRADIENT_1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule1 = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector div ", SelectorsUtil.createSelectors("div"), rule1.getSelectors()); assertEquals("Rule contains one declaration for background ", "background", rule1.get(0).getProperty()); assertEquals("Rule contains one term ", 1, rule1.get(0).size()); assertTrue("Rule contains a TermFunction ", rule1.get(0).get(0) instanceof TermFunction); TermFunction func = (TermFunction) rule1.get(0).get(0); assertEquals("Function name is linear-gradient ", "linear-gradient", func.getFunctionName()); List<List<Term<?>>> separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("There are 3 comma-separated arguments ", 3, separatedArguments.size()); assertEquals("The first argument is to bottom ", Arrays.asList(tf.createIdent("to"), tf.createIdent("bottom")), separatedArguments.get(0)); assertEquals("The first argument is pretty-printed as \"to bottom\" ", "linear-gradient(to bottom,", func.toString().substring(0, "linear-gradient(to bottom,".length())); assertEquals("The second argument is rgba(245,245,245,1) 0% ", Arrays.asList(tf.createColor(245, 245, 245, 255), tf.createPercent(0f)), separatedArguments.get(1)); assertEquals("The second argument is rgba(221,221,221,1) 100% ", Arrays.asList(tf.createColor(221, 221, 221, 255), tf.createPercent(100f)), separatedArguments.get(2)); }
Example #11
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: #00aa85;}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(192, 64, 32)), rule.asList()); }
Example #12
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBFunction2() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION2, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: rgb(50%,40%,30%);}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(127, 102, 76)), rule.asList()); }
Example #13
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHSLFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HSLFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration with color", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(0, 255, 0)), rule.asList()); }
Example #14
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void pseudoClassDirectNonStatic() throws SAXException, IOException { DOMSource ds = new DOMSource(getClass().getResourceAsStream("/simple/pseudo.html")); Document doc = ds.parse(); ElementMap elements = new ElementMap(doc); MatchConditionOnElements cond = new MatchConditionOnElements("a", PseudoClassType.LINK); cond.addMatch(elements.getElementById("l2"), PseudoClassType.HOVER); cond.addMatch(elements.getElementById("l3"), PseudoClassType.VISITED); StyleSheet style = CSSFactory.getUsedStyles(doc, null, createBaseFromFilename("data/simple/selectors.html"),"screen"); DirectAnalyzer da = new DirectAnalyzer(style); da.registerMatchCondition(cond); NodeData l1 = getStyleById(elements, da, "l1"); NodeData l2 = getStyleById(elements, da, "l2"); NodeData l3 = getStyleById(elements, da, "l3"); assertThat(l1.getValue(TermColor.class, "color"), is(tf.createColor(0,255,0))); assertThat(l2.getValue(TermColor.class, "color"), is(tf.createColor(0,255,255))); assertThat(l3.getValue(TermColor.class, "color"), is(tf.createColor(0,0,170))); }
Example #15
Source File: ImportTest1.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
private void checkDataCSS(StyleSheet ss) { Analyzer analyzer = new Analyzer(ss); StyleMap decl = analyzer.evaluateDOM(doc, "all", true); ElementMap elements = new ElementMap(doc); Element marginator = elements.getElementById("marginator"); assertNotNull("Element marginator exists", marginator); NodeData data = decl.get(marginator); assertEquals( "<div id=\"marginator\"> contains margin with for same values", Margin.length, data.getProperty("margin-top")); assertEquals( "<div id=\"marginator\"> contains margin with for same values", Margin.length, data.getProperty("margin-bottom")); assertEquals("Margin of 100px", new Float(100.0f), data.getValue( TermLength.class, "margin-top").getValue()); assertEquals("Margin of 100px", TermNumeric.Unit.px, data.getValue( TermLength.class, "margin-top").getUnit()); assertEquals("for all for both values", data.getValue(TermLength.class, "margin-bottom"), data .getValue(TermLength.class, "margin-left")); }
Example #16
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPseudo() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PSEUDO, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf.createPseudoClass("hover")); assertArrayEquals("Rule contains one pseudoselector :hover", cslist.toArray(), rule .getSelectors()); assertEquals( "Rule contains one declaration { text-decoration: underline; }", DeclarationsUtil.appendDeclaration(null, "text-decoration", tf .createIdent("underline")), rule.asList()); }
Example #17
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void nonlegacyPseudoElementSupport() throws CSSException, IOException { StyleSheet style = CSSFactory.parseString(TEST_PSEUDO_2, null); assertEquals("There are 4 rules", 4, style.size()); List<CombinedSelector> sel1 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-line")); List<CombinedSelector> sel2 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-letter")); List<CombinedSelector> sel3 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("before")); List<CombinedSelector> sel4 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("after")); RuleSet rule1 = (RuleSet) style.get(0); assertArrayEquals("Rule contains one selector p::first-line", sel1.toArray(), rule1.getSelectors()); assertEquals("Rule contains one declaration", 1, rule1.size()); RuleSet rule2 = (RuleSet) style.get(1); assertArrayEquals("Rule contains one selector p::first-letter", sel2.toArray(), rule2.getSelectors()); assertEquals("Rule contains one declaration", 1, rule2.size()); RuleSet rule3 = (RuleSet) style.get(2); assertArrayEquals("Rule contains one selector p::before", sel3.toArray(), rule3.getSelectors()); assertEquals("Rule contains one declaration", 1, rule3.size()); RuleSet rule4 = (RuleSet) style.get(3); assertArrayEquals("Rule contains one selector p::after", sel4.toArray(), rule4.getSelectors()); assertEquals("Rule contains one declaration", 1, rule4.size()); }
Example #18
Source File: FunctionsTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void rectFunctions() throws IOException, CSSException { StyleSheet ss1 = CSSFactory.parseString(TEST_RECT1, null); assertEquals("Two properties are accepted", 2, ss1.get(0).size()); Declaration d1 = (Declaration) ss1.get(0).get(0); TermRect r1 = (TermRect) d1.get(0); assertEquals("The last one is a correct length", tf.createLength(2f, Unit.ch), r1.getValue().get(3)); StyleSheet ss2 = CSSFactory.parseString(TEST_RECT2, null); assertEquals("Two properties are accepted", 2, ss2.get(0).size()); Declaration d2 = (Declaration) ss2.get(0).get(0); TermRect r2 = (TermRect) d2.get(0); assertEquals("The last one is a correct length", tf.createLength(2f, Unit.ch), r2.getValue().get(3)); StyleSheet ss3 = CSSFactory.parseString(TEST_RECT3, null); assertEquals("Two properties are accepted", 2, ss3.get(0).size()); Declaration d3 = (Declaration) ss3.get(0).get(0); TermRect r3 = (TermRect) d3.get(0); assertEquals("The last one is a correct length", null, r3.getValue().get(3)); }
Example #19
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAttribute() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ATTRIB, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "A", null, rf .createAttribute("fit.vutbr.cz", true, Selector.Operator.EQUALS, "href"), rf.createAttribute( "fit", false, Selector.Operator.DASHMATCH, "id")); assertArrayEquals( "Rule contains one ID attributed selector A[href='fit.vutbr.cz'][id|=fit]", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration { text-align: left; }", DeclarationsUtil.appendDeclaration(null, "text-align", tf .createIdent("left")), rule.asList()); }
Example #20
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHashColor2() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HASH_COLOR2, null); assertEquals("One rule is set", 1, ss.size()); final RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains two selectors DIV, P", SelectorsUtil.createSelectors("DIV", "P"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: #CCC;}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(204,204,204)), rule.asList()); }
Example #21
Source File: FontFaceTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testFFMultiSrc() throws IOException, CSSException { log.info("input:\n\n\n" + TEST_STRING2 + "\n\n\n"); StyleSheet ss; ss = CSSFactory.parseString(TEST_STRING2, null); assertEquals("One rule is set", 1, ss.size()); RuleFontFace rule = (RuleFontFace) ss.get(0); assertEquals("Rule contains 2 declarations ", 2, rule.size()); assertEquals("Rule contains font-family declaration", "font-family: 'MyWebFont';\n", rule.get(0).toString()); assertEquals("Rule contains scr declaration", "src: url('myfont.woff2') format('woff2'), url('myfont.woff') format('woff'), url('myfont.ttf') format('truetype');\n", rule.get(1).toString()); }
Example #22
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testID() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ID, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createID("krysa")); assertArrayEquals("Rule contains one ID selector #krysa", cslist.toArray(), rule .getSelectors()); assertEquals("Rule contains one declaration { font-size: 100px;}", DeclarationsUtil.appendDeclaration(null, "font-size", tf .createLength(100.0f).setUnit(TermNumeric.Unit.px)), rule.asList()); }
Example #23
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBAFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBAFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration with color", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(255, 0, 0, 51)), rule.asList()); }
Example #24
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPreceding() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PRECEDING, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "DIV", null); SelectorsUtil.appendPreceding(cslist, "P"); assertArrayEquals("Rule contains one combined selectors DIV~P ", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration {color:blue;}", DeclarationsUtil.appendDeclaration(null, "color", tf .createColor(0, 0, 255)), rule.asList()); }
Example #25
Source File: FunctionsTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void vendorSpecificUnderscore() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_DECL1A, null); assertEquals("Two properties are accepted", 2, ss.get(0).size()); final RuleSet rule = (RuleSet) ss.get(0); assertEquals("The first property value has three terms", 3, rule.get(0).size()); }
Example #26
Source File: FunctionsTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void vendorSpecificFunctions() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_DECL2A, null); assertEquals("Two properties are accepted", 2, ss.get(0).size()); Declaration d = (Declaration) ss.get(0).get(0); TermFunction f = (TermFunction) d.get(0); char first = f.getFunctionName().charAt(0); assertEquals("Function name starts with minus", '-', first); }
Example #27
Source File: GrammarRecovery2Test.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void invalidDirective() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_DECL5A, null); assertEquals("One property is accepted (second one is invalid)", 1, ss.get(0).size()); ss = CSSFactory.parseString(TEST_DECL5B, null); assertEquals("One property is accepted (first one is invalid)", 1, ss.get(0).size()); }
Example #28
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testInvalidPseudoSelector2() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_INVALID_PSEUDO_SELECTOR2, null); assertEquals("Two rules are set", 2, ss.size()); RuleSet rule1 = (RuleSet) ss.get(0); assertEquals("Rule contains one selector ::selection ", "[::selection]", Arrays.toString(rule1.getSelectors())); assertEquals("Rule contains one declaration {background: red}", DeclarationsUtil.appendDeclaration(null, "background", tf.createColor(255, 0, 0)), rule1.asList()); RuleSet rule2 = (RuleSet) ss.get(1); assertArrayEquals("Rule contains one selector p ", SelectorsUtil.createSelectors("p"), rule2.getSelectors()); assertEquals("Rule contains one declaration {background: green}", DeclarationsUtil.appendDeclaration(null, "background", tf.createColor(0, 128, 0)), rule2.asList()); }
Example #29
Source File: EscapingTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testAttributes() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_STRING13, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertEquals("One combined selector", rule.getSelectors().length, 1); CombinedSelector cs = rule.getSelectors()[0]; assertEquals("One selector", cs.size(), 1); ElementAttribute attr = (ElementAttribute) cs.get(0).get(1); assertEquals("The attribute value", "text/plain", attr.getValue()); }
Example #30
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testURI1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_URI1, null); assertEquals("There is one rule", 1, ss.size()); Declaration dec = (Declaration) ss.get(0).get(0); assertEquals("There is one declaration", 1, ss.get(0).size()); Object term = dec.get(0); assertTrue("Term value is URI", term instanceof TermURI); TermURI uri = (TermURI) term; assertEquals("URI has proper value", "image.jpg", uri.getValue()); }