-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlTests.fs
72 lines (61 loc) · 2 KB
/
XmlTests.fs
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
namespace PidginFsharp.Test
open PidginFsharp
open PidginFsharp.Examples
open System
open Xunit
module XmlTests =
open Basic
open Sequence
open XmlParser
[<Fact>]
let ``tag fails if tag names don't match`` () =
tag |> Util.fails "<foo>tagcontent</bar>" true
[<Fact>]
let ``tagClose matches a closer tag with the matching name`` () =
tagClose "foo"
|> Util.succeed "</foo>" "foo"
[<Fact>]
let ``tagClose fails if the name does not match`` () =
tagClose "bar"
|> Util.fails "</foo>" true
[<Fact>]
let ``tagOpen matches an opening tag`` () =
tagOpen |> Util.succeed "<foo>" ("foo", [])
[<Fact>]
let ``tagOpen fails if it's a closing tag`` () =
tagOpen |> Util.fails "</foo>" true
[<Fact>]
let ``tag can parse XML tag with string content`` () =
tag
|> Util.succeed
"<foo attr1=\"val1\" attr2=\"val2\">bar</foo>"
{
Name = "foo"
Attributes = [ XmlAttribute ("attr1", "val1"); XmlAttribute ("attr2", "val2") ]
Content = RawString "bar"
}
[<Fact>]
let ``tag can parse XML tag with empty content`` () =
tag |>
Util.succeed
"<foo></foo>"
{
Name = "foo"
Attributes = []
Content = Empty
}
[<Fact>]
let ``rawString fails with Consumed false for an xml tag`` () =
rawString |> Util.fails "</bar>" false
[<Fact>]
let ``tag can parse XML tag with inner xml`` () =
tag |>
Util.succeed
"<foo><bar attr1=\"val1\" attr2=\"val2\">baz</bar></foo>"
{
Name = "foo"
Attributes = []
Content = InnerXml [ { Name = "bar"
Attributes = [ XmlAttribute ("attr1", "val1"); XmlAttribute ("attr2", "val2") ]
Content = RawString "baz" } ]
}