⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attributetests.java

📁 html to xml convertor
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        attribute.setRawValue ("no");        assertTrue ("should not be standalone", !attribute.isStandAlone ());        assertTrue ("should not be whitespace", !attribute.isWhitespace ());        assertTrue ("should be valued", attribute.isValued ());        assertTrue ("should not be empty", !attribute.isEmpty ());         attributes.add (attribute);        attributes.add (space);        attribute = new PageAttribute ();        attribute.setName ("name");        attribute.setAssignment ("=");        attribute.setValue ("topFrame");        attribute.setQuote ('"');        assertTrue ("should not be standalone", !attribute.isStandAlone ());        assertTrue ("should not be whitespace", !attribute.isWhitespace ());        assertTrue ("should be valued", attribute.isValued ());        assertTrue ("should not be empty", !attribute.isEmpty ());         attributes.add (attribute);        tag = new TagNode (null, 0, 0, attributes);        html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">";        assertStringEquals ("tag contents", html, tag.toHtml ());    }    /**     * Test simple value.     */    public void testParseParameters() {        getParameterTableFor("a b = \"c\"");        assertEquals("Value","c",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test quote value.     */    public void testParseTokenValues() {        getParameterTableFor("a b = \"'\"");        assertEquals("Value","'",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test empty value.     */    public void testParseEmptyValues() {        getParameterTableFor("a b = \"\"");        assertEquals("Value","",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test no equals or whitespace.     * This might be reason for another rule, since another interpretation     * would have an attribute called B with a value of "C".     */    public void testParseMissingEqual() {        getParameterTableFor("a b\"c\"");        assertEquals("NameC", "b\"c\"", ((Attribute)(attributes.elementAt (2))).getName ());    }    /**     * Test multiple attributes.     */    public void testTwoParams(){        getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\"");        assertEquals("Param1","Param1",((Attribute)(attributes.elementAt (2))).getValue ());        assertEquals("Somik","Somik",((Attribute)(attributes.elementAt (4))).getValue ());    }    /**     * Test unquoted attributes.     */    public void testPlainParams(){        getParameterTableFor("PARAM NAME=Param1 VALUE=Somik");        assertEquals("Param1","Param1",((Attribute)(attributes.elementAt (2))).getValue ());        assertEquals("Somik","Somik",((Attribute)(attributes.elementAt (4))).getValue ());    }    /**     * Test standalone attribute.     */    public void testValueMissing() {        getParameterTableFor("INPUT type=\"checkbox\" name=\"Authorize\" value=\"Y\" checked");        assertEquals("Name of Tag","INPUT",((Attribute)(attributes.elementAt (0))).getName ());        assertEquals("Type","checkbox",((Attribute)(attributes.elementAt (2))).getValue ());        assertEquals("Name","Authorize",((Attribute)(attributes.elementAt (4))).getValue ());        assertEquals("Value","Y",((Attribute)(attributes.elementAt (6))).getValue ());        assertEquals("Checked",null,((Attribute)(attributes.elementAt (8))).getValue ());    }    /**     * This is a simulation of a bug reported by Dhaval Udani - wherein     * a space before the end of the tag causes a problem - there is a key     * in the table with just a space in it and an empty value     */    public void testIncorrectSpaceKeyBug() {        getParameterTableFor("TEXTAREA name=\"Remarks\" ");        // There should only be two keys..        assertEquals("There should only be two attributes",4,attributes.size());        // The first key is name        assertEquals("Expected name","TEXTAREA",((Attribute)(attributes.elementAt (0))).getName ());        assertEquals("Expected value 1", "Remarks",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test empty attribute.     */    public void testNullTag(){        getParameterTableFor("INPUT type=");        assertEquals("Name of Tag","INPUT",((Attribute)(attributes.elementAt (0))).getName ());        assertNull("Type",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test attribute containing an equals sign.     */    public void testAttributeWithSpuriousEqualTo() {        getParameterTableFor(            "a class=rlbA href=/news/866201.asp?0sl=-32"        );        assertStringEquals(            "href",            "/news/866201.asp?0sl=-32",            ((Attribute)(attributes.elementAt (4))).getValue ()        );    }    /**     * Test attribute containing a question mark.     */    public void testQuestionMarksInAttributes() {        getParameterTableFor(            "a href=\"mailto:sam@neurogrid.com?subject=Site Comments\""        );        assertStringEquals(            "href",            "mailto:sam@neurogrid.com?subject=Site Comments",            ((Attribute)(attributes.elementAt (2))).getValue ()        );        assertStringEquals(            "tag name",            "a",            ((Attribute)(attributes.elementAt (0))).getName ()        );    }    /**     * Check that an empty tag is considered a string node.     * Believe it or not Moi (vincent_aumont) wants htmlparser to parse a text file     * containing something that looks nearly like a tag:     * <pre>     * "basic_string&lt;char, string_char_traits&lt;char&gt;, &lt;&gt;&gt;::basic_string()"     * </pre>     * This was throwing a null pointer exception when the empty &lt;&gt; was encountered.     * Bug #725420 NPE in StringBean.visitTag     **/    public void testEmptyTag () {        getParameterTableFor("");        assertNull ("<> is not a tag",attributes);    }    /**     * Test attributes when they contain scriptlets.     * Submitted by Cory Seefurth     * See also feature request #725376 Handle script in attributes.     */    public void testJspWithinAttributes() {        if (JSP_TESTS_ENABLED)        {            getParameterTableFor(                "a href=\"<%=Application(\"sURL\")%>/literature/index.htm"            );            assertStringEquals(                "href",                "<%=Application(\"sURL\")%>/literature/index.htm",                ((Attribute)(attributes.elementAt (2))).getValue ()            );        }    }    /**     * Test Script in attributes.     * See feature request #725376 Handle script in attributes.     */    public void testScriptedTag () {        getParameterTableFor("body onLoad=defaultStatus=''");        String name = ((Attribute)(attributes.elementAt (0))).getName ();        assertNotNull ("No Tag.TAGNAME", name);        assertStringEquals("tag name parsed incorrectly", "body", name);        String value = ((Attribute)(attributes.elementAt (2))).getValue ();        assertStringEquals ("parameter parsed incorrectly", "defaultStatus=''", value);    }    /**     * Test that stand-alone attributes are kept that way, rather than being     * given empty values.     * -Joe Robins, 6/19/03     */    public void testStandaloneAttribute ()    {        getParameterTableFor ("INPUT DISABLED");        assertStringEquals("Standalone attribute not parsed","DISABLED",((Attribute)(attributes.elementAt (2))).getName ());        assertNull ("Standalone attribute has non-null value",((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test missing value.     */    public void testMissingAttribute ()    {        getParameterTableFor ("INPUT DISABLED=");        assertStringEquals("Empty attribute has no attribute","DISABLED",((Attribute)(attributes.elementAt (2))).getName ());        assertEquals ("Attribute has non-blank value",null,((Attribute)(attributes.elementAt (2))).getValue ());    }    /**     * Test Rule 1.     * See discussion in Bug#891058 Bug in lexer. regarding alternate interpretations.     */    public void testRule1 ()    {        getParameterTableFor ("tag att = other=fred");        assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ());        assertEquals ("Attribute has wrong value", "other=fred", ((Attribute)(attributes.elementAt (2))).getValue ());        for (int i = 0; i < attributes.size (); i++)            assertTrue ("No attribute should be called =", !((Attribute)(attributes.elementAt (2))).getName ().equals ("="));    }    /**     * Test Rule 2.     */    public void testRule2 ()    {        getParameterTableFor ("tag att =value other=fred");        assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ());        assertEquals ("Attribute has wrong value", "value", ((Attribute)(attributes.elementAt (2))).getValue ());        for (int i = 0; i < attributes.size (); i++)            assertTrue ("No attribute should be called =value", !((Attribute)(attributes.elementAt (2))).getName ().equals ("=value"));        assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (4))).getName ());        assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (4))).getValue ());    }    /**     * Test Rule 3.     */    public void testRule3 ()    {        getParameterTableFor ("tag att= \"value\" other=fred");        assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ());        assertEquals ("Attribute has wrong value", "value", ((Attribute)(attributes.elementAt (2))).getValue ());        for (int i = 0; i < attributes.size (); i++)            assertTrue ("No attribute should be called \"value\"", !((Attribute)(attributes.elementAt (2))).getName ().equals ("\"value\""));        assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (4))).getName ());        assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (4))).getValue ());    }    /**     * Test Rule 4.     * See discussion in Bug#891058 Bug in lexer. regarding alternate interpretations.     */    public void testRule4 ()    {        getParameterTableFor ("tag att=\"va\"lue\" other=fred");        assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -