From 5af3fc04c60703c30fba87956c7e19b021c6f367 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Tue, 22 May 2012 22:17:50 -0500 Subject: [PATCH] Registered all the generated emitter tests --- test/create-emitter-tests.py | 12 +++++--- test/genemittertests.h | 53 ++++++++++++++++++++++++++++++++++++ test/handlermacros.h | 8 +++--- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 test/genemittertests.h diff --git a/test/create-emitter-tests.py b/test/create-emitter-tests.py index 237d013..93cab54 100644 --- a/test/create-emitter-tests.py +++ b/test/create-emitter-tests.py @@ -25,13 +25,13 @@ def doc_start(implicit=False): if implicit: return {'emit': '', 'handle': 'DOC_START()'} else: - return {'emit': 'YAML::DocStart', 'handle': 'DOC_START()'} + return {'emit': 'YAML::BeginDoc', 'handle': 'DOC_START()'} def doc_end(implicit=False): if implicit: return {'emit': '', 'handle': 'DOC_END()'} else: - return {'emit': 'YAML::DocEnd', 'handle': 'DOC_END()'} + return {'emit': 'YAML::EndDoc', 'handle': 'DOC_END()'} def scalar(value, tag='', anchor='', anchor_id=0): emit = [] @@ -39,8 +39,12 @@ def scalar(value, tag='', anchor='', anchor_id=0): emit += ['YAML::VerbatimTag("%s")' % encode(tag)] if anchor: emit += ['YAML::Anchor("%s")' % encode(anchor)] + if tag: + out_tag = encode(tag) + else: + out_tag = '!' emit += ['"%s"' % encode(value)] - return {'emit': emit, 'handle': 'SCALAR("%s", %s, "%s")' % (encode(tag), anchor_id, encode(value))} + return {'emit': emit, 'handle': 'SCALAR("%s", %s, "%s")' % (out_tag, anchor_id, encode(value))} def gen_outlines(): yield [doc_start(), scalar('foo\n'), doc_end()] @@ -87,7 +91,7 @@ def create_emitter_tests(out): out.write('void RunGenEmitterTests(int& passed, int& total)\n') out.write('{\n') for test in tests: - out.write(' RunGenEmitterTest(&Emitter::%s, %s, passed, total);\n' % (test['name'], encode(test['name']))) + out.write(' RunGenEmitterTest(&Emitter::%s, "%s", passed, total);\n' % (test['name'], encode(test['name']))) out.write('}\n') if __name__ == '__main__': diff --git a/test/genemittertests.h b/test/genemittertests.h new file mode 100644 index 0000000..9e008f2 --- /dev/null +++ b/test/genemittertests.h @@ -0,0 +1,53 @@ +namespace Emitter { +TEST testb3471d40ef2dadee13be(YAML::Emitter& out) +{ + out << YAML::BeginDoc; + out << "foo\n"; + out << YAML::EndDoc; + + HANDLE(out.c_str()); + EXPECT_DOC_START(); + EXPECT_SCALAR("!", 0, "foo\n"); + EXPECT_DOC_END(); + DONE(); +} +TEST testb1f8cfb6083c3fc130aa(YAML::Emitter& out) +{ + out << "foo\n"; + out << YAML::EndDoc; + + HANDLE(out.c_str()); + EXPECT_DOC_START(); + EXPECT_SCALAR("!", 0, "foo\n"); + EXPECT_DOC_END(); + DONE(); +} +TEST testa2f381bb144cf8886efe(YAML::Emitter& out) +{ + out << YAML::BeginDoc; + out << "foo\n"; + + HANDLE(out.c_str()); + EXPECT_DOC_START(); + EXPECT_SCALAR("!", 0, "foo\n"); + EXPECT_DOC_END(); + DONE(); +} +TEST test29a80ae92b2f00fa1d06(YAML::Emitter& out) +{ + out << "foo\n"; + + HANDLE(out.c_str()); + EXPECT_DOC_START(); + EXPECT_SCALAR("!", 0, "foo\n"); + EXPECT_DOC_END(); + DONE(); +} +} +void RunGenEmitterTests(int& passed, int& total) +{ + RunGenEmitterTest(&Emitter::testb3471d40ef2dadee13be, "testb3471d40ef2dadee13be", passed, total); + RunGenEmitterTest(&Emitter::testb1f8cfb6083c3fc130aa, "testb1f8cfb6083c3fc130aa", passed, total); + RunGenEmitterTest(&Emitter::testa2f381bb144cf8886efe, "testa2f381bb144cf8886efe", passed, total); + RunGenEmitterTest(&Emitter::test29a80ae92b2f00fa1d06, "test29a80ae92b2f00fa1d06", passed, total); +} diff --git a/test/handlermacros.h b/test/handlermacros.h index 5bdaf69..6b87303 100644 --- a/test/handlermacros.h +++ b/test/handlermacros.h @@ -7,7 +7,7 @@ #include namespace Test { - std::string Quote(const std::string& text) { + inline std::string Quote(const std::string& text) { YAML::Emitter out; out << YAML::DoubleQuoted << text; return out.c_str(); @@ -52,15 +52,15 @@ namespace Test { } }; - std::ostream& operator << (std::ostream& out, const Event& event) { + inline std::ostream& operator << (std::ostream& out, const Event& event) { return event.write(out); } - bool operator == (const Event& a, const Event& b) { + inline bool operator == (const Event& a, const Event& b) { return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor && a.scalar == b.scalar; } - bool operator != (const Event& a, const Event& b) { + inline bool operator != (const Event& a, const Event& b) { return !(a == b); }