?? attributetests.java
字號:
// HTMLParser Library $Name: v1_6 $ - A java-based parser for HTML// http://sourceforge.org/projects/htmlparser// Copyright (C) 2004 Derrick Oswald//// Revision Control Information//// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v $// $Author: derrickoswald $// $Date: 2004/07/18 21:31:22 $// $Revision: 1.19 $//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//package org.htmlparser.tests.lexerTests;import java.util.Vector;import org.htmlparser.Node;import org.htmlparser.Attribute;import org.htmlparser.PrototypicalNodeFactory;import org.htmlparser.Tag;import org.htmlparser.lexer.PageAttribute;import org.htmlparser.nodes.TagNode;import org.htmlparser.tags.ImageTag;import org.htmlparser.tags.LinkTag;import org.htmlparser.tests.ParserTestCase;import org.htmlparser.util.NodeIterator;import org.htmlparser.util.ParserException;public class AttributeTests extends ParserTestCase{ static { System.setProperty ("org.htmlparser.tests.lexerTests.AttributeTests", "AttributeTests"); } private static final boolean JSP_TESTS_ENABLED = false; private Tag tag; private Vector attributes; public AttributeTests (String name) { super(name); } public void getParameterTableFor(String tagContents) { getParameterTableFor (tagContents, false); } public void getParameterTableFor(String tagContents, boolean dump) { String html; NodeIterator iterator; Node node; html = "<" + tagContents + ">"; createParser (html); parser.setNodeFactory (new PrototypicalNodeFactory (true)); try { iterator = parser.elements (); node = iterator.nextNode (); if (node instanceof Tag) { tag = (Tag)node; attributes = tag.getAttributesEx (); if (dump) { for (int i = 0; i < attributes.size (); i++) { System.out.print ("Attribute #" + i); Attribute attribute = (Attribute)attributes.elementAt (i); if (null != attribute.getName ()) System.out.print (" Name: '" + attribute.getName () + "'"); if (null != attribute.getAssignment ()) System.out.print (" Assignment: '" + attribute.getAssignment () + "'"); if (0 != attribute.getQuote ()) System.out.print (" Quote: " + attribute.getQuote ()); if (null != attribute.getValue ()) System.out.print (" Value: '" + attribute.getValue () + "'"); System.out.println (); } System.out.println (); } } else attributes = null; String string = node.toHtml (); assertEquals ("toHtml differs", html, string); assertTrue ("shouldn't be any more nodes", !iterator.hasMoreNodes ()); } catch (ParserException pe) { fail (pe.getMessage ()); } } /** * Test constructors. */ public void testConstructors () { Vector attributes; Tag tag; String html; attributes = new Vector (); // String, null attributes.add (new Attribute ("wombat", null)); // String attributes.add (new Attribute (" ")); // String, String attributes.add (new Attribute ("label", "The civil war.")); attributes.add (new Attribute (" ")); // String, String, String attributes.add (new Attribute ("frameborder", "= ", "no")); attributes.add (new Attribute (" ")); // String String, String, char attributes.add (new Attribute ("name", "=", "topFrame", '"')); tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); } /** * Test bean properties. */ public void testProperties () { Attribute attribute; Attribute space; Vector attributes; Tag tag; String html; attributes = new Vector (); attribute = new Attribute (); attribute.setName ("wombat"); assertTrue ("should be standalone", attribute.isStandAlone ()); assertTrue ("should not be whitespace", !attribute.isWhitespace ()); assertTrue ("should not be valued", !attribute.isValued ()); assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); space = new Attribute (); space.setValue (" "); assertTrue ("should not be standalone", !space.isStandAlone ()); assertTrue ("should be whitespace", space.isWhitespace ()); assertTrue ("should be valued", space.isValued ()); assertTrue ("should not be empty", !space.isEmpty ()); attributes.add (space); attribute = new Attribute (); attribute.setName ("label"); attribute.setAssignment ("="); attribute.setRawValue ("The civil war."); 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 Attribute (); attribute.setName ("frameborder"); attribute.setAssignment ("= "); attribute.setRawValue ("no"); attributes.add (attribute); attributes.add (space); attribute = new Attribute (); 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 constructors. */ public void testConstructors2 () { Vector attributes; Tag tag; String html; attributes = new Vector (); // String, null attributes.add (new PageAttribute ("wombat", null)); // String attributes.add (new PageAttribute (" ")); // String, String attributes.add (new PageAttribute ("label", "The civil war.")); attributes.add (new PageAttribute (" ")); // String, String, String attributes.add (new PageAttribute ("frameborder", "= ", "no")); attributes.add (new PageAttribute (" ")); // String String, String, char attributes.add (new PageAttribute ("name", "=", "topFrame", '"')); tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); } /** * Test bean properties. */ public void testProperties2 () { Attribute attribute; Attribute space; Vector attributes; Tag tag; String html; attributes = new Vector (); attribute = new PageAttribute (); attribute.setName ("wombat"); assertTrue ("should be standalone", attribute.isStandAlone ()); assertTrue ("should not be whitespace", !attribute.isWhitespace ()); assertTrue ("should not be valued", !attribute.isValued ()); assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); space = new PageAttribute (); space.setValue (" "); assertTrue ("should not be standalone", !space.isStandAlone ()); assertTrue ("should be whitespace", space.isWhitespace ()); assertTrue ("should be valued", space.isValued ()); assertTrue ("should not be empty", !space.isEmpty ()); attributes.add (space); attribute = new PageAttribute (); attribute.setName ("label"); attribute.setAssignment ("="); attribute.setRawValue ("The civil war."); 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 ("frameborder"); attribute.setAssignment ("= ");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -