-
Notifications
You must be signed in to change notification settings - Fork 64
/
XmlTest.cs
86 lines (67 loc) · 2.22 KB
/
XmlTest.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using Pidgin.Examples.Xml;
using Xunit;
using Attribute = Pidgin.Examples.Xml.Attribute;
namespace Pidgin.Tests;
public class XmlTest
{
[Fact]
public void TestParseSelfClosingTagWithoutAttributes()
{
{
var input = "<foo/>";
var expected = new Tag("foo", Array.Empty<Attribute>(), null);
var result = XmlParser.Parse(input);
Assert.True(result.Success);
Assert.Equal(expected, result.Value);
}
}
[Fact]
public void TestParseSelfClosingTagWithAttributes()
{
{
var input = "<foo bar=\"baz\" wibble=\"wobble\"/>";
var expected = new Tag("foo", new[] { new Attribute("bar", "baz"), new Attribute("wibble", "wobble") }, null);
var result = XmlParser.Parse(input);
Assert.True(result.Success);
Assert.NotNull(result.Value);
Assert.Equal(expected, result.Value);
}
}
[Fact]
public void TestParseTagWithNoContentAndNoAttributes()
{
{
var input = "<foo> </foo>";
var expected = new Tag("foo", Array.Empty<Attribute>(), Array.Empty<Tag>());
var result = XmlParser.Parse(input);
Assert.True(result.Success);
Assert.NotNull(result.Value);
Assert.Equal(expected, result.Value);
}
}
[Fact]
public void TestParseTagWithContentAndAttributes()
{
{
var input = "<foo bar=\"baz\" wibble=\"wobble\"><bar></bar><baz/></foo>";
var expected = new Tag(
"foo",
new[] { new Attribute("bar", "baz"), new Attribute("wibble", "wobble") },
new[] { new Tag("bar", Array.Empty<Attribute>(), Array.Empty<Tag>()), new Tag("baz", Array.Empty<Attribute>(), null) });
var result = XmlParser.Parse(input);
Assert.True(result.Success);
Assert.NotNull(result.Value);
Assert.Equal(expected, result.Value);
}
}
[Fact]
public void TestParseMismatchingTags()
{
{
var input = "<foo></bar>";
var result = XmlParser.Parse(input);
Assert.False(result.Success);
}
}
}