-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.zig
180 lines (171 loc) · 10.6 KB
/
test.zig
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const std = @import("std");
const string = []const u8;
const xml = @import("xml");
const expect = std.testing.expect;
// zig fmt: off
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/001.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/002.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/003.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/004.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/005.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/006.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/007.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/008.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/009.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/010.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/011.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/012.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/013.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/014.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/015.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/016.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/017.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/018.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/019.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/020.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/021.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/022.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/023.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/024.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/025.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/026.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/027.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/028.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/029.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/030.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/031.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/032.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/033.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/034.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/035.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/036.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/037.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/038.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/039.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/040.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/041.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/042.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/043.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/044.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/045.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/046.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/047.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/048.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/049.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/050.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/051.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/052.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/053.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/054.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/055.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/056.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/057.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/058.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/059.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/060.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/061.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/062.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/063.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/064.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/065.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/066.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/067.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/068.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/069.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/070.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/071.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/072.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/073.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/074.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/075.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/076.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/077.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/078.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/079.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/080.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/081.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/082.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/083.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/084.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/085.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/086.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/087.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/088.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/089.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/090.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/091.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/092.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/093.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/094.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/095.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/096.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/097.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/098.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/099.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/100.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/101.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/102.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/103.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/104.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/105.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/106.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/107.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/108.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/109.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/110.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/111.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/112.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/113.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/114.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/115.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/116.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/117.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/118.xml"); }
test { try doValid("xml-test-suite/xmlconf/xmltest/valid/sa/119.xml"); }
// zig fmt: on
fn doValid(testfile_path: string) !void {
var testfile_file = try std.fs.cwd().openFile(testfile_path, .{});
defer testfile_file.close();
var doc = try xml.parse(std.testing.allocator, testfile_path, testfile_file.reader());
defer doc.deinit();
}
test {
const input =
\\<?xml version="1.0" standalone="yes" ?>
\\<category name="Technology">
\\ <book title="Learning Amazon Web Services" author="Mark Wilkins">
\\ <price>$20</price>
\\ </book>
\\ <book title="The Hunger Games" author="Suzanne Collins">
\\ <price>$13</price>
\\ </book>
\\ <book title="The Lightning Thief: Percy Jackson and the Olympians" author="Rick Riordan"></book>
\\</category>
;
var fbs = std.io.fixedBufferStream(input);
var doc = try xml.parse(std.testing.allocator, "<stdin>", fbs.reader());
defer doc.deinit();
doc.acquire();
defer doc.release();
try expectEqualStrings(doc.root.tag_name.slice(), "category");
const children = doc.root.children();
try expect(children.len == 3);
try expect(children[0].v() == .element);
try expect(children[1].v() == .element);
try expect(children[2].v() == .element);
const child1 = children[1].v().element;
try expectEqualStrings(child1.tag_name.slice(), "book");
try expectEqualStrings(child1.attr("title").?, "The Hunger Games");
const children2 = child1.children();
try expect(children2.len == 1);
try expect(children2[0].v() == .element);
const child2 = children2[0].v().element;
try expectEqualStrings(child2.tag_name.slice(), "price");
const children3 = child2.children();
try expect(children3.len == 1);
try expect(children3[0].v() == .text);
try expectEqualStrings(children3[0].v().text.slice(), "$13");
}
fn expectEqualStrings(actual: []const u8, expected: []const u8) !void {
try std.testing.expectEqualStrings(expected, actual);
}