// License: MPL-2.0
// (c) 2022 Chris Palmer <chris@red-oxide.org>
use bufio;
use encoding::utf8;
use fmt;
use io;
use strings;
@test fn simple() void = {
const buf = bufio::fixed(strings::toutf8(
`<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<title>Example Feed</title>
<updated>2003-12-13T18:30:02Z</updated>
<link href="http://example.org/"/>
<author>
<name>John Doe</name>
</author>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>`), io::mode::READ);
const f = scan(&buf)!;
defer finish(&f);
zcmp("Feed Extensions",
1z,
len(f.extensions));
scmp("Feed Updated",
"2003-12-13T18:30:02Z",
f.updated);
scmp("Feed ID",
"urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6",
f.id);
scmp("Feed Icon",
"",
f.icon);
scmp("Feed Logo",
"",
f.logo);
scmp("Feed Title Type",
"",
f.title.1);
scmp("Feed Title Value",
"Example Feed",
f.title.0);
zcmp("Feed Links",
1z,
len(f.links));
scmp("Feed Link 1 HREF",
"http://example.org/",
f.links[0].href);
scmp("Feed Link 1 HREF",
"",
f.links[0].rel);
scmp("Feed Link 1 Type",
"",
f.links[0].linktype);
scmp("Feed Link 1 Lang",
"",
f.links[0].hreflang);
scmp("Feed Link 1 Title",
"",
f.links[0].title);
scmp("Feed Link 1 Length",
"",
f.links[0].length);
zcmp("Feed Authors",
1z,
len(f.authors));
scmp("Feed Author 1 Name",
"John Doe",
f.authors[0].name);
scmp("Feed Author 1 URI",
"",
f.authors[0].uri);
scmp("Feed Author 1 Email",
"",
f.authors[0].email);
zcmp("Feed Author 1 Extensions",
0z,
len(f.authors[0].extensions));
zcmp("Feed Categories",
0z,
len(f.categories));
zcmp("Feed Contributors",
0z,
len(f.contributors));
scmp("Feed Subtitle type",
"",
f.subtitle.1);
scmp("Feed Subtitle value",
"",
f.subtitle.0);
scmp("Feed Rights type",
"",
f.rights.1);
scmp("Feed Rights value",
"",
f.rights.0);
scmp("Feed Generator Value",
"",
f.generator.0);
scmp("Feed Generator URI",
"",
f.generator.1);
scmp("Feed Generator Version",
"",
f.generator.2);
zcmp("Feed Entries",
1z,
len(f.entries));
zcmp("Entry 1 Extensions",
0z,
len(f.entries[0].extensions));
scmp("Entry 1 Updated",
"2003-12-13T18:30:02Z",
f.entries[0].updated);
scmp("Entry 1 ID",
"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
f.entries[0].id);
scmp("Entry 1 Published",
"",
f.entries[0].published);
scmp("Entry 1 Summary Type",
"",
f.entries[0].summary.1);
scmp("Entry 1 Summary Value",
"Some text.",
f.entries[0].summary.0);
scmp("Entry 1 Rights type",
"",
f.entries[0].rights.1);
scmp("Entry 1 Rights value",
"",
f.entries[0].rights.0);
scmp("Entry 1 Title Type",
"",
f.entries[0].title.1);
scmp("Entry 1 Title Value",
"Atom-Powered Robots Run Amok",
f.entries[0].title.0);
zcmp("Entry 1 Links",
1z,
len(f.entries[0].links));
scmp("Entry 1 Link 1 HREF",
"http://example.org/2003/12/13/atom03",
f.entries[0].links[0].href);
scmp("Entry 1 Link 1 HREF",
"",
f.entries[0].links[0].rel);
scmp("Entry 1 Link 1 Type",
"",
f.entries[0].links[0].linktype);
scmp("Entry 1 Link 1 Lang",
"",
f.entries[0].links[0].hreflang);
scmp("Entry 1 Link 1 Title",
"",
f.entries[0].links[0].title);
scmp("Entry 1 Link 1 Length",
"",
f.entries[0].links[0].length);
zcmp("Entry 1 Authors",
0z,
len(f.entries[0].authors));
zcmp("Entry 1 Contributors",
0z,
len(f.entries[0].contributors));
zcmp("Entry 1 Categories",
0z,
len(f.entries[0].categories));
};
@test fn more() void = {
const buf = bufio::fixed(strings::toutf8(
`<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<a:simple>test</a:simple>
<a:complex xlmns="a" type="ext">
<a:t a="b"/>
<a:name>test</a:name>
</a:complex>
<title type="text">dive into mark</title>
<subtitle type="text">A lot of effort went into making this effortless</subtitle>
<updated>2005-07-31T12:29:29Z</updated>
<id>tag:example.org,2003:3</id>
<link rel="alternate" type="text/html" hreflang="en" href="http://example.org/"/>
<link rel="self" type="application/atom+xml" href="http://example.org/feed.atom"/>
<icon>test.jpg</icon>
<logo>logo.jpg</logo>
<rights type="text">© 2005 John Doe</rights>
<generator uri="/myblog.php" version="1.0">Example Toolkit</generator>
<category term="sports"/>
<author>
<name>Mark Pilgrim</name>
<uri>http://example.org/</uri>
<email>f8dy@example.com</email>
<a:simple>test</a:simple>
<a:complex xlmns="a" type="ext">
<a:t a="b"/>
<a:name>test</a:name>
</a:complex>
</author>
<contributor>
<name>Mark Pilgrim</name>
<uri>http://example.org/</uri>
<email>f8dy@example.com</email>
</contributor>
<entry>
<a:simple>test</a:simple>
<a:complex xlmns="a" type="ext">
<a:t a="b"/>
<a:name>test</a:name>
</a:complex>
<title type="text">Atom draft-07 snapshot</title>
<link rel="alternate" type="text/html" href="http://example.org/2005/04/02/atom"/>
<link rel="enclosure" type="audio/mpeg" length="1337" href="http://example.org/audio/ph34r_my_podcast.mp3"/>
<id>tag:example.org,2003:3.2397</id>
<updated>2005-07-31T12:29:29Z</updated>
<published>2003-12-13T08:29:29-04:00</published>
<author>
<name>Mark Pilgrim</name>
<uri>http://example.org/</uri>
<email>f8dy@example.com</email>
</author>
<contributor>
<name>Sam Ruby</name>
</contributor>
<contributor>
<name>Joe Gregorio</name>
</contributor>
<content type="text">[Update: The Atom draft is finished.]</content>
<rights type="text">© 2005 Jane Doe</rights>
<category term="sports"/>
</entry>
</feed>`), io::mode::READ);
const f = scan(&buf)!;
defer finish(&f);
zcmp("Feed Extensions",
14z,
len(f.extensions));
scmp("Feed Updated",
"2005-07-31T12:29:29Z",
f.updated);
scmp("Feed ID",
"tag:example.org,2003:3",
f.id);
scmp("Feed Icon",
"test.jpg",
f.icon);
scmp("Feed Logo",
"logo.jpg",
f.logo);
zcmp("Feed Links",
2z,
len(f.links));
scmp("Feed Link 1 HREF",
"http://example.org/",
f.links[0].href);
scmp("Feed Link 1 Rel",
"alternate",
f.links[0].rel);
scmp("Feed Link 1 Type",
"text/html",
f.links[0].linktype);
scmp("Feed Link 1 Lang",
"en",
f.links[0].hreflang);
scmp("Feed Link 1 Title",
"",
f.links[0].title);
scmp("Feed Link 1 Length",
"",
f.links[0].length);
scmp("Feed Link 2 HREF",
"http://example.org/feed.atom",
f.links[1].href);
scmp("Feed Link 2 Rel",
"self",
f.links[1].rel);
scmp("Feed Link 2 Type",
"application/atom+xml",
f.links[1].linktype);
scmp("Feed Link 2 Lang",
"",
f.links[1].hreflang);
scmp("Feed Link 2 Title",
"",
f.links[1].title);
scmp("Feed Link 2 Length",
"",
f.links[1].length);
scmp("Feed Title Type",
"text",
f.title.1);
scmp("Feed Title Value",
"dive into mark",
f.title.0);
scmp("Feed Subtitle Type",
"text",
f.subtitle.1);
scmp("Feed Subtitle Value",
"A lot of effort went into making this effortless",
f.subtitle.0);
scmp("Feed Rights Type",
"text",
f.rights.1);
scmp("Feed Rights Value",
"© 2005 John Doe",
f.rights.0);
zcmp("Feed Authors",
1z,
len(f.authors));
scmp("Feed Author 1 Name",
"Mark Pilgrim",
f.authors[0].name);
scmp("Feed Author 1 URI",
"http://example.org/",
f.authors[0].uri);
scmp("Feed Author 1 Email",
"f8dy@example.com",
f.authors[0].email);
zcmp("Feed Author 1 Extensions",
13z,
len(f.authors[0].extensions));
zcmp("Feed Contibutors",
1z,
len(f.contributors));
scmp("Feed Contibutor 1 Name",
"Mark Pilgrim",
f.contributors[0].name);
scmp("Feed Contibutor 1 URI",
"http://example.org/",
f.contributors[0].uri);
scmp("Feed Contributor 1 Email",
"f8dy@example.com",
f.contributors[0].email);
zcmp("Feed Contributor 1 Extensions",
0z,
len(f.contributors[0].extensions));
scmp("Feed Generator Value",
"Example Toolkit",
f.generator.0);
scmp("Feed Generator URI",
"/myblog.php",
f.generator.1);
scmp("Feed Generator Version",
"1.0",
f.generator.2);
zcmp("Feed Categories",
1z,
len(f.categories));
zcmp("Feed Entries",
1z,
len(f.entries));
zcmp("Entry 1 Extensions",
13z,
len(f.entries[0].extensions));
scmp("Entry 1 Updated",
"2005-07-31T12:29:29Z",
f.entries[0].updated);
scmp("Entry 1 ID",
"tag:example.org,2003:3.2397",
f.entries[0].id);
scmp("Entry 1 Published",
"2003-12-13T08:29:29-04:00",
f.entries[0].published);
zcmp("Entry 1 Links",
2z,
len(f.entries[0].links));
scmp("Entry 1 Link 1 HREF",
"http://example.org/2005/04/02/atom",
f.entries[0].links[0].href);
scmp("Entry 1 Link 1 Rel",
"alternate",
f.entries[0].links[0].rel);
scmp("Entry 1 Link 1 Type",
"text/html",
f.entries[0].links[0].linktype);
scmp("Entry 1 Link 1 Lang",
"",
f.entries[0].links[0].hreflang);
scmp("Entry 1 Link 1 Title",
"",
f.entries[0].links[0].title);
scmp("Entry 1 Link 1 Length",
"",
f.entries[0].links[0].length);
scmp("Entry 1 Link 2 HREF",
"http://example.org/audio/ph34r_my_podcast.mp3",
f.entries[0].links[1].href);
scmp("Entry 1 Link 2 Rel",
"enclosure",
f.entries[0].links[1].rel);
scmp("Entry 1 Link 2 Type",
"audio/mpeg",
f.entries[0].links[1].linktype);
scmp("Entry 1 Link 2 Lang",
"",
f.entries[0].links[1].hreflang);
scmp("Entry 1 Link 2 Title",
"",
f.entries[0].links[1].title);
scmp("Entry 1 Link 2 Length",
"1337",
f.entries[0].links[1].length);
scmp("Entry 1 Title Type",
"text",
f.entries[0].title.1);
scmp("Entry 1 Title Value",
"Atom draft-07 snapshot",
f.entries[0].title.0);
scmp("Entry 1 Rights Type",
"text",
f.entries[0].rights.1);
scmp("Entry 1 Rights Value",
"© 2005 Jane Doe",
f.entries[0].rights.0);
scmp("Entry 1 Summary Type",
"",
f.entries[0].summary.1);
scmp("Entry 1 Summary Value",
"",
f.entries[0].summary.0);
scmp("Entry 1 Content Type",
"text",
f.entries[0].content.1);
scmp("Entry 1 Content Value",
"[Update: The Atom draft is finished.]",
f.entries[0].content.0);
zcmp("Entry 1 Authors",
1z,
len(f.entries[0].authors));
scmp("Entry 1 Author 1 Name",
"Mark Pilgrim",
f.entries[0].authors[0].name);
scmp("Entry 1 Author 1 URI",
"http://example.org/",
f.entries[0].authors[0].uri);
scmp("Entry 1 Author 1 Email",
"f8dy@example.com",
f.entries[0].authors[0].email);
zcmp("Entry 1 Author 1 Extensions",
0z,
len(f.entries[0].authors[0].extensions));
zcmp("Entry 1 Contibutors",
2z,
len(f.entries[0].contributors));
scmp("Entry 1 Contibutor 1 Name",
"Sam Ruby",
f.entries[0].contributors[0].name);
scmp("Entry 1 Contibutor 1 URI",
"",
f.entries[0].contributors[0].uri);
scmp("Entry 1 Contributor 1 Email",
"",
f.entries[0].contributors[0].email);
scmp("Entry 1 Contributor 1 Name",
"Joe Gregorio",
f.entries[0].contributors[1].name);
scmp("Entry 1 Contributor 1 URI",
"",
f.entries[0].contributors[1].uri);
scmp("Entry 1 Contributor 1 Email",
"",
f.entries[0].contributors[1].email);
zcmp("Entry 1 Contributor 1 Extensions",
0z,
len(f.entries[0].contributors[0].extensions));
zcmp("Entry 1 Categories",
1z,
len(f.entries[0].categories));
};
fn zcmp(name: const str, e: const size, a: const size ) void = {
fmt::printfln("\n{}\nExpected: {}\n Actual: {}", name, e, a)!;
assert(e == a);
};
fn scmp(name: const str, e: const str, a: const str) void = {
fmt::printfln("\n{}\nExpected: {}\n Actual: {}", name, e, a)!;
assert(e == a);
};