[opengtl-commits] [732] add a test and fix a bug

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 732
Author:   cyrille
Date:     2009-05-06 20:28:28 +0200 (Wed, 06 May 2009)

Log Message:
-----------
add a test and fix a bug

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
    trunk/OpenGTL/OpenCTL/tests/library/TestOpenCTL.cpp

Added Paths:
-----------
    trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-06 18:04:33 UTC (rev 731)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-06 18:28:28 UTC (rev 732)
@@ -43,7 +43,7 @@
   while (not eof() )
   {
     lastChar = getNextChar();
-    if( lastChar == '@' or lastChar == '(' or lastChar == ')' )
+    if( lastChar == '@' or lastChar == '(' or lastChar == ')' or eof() )
     {
       unget();
       break;
@@ -51,5 +51,5 @@
       str += lastChar;
     }
   }
-  return GTLCore::Token(GTLCore::Token::IDENTIFIER, str, line(), initial_col);
+  return GTLCore::Token(GTLCore::Token::STRING_CONSTANT, str, line(), initial_col);
 }

Modified: trunk/OpenGTL/OpenCTL/tests/library/TestOpenCTL.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/library/TestOpenCTL.cpp	2009-05-06 18:04:33 UTC (rev 731)
+++ trunk/OpenGTL/OpenCTL/tests/library/TestOpenCTL.cpp	2009-05-06 18:28:28 UTC (rev 732)
@@ -36,6 +36,7 @@
 #include "TestModule.h"
 #include "TestLexerNG.h"
 #include "TestParserNG.h"
+#include "TestTemplateLexer.h"
 
 GTLTEST_MAIN_BEGIN(TestOpenCTL)
 GTLTEST_MAIN_ADD_CASE(TestFunction)
@@ -43,4 +44,5 @@
 GTLTEST_MAIN_ADD_CASE(TestModule)
 GTLTEST_MAIN_ADD_CASE(TestLexerNG)
 GTLTEST_MAIN_ADD_CASE(TestParserNG)
+GTLTEST_MAIN_ADD_CASE(TestTemplateLexer)
 GTLTEST_MAIN_END()

Added: trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h	2009-05-06 18:28:28 UTC (rev 732)
@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "OpenCTL/templatecompiler/TemplateLexer_p.h"
+#include "GTLCore/Token_p.h"
+
+#define TEST_FOR_TOKEN_STRING( str ) \
+  { \
+    GTLCore::Token tok = lng.nextToken(); \
+    GTLTEST_CHECK_EQUAL(tok.type, GTLCore::Token::STRING_CONSTANT ); \
+    GTLTEST_CHECK_EQUAL(tok.string, str); \
+  }
+
+class TestTemplateLexer : public GTLTest::Case {
+  public:
+    TestTemplateLexer() : GTLTest::Case("TemplateLexer") {}
+    virtual void runTest()
+    {
+      std::istringstream iss("I am a string @hello(world) kikoo");
+      OpenCTL::TemplateLexer lng(&iss);
+      TEST_FOR_TOKEN_STRING("I am a string ");
+      TEST_FOR_TOKEN(AROBASE);
+      TEST_FOR_TOKEN_STRING("hello");
+      TEST_FOR_TOKEN(STARTBRACKET);
+      TEST_FOR_TOKEN_STRING("world");
+      TEST_FOR_TOKEN(ENDBRACKET);
+      TEST_FOR_TOKEN_STRING(" kikoo");
+    }
+};


Property changes on: trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/