Package com.volantis.styling.compiler

Examples of com.volantis.styling.compiler.Specificity


        calculator = new SpecificityCalculatorImpl();
    }

    public void testResetWorks() {

        Specificity expected = calculator.getSpecificity();
        calculator.addAttributeSelector();
        calculator.reset();
        Specificity actual = calculator.getSpecificity();

        assertEquals("Reset should clear specificity", expected, actual);
    }
View Full Code Here


     * Test that all the add methods actually increase the specificity.
     */
    public void testAddIncreasesSpecificity() {

        // Get the empty specificity.
        Specificity EMPTY = calculator.getSpecificity();
        Specificity after;

        calculator.reset();
        calculator.addAttributeSelector();
        after = calculator.getSpecificity();
        assertTrue("addAttributeSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addClassSelector();
        after = calculator.getSpecificity();
        assertTrue("addClassSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addElementSelector();
        after = calculator.getSpecificity();
        assertTrue("addElementSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addIDSelector();
        after = calculator.getSpecificity();
        assertTrue("addIDSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addPseudoClassSelector();
        after = calculator.getSpecificity();
        assertTrue("addPseudoClassSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addPseudoElementSelector();
        after = calculator.getSpecificity();
        assertTrue("addPseudoElementSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);
    }
View Full Code Here

        // Make sure that attribute, class and pseudo class selectors have
        // the same specificity.
        calculator.reset();
        calculator.addAttributeSelector();
        Specificity attributeSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addClassSelector();
        Specificity classSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addPseudoClassSelector();
        Specificity pseudoClassSpecificity = calculator.getSpecificity();

        assertEquals("Attribute and class selectors have the same specificity",
                     attributeSpecificity, classSpecificity);
        assertEquals("Class and pseudo class selectors have the same specificity",
                     classSpecificity, pseudoClassSpecificity);

        // Make sure that element and pseudo element selectors have the same
        // specificity.
        calculator.reset();
        calculator.addElementSelector();
        Specificity elementSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addPseudoElementSelector();
        Specificity pseudoElementSpecificity = calculator.getSpecificity();

        assertEquals("Element and pseudo element selectors have the same specificity",
                     elementSpecificity, pseudoElementSpecificity);
    }
View Full Code Here

    public void testRelativeSpecificities() {

        // Calculate the specificity of a single class.
        calculator.reset();
        calculator.addClassSelector();
        Specificity singleClassSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a single id.
        calculator.reset();
        calculator.addIDSelector();
        Specificity singleIDSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a large number of element selectors.
        calculator.reset();
        for (int i = 0; i < MAX_SELECTORS_PER_TYPE; i += 1) {
            calculator.addElementSelector();
        }
        Specificity manyElementSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a large number of class selectors.
        calculator.reset();
        for (int i = 0; i < MAX_SELECTORS_PER_TYPE; i += 1) {
            calculator.addClassSelector();
        }
        Specificity manyClassSpecificity = calculator.getSpecificity();

        assertTrue("Class selector (" + singleClassSpecificity +
                   ") should have higher specificity than " +
                   "many element selectors (" + manyElementSpecificity + ")",
                   singleClassSpecificity.compareTo(manyElementSpecificity) > 0);
View Full Code Here

        calculator = new SpecificityCalculatorImpl();
    }

    public void testResetWorks() {

        Specificity expected = calculator.getSpecificity();
        calculator.addAttributeSelector();
        calculator.reset();
        Specificity actual = calculator.getSpecificity();

        assertEquals("Reset should clear specificity", expected, actual);
    }
View Full Code Here

     * Test that all the add methods actually increase the specificity.
     */
    public void testAddIncreasesSpecificity() {

        // Get the empty specificity.
        Specificity EMPTY = calculator.getSpecificity();
        Specificity after;

        calculator.reset();
        calculator.addAttributeSelector();
        after = calculator.getSpecificity();
        assertTrue("addAttributeSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addClassSelector();
        after = calculator.getSpecificity();
        assertTrue("addClassSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addElementSelector();
        after = calculator.getSpecificity();
        assertTrue("addElementSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addIDSelector();
        after = calculator.getSpecificity();
        assertTrue("addIDSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addPseudoClassSelector();
        after = calculator.getSpecificity();
        assertTrue("addPseudoClassSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);

        calculator.reset();
        calculator.addPseudoElementSelector();
        after = calculator.getSpecificity();
        assertTrue("addPseudoElementSelector should increase specificity.",
                   after.compareTo(EMPTY) > 0);
    }
View Full Code Here

        // Make sure that attribute, class and pseudo class selectors have
        // the same specificity.
        calculator.reset();
        calculator.addAttributeSelector();
        Specificity attributeSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addClassSelector();
        Specificity classSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addPseudoClassSelector();
        Specificity pseudoClassSpecificity = calculator.getSpecificity();

        assertEquals("Attribute and class selectors have the same specificity",
                     attributeSpecificity, classSpecificity);
        assertEquals("Class and pseudo class selectors have the same specificity",
                     classSpecificity, pseudoClassSpecificity);

        // Make sure that element and pseudo element selectors have the same
        // specificity.
        calculator.reset();
        calculator.addElementSelector();
        Specificity elementSpecificity = calculator.getSpecificity();

        calculator.reset();
        calculator.addPseudoElementSelector();
        Specificity pseudoElementSpecificity = calculator.getSpecificity();

        assertEquals("Element and pseudo element selectors have the same specificity",
                     elementSpecificity, pseudoElementSpecificity);
    }
View Full Code Here

    public void testRelativeSpecificities() {

        // Calculate the specificity of a single class.
        calculator.reset();
        calculator.addClassSelector();
        Specificity singleClassSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a single id.
        calculator.reset();
        calculator.addIDSelector();
        Specificity singleIDSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a large number of element selectors.
        calculator.reset();
        for (int i = 0; i < MAX_SELECTORS_PER_TYPE; i += 1) {
            calculator.addElementSelector();
        }
        Specificity manyElementSpecificity = calculator.getSpecificity();

        // Calculate the specificity of a large number of class selectors.
        calculator.reset();
        for (int i = 0; i < MAX_SELECTORS_PER_TYPE; i += 1) {
            calculator.addClassSelector();
        }
        Specificity manyClassSpecificity = calculator.getSpecificity();

        assertTrue("Class selector (" + singleClassSpecificity +
                   ") should have higher specificity than " +
                   "many element selectors (" + manyElementSpecificity + ")",
                   singleClassSpecificity.compareTo(manyElementSpecificity) > 0);
View Full Code Here

    /**
     * Test the specificity value is equal initially and after a reset
     */
    public void testInitialSetupAndReset() {
        Specificity initial = calculator.getSpecificity();

        calculator.addAttributeSelector();
        calculator.reset();

        Specificity after = calculator.getSpecificity();

        assertEquals("The initial specificity should be equal to the " +
                "reset specificity", initial, after);
    }
View Full Code Here

        int result = priority1.compareTo(priority2);
        if (result != 0) {
            return result;
        }

        Specificity specificity1 = styler1.getSpecificity();
        Specificity specificity2 = styler2.getSpecificity();
        return specificity1.compareTo(specificity2);
    }
View Full Code Here

TOP

Related Classes of com.volantis.styling.compiler.Specificity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.