From e6ebbe43ed9043c12245cea152cbc62ffd4ad0df Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 3 Jun 2019 11:15:11 +0300 Subject: [PATCH] Add a test case for Loader overload resolution --- tests/loader.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/loader.cpp b/tests/loader.cpp index 94bf687..f9694af 100644 --- a/tests/loader.cpp +++ b/tests/loader.cpp @@ -17,6 +17,7 @@ public: private: void load(); void int_as_float(); + void overload(); void bad_keyword(); void bad_signature(); }; @@ -45,6 +46,7 @@ LoaderTests::LoaderTests() { add(&LoaderTests::load, "Load"); add(&LoaderTests::int_as_float, "Int -> float"); + add(&LoaderTests::overload, "Overload resolution"); add(&LoaderTests::bad_keyword, "Bad keyword").expect_throw(); add(&LoaderTests::bad_signature, "Bad signature").expect_throw(); } @@ -83,6 +85,22 @@ void LoaderTests::int_as_float() EXPECT_EQUAL(obj.f, 2); } +void LoaderTests::overload() +{ + const char input[] = + "o 1.0;\n" + "o 2;\n"; + + TestObject obj; + IO::Memory mem(input, sizeof(input)-1); + DataFile::Parser parser(mem, "-"); + TestObject::Loader loader(obj); + loader.load(parser); + + EXPECT_EQUAL(obj.f, 1.0f); + EXPECT_EQUAL(obj.i, 2); +} + void LoaderTests::bad_keyword() { const char input[] = @@ -118,6 +136,8 @@ TestObject::Loader::Loader(TestObject &o): { add("i", &TestObject::i); add("f", &TestObject::f); + add("o", &TestObject::i); + add("o", &TestObject::f); add("s", &TestObject::s); add("c", &Loader::func); } -- 2.45.2