]> git.localhorst.tv Git - blank.git/blobdiff - tst/io/TokenTest.cpp
impersonate command
[blank.git] / tst / io / TokenTest.cpp
index d0d7fc4d95e89ac1c3dc8f19a2cfc0fd30c8fe02..16b4f4d8aeddfdc37dabb8300755e4eeca5e5ade 100644 (file)
@@ -202,6 +202,7 @@ void TokenTest::testReader() {
                "0 1 -1 2.5\n"
                // strings
                "\"hello\" \"\" \"\\r\\n\\t\\\"\"\n"
+               "\"world\" foo 12\n"
                // vectors
                "[1,0] [ 0.707, 0.707 ] // vec2\n"
                "[.577,.577 ,0.577] [ 1,-2,3] // vec3\n"
@@ -308,6 +309,21 @@ void TokenTest::testReader() {
                "reading string \"\\r\\n\\t\\\"\"",
                "\r\n\t\"", value_string, in);
 
+       in.ReadRelaxedString(value_string);
+       assert_read<string>(
+               "reading relaxed string \"world\"",
+               "world", value_string, in);
+
+       in.ReadRelaxedString(value_string);
+       assert_read<string>(
+               "reading relaxed string foo",
+               "foo", value_string, in);
+
+       in.ReadRelaxedString(value_string);
+       assert_read<string>(
+               "reading relaxed string 12",
+               "12", value_string, in);
+
        // vectors
 
        glm::vec2 value_vec2;
@@ -361,6 +377,12 @@ void TokenTest::testReader() {
        assert_read(
                "reading quaternion [ -0.945, 0, -0.326, 0]",
                glm::quat(-0.945, 0, -0.326, 0), value_quat, in);
+       // TODO: comment at end of stream makes it think there's more?
+       //CPPUNIT_ASSERT_MESSAGE("expected end of stream", !in.HasMore());
+       // TODO: and it even works??
+       //CPPUNIT_ASSERT_THROW_MESSAGE(
+       //      "extracting token after EOS",
+       //      in.Next(), std::runtime_error);
 }
 
 void TokenTest::testReaderEmpty() {
@@ -389,9 +411,30 @@ void TokenTest::testReaderEmpty() {
 }
 
 void TokenTest::testReaderMalformed() {
-       stringstream ss;
-       ss << "";
-       TokenStreamReader in(ss);
+       {
+               stringstream ss;
+               ss << "a";
+               TokenStreamReader in(ss);
+               CPPUNIT_ASSERT_THROW_MESSAGE(
+                       "unexpected token type should throw",
+                       in.GetInt(), std::runtime_error);
+       }
+       {
+               stringstream ss;
+               ss << ":";
+               TokenStreamReader in(ss);
+               CPPUNIT_ASSERT_THROW_MESSAGE(
+                       "casting ':' to bool should throw",
+                       in.GetBool(), std::runtime_error);
+       }
+       {
+               stringstream ss;
+               ss << "hello";
+               TokenStreamReader in(ss);
+               CPPUNIT_ASSERT_THROW_MESSAGE(
+                       "casting \"hello\" to bool should throw",
+                       in.GetBool(), std::runtime_error);
+       }
 }