Java Code Examples for cz.vutbr.web.css.StyleSheet#get()

The following examples show how to use cz.vutbr.web.css.StyleSheet#get() . 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: PseudoClassTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 2
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 3
Source File: FontFaceTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 4
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 5
Source File: KeyframesTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testSimpleKeyframes() throws IOException, CSSException {
    log.info("input:\n\n\n" + TEST_STRING1 + "\n\n\n");
    StyleSheet ss;

    ss = CSSFactory.parseString(TEST_STRING1, null);

    assertEquals("Two rules are present", 2, ss.size());

    RuleKeyframes rule = (RuleKeyframes) ss.get(0);
    assertEquals("Keyframes name is correct ", "test_anim", rule.getName());
    assertEquals("Rule contains 5 keyframes ", 5, rule.size());
    assertEquals("Selector is correct ", tf.createPercent(0.0f), rule.get(0).getPercentages().get(0));
    assertEquals("Selector is correct ", tf.createPercent(50.0f), rule.get(1).getPercentages().get(0));
    assertEquals("Selector is correct ", tf.createPercent(50.0f), rule.get(2).getPercentages().get(0));
    assertEquals("Selector is correct ", tf.createPercent(60.0f), rule.get(3).getPercentages().get(0));
    assertEquals("Selector is correct ", tf.createPercent(72.0f), rule.get(3).getPercentages().get(1));
    assertEquals("Selector is correct ", tf.createPercent(100.0f), rule.get(4).getPercentages().get(0));
    assertEquals("Second keyframe has two declarations ", 2, rule.get(1).size());
}
 
Example 6
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 7
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 8
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 9
Source File: PseudoClassTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void rangeInputPseudoElements() throws CSSException, IOException {
    StyleSheet style = CSSFactory.parseString(TEST_RANGE, null);
    assertEquals("There are 6 rules", 6, style.size());
    
    for (int i = 0; i < TEST_RANGE_ELEMENTS.length; i++) {
        List<CombinedSelector> cslist = SelectorsUtil.appendSimpleSelector(null, 
            "input", 
            null, 
            rf.createAttribute("range", false, Selector.Operator.EQUALS, "type"), 
            rf.createPseudoElement(TEST_RANGE_ELEMENTS[i]));

        RuleSet rule = (RuleSet) style.get(i);
        assertArrayEquals("Rule contains one selector input[type=range]::" + TEST_RANGE_ELEMENTS[i], cslist.toArray(), rule.getSelectors());
        assertEquals("Rule contains one declaration", 1, rule.size());
    }
}
 
Example 10
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test 
public void testRGBFunctionInvalid() throws IOException, CSSException   {
    
    StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION_INVALID, 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", 1, rule.size());
    Term<?> value = rule.get(0).get(0);
    assertTrue("Assigned value is TermFunction (not TermColor)", value instanceof TermFunction);
}
 
Example 11
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 12
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 13
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testEscapedID() throws CSSException, IOException {

    StyleSheet ss = CSSFactory.parseString(TEST_ESCAPED_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("1krysa"));

    assertArrayEquals("Rule contains one ID selector #1krysa", 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 14
Source File: GradientTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 15
Source File: EscapingTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testElementNames() throws IOException, CSSException   {
	
	StyleSheet ss;
	
	ss = CSSFactory.parseString(TEST_STRING1, null);
	assertEquals("One rule is set", 1, ss.size());
	RuleSet rule = (RuleSet) ss.get(0);				
	assertArrayEquals("Rule contains one selector em ", 
			SelectorsUtil.createSelectors("em"), 
			rule.getSelectors());
}
 
Example 16
Source File: EscapingTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void assertSingleId(String input, String className) throws IOException, CSSException
{
    StyleSheet ss = CSSFactory.parseString(input, 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);
    assertEquals("The class name is correct", className, cs.get(0).getIDName());
}
 
Example 17
Source File: FunctionsTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 18
Source File: SelectorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testMultiple() throws CSSException, IOException {
	StyleSheet ss = CSSFactory.parseString(TEST_MULTIPLE, null);

	assertEquals("One rule is set", 1, ss.size());

	RuleSet rule = (RuleSet) ss.get(0);

	assertArrayEquals("Rule contains two selectors H1, DIV  ", SelectorsUtil
			.createSelectors("H1", "DIV"), rule.getSelectors());

	assertEquals("Rule contains one declaration {display:block;}",
			DeclarationsUtil.appendDeclaration(null, "display", tf
					.createIdent("block")), rule.asList());
}
 
Example 19
Source File: ErrorTest.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test 
public void testString1() throws IOException, CSSException   {
    
    StyleSheet ss = CSSFactory.parseString(TEST_STRING1, 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", rule.size(), 1);
                        
}
 
Example 20
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testCharsets() throws IOException, CSSException   {
	
	StyleSheet ss;
	
	ss = CSSFactory.parseString(TEST_CHARSET_STRING1, null);
	
	assertEquals("No rules are defined", 0, ss.size());

	ss = CSSFactory.parseString(TEST_CHARSET_STRING2, 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: blue;}",
			DeclarationsUtil.appendDeclaration(null, "color", 
					tf.createColor(0,0,255)),
			rule.asList());	
}