1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package org.zwobble.mammoth.tests.xml;
import org.junit.Test;
import org.zwobble.mammoth.xml.XmlElement;
import org.zwobble.mammoth.xml.XmlParser;
import org.zwobble.mammoth.xml.XmlTextNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class XmlParserTests {
@Test
public void canParseSelfClosingElement() {
assertThat(
XmlParser.parseString("<body/>"),
is(new XmlElement("body")));
assertThat(
XmlParser.parseString("<values/>"),
is(new XmlElement("values")));
}
@Test
public void canParseEmptyElementWithSeparateClosingTag() {
assertThat(
XmlParser.parseString("<body></body>"),
is(new XmlElement("body")));
}
@Test
public void canParseAttributesOfTag() {
assertThat(
XmlParser.parseString("<body name='bob'></body>"),
is(new XmlElement("body", ImmutableMap.of("name", "bob"))));
}
@Test
public void canParseElementWithDescendantElements() {
assertThat(
XmlParser.parseString("<body><a><b/></a><a/></body>"),
is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of(
new XmlElement("a", ImmutableMap.of(), ImmutableList.of(
new XmlElement("b")
)),
new XmlElement("a")
))));
}
@Test
public void canParseTextNodes() {
assertThat(
XmlParser.parseString("<body>Hello!</body>"),
is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of(
new XmlTextNode("Hello!")
))));
}
}
|