Registered all the generated emitter tests

This commit is contained in:
Jesse Beder
2012-05-22 22:17:50 -05:00
parent 0fb59c18dd
commit 5af3fc04c6
3 changed files with 65 additions and 8 deletions

View File

@@ -25,13 +25,13 @@ def doc_start(implicit=False):
if implicit: if implicit:
return {'emit': '', 'handle': 'DOC_START()'} return {'emit': '', 'handle': 'DOC_START()'}
else: else:
return {'emit': 'YAML::DocStart', 'handle': 'DOC_START()'} return {'emit': 'YAML::BeginDoc', 'handle': 'DOC_START()'}
def doc_end(implicit=False): def doc_end(implicit=False):
if implicit: if implicit:
return {'emit': '', 'handle': 'DOC_END()'} return {'emit': '', 'handle': 'DOC_END()'}
else: else:
return {'emit': 'YAML::DocEnd', 'handle': 'DOC_END()'} return {'emit': 'YAML::EndDoc', 'handle': 'DOC_END()'}
def scalar(value, tag='', anchor='', anchor_id=0): def scalar(value, tag='', anchor='', anchor_id=0):
emit = [] emit = []
@@ -39,8 +39,12 @@ def scalar(value, tag='', anchor='', anchor_id=0):
emit += ['YAML::VerbatimTag("%s")' % encode(tag)] emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
if anchor: if anchor:
emit += ['YAML::Anchor("%s")' % encode(anchor)] emit += ['YAML::Anchor("%s")' % encode(anchor)]
if tag:
out_tag = encode(tag)
else:
out_tag = '!'
emit += ['"%s"' % encode(value)] 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(): def gen_outlines():
yield [doc_start(), scalar('foo\n'), doc_end()] 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('void RunGenEmitterTests(int& passed, int& total)\n')
out.write('{\n') out.write('{\n')
for test in tests: 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') out.write('}\n')
if __name__ == '__main__': if __name__ == '__main__':

53
test/genemittertests.h Normal file
View File

@@ -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);
}

View File

@@ -7,7 +7,7 @@
#include <cassert> #include <cassert>
namespace Test { namespace Test {
std::string Quote(const std::string& text) { inline std::string Quote(const std::string& text) {
YAML::Emitter out; YAML::Emitter out;
out << YAML::DoubleQuoted << text; out << YAML::DoubleQuoted << text;
return out.c_str(); 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); 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; 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); return !(a == b);
} }