8static vector<string> parse(
const string& stream)
10 vector<string> result;
18 SECTION(
"whitespace") {
19 CHECK(parse(
"<command>foo</command>") ==
20 vector<string>{
"foo"});
21 CHECK(parse(
" \t<command>foo</command>") ==
22 vector<string>{
"foo"});
23 CHECK(parse(
"<command>foo</command>\n ") ==
24 vector<string>{
"foo"});
25 CHECK(parse(
" \n\n<command>foo</command> \t\n ") ==
26 vector<string>{
"foo"});
28 SECTION(
"multiple commands") {
29 CHECK(parse(
"<command>foo</command><command>bar</command>") ==
30 vector<string>{
"foo",
"bar"});
31 CHECK(parse(
"<command>foo</command> <command>bar</command>") ==
32 vector<string>{
"foo",
"bar"});
34 SECTION(
"XML-entities") {
35 CHECK(parse(
"<command>&</command>") ==
37 CHECK(parse(
"<command>'</command>") ==
39 CHECK(parse(
"<command>"</command>") ==
40 vector<string>{
"\""});
41 CHECK(parse(
"<command><</command>") ==
43 CHECK(parse(
"<command>></command>") ==
45 CHECK(parse(
"<command>A</command>") ==
47 CHECK(parse(
"<command>A</command>") ==
49 CHECK(parse(
"<command><command></command>") ==
50 vector<string>{
"<command>"});
52 SECTION(
"tags other than <command> are ignored") {
53 CHECK(parse(
"<openmsx-control> <command>foo</command> </openmsx-control>") ==
54 vector<string>{
"foo"});
55 CHECK(parse(
"<openmsx-control> <unknown>foo</unknown> <command>foo</command>") ==
56 vector<string>{
"foo"});
58 SECTION(
"errors, but we do recover") {
59 CHECK(parse(
"<command>&unknown;</command><command>foo</command>") ==
60 vector<string>{
"foo"});
61 CHECK(parse(
"<command>&#fffffff;</command><command>foo</command>") ==
62 vector<string>{
"foo"});
63 CHECK(parse(
"<<<<<command>foo</command>") ==
64 vector<string>{
"foo"});
65 CHECK(parse(
"<foo></bar><command>foo</command>") ==
66 vector<string>{
"foo"});
67 CHECK(parse(
"</command><command>foo</command>") ==
68 vector<string>{
"foo"});
69 CHECK(parse(
"<command>bar</foobar><command>foo</command>") ==
70 vector<string>{
"foo"});
72 SECTION(
"old (XML) parser didn't accept this, AdhocCliCommParser does") {
74 CHECK(parse(
"<openmsx-control></openmsx-control><command>foo</command>") ==
75 vector<string>{
"foo"});
77 SECTION(
"old (XML) parser did accept this, AdhocCliCommParser does not") {
79 CHECK(parse(
"<command value=\"3\">foo</command>") ==
82 CHECK(parse(
"<command><bla></bla>foo</command>") ==
86 CHECK(parse(
"<command/>") ==
TEST_CASE("AdhocCliCommParser")
void parse(std::span< const char > buf)