Console: Added lots of unit-tests
[senf.git] / Console / Parse.test.cc
index 11d8a38..491866a 100644 (file)
@@ -35,7 +35,7 @@
 #include "Parse.ih"
 #include "../Utils/String.hh"
 
-#include <boost/test/auto_unit_test.hpp>
+#include "../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
 
 namespace 
 {
-    
-
     struct TestParseDispatcher 
     {
         TestParseDispatcher(std::ostream & os) : os_ (os) {}
 
         std::ostream & os_;
 
+        void pushDirectory(std::vector<std::string> const & path)
+            { os_ << "pushDirectory( " << senf::stringJoin(path,"/") << " )\n"; }
+        void popDirectory()
+            { os_ << "popDirectory()\n"; }
+
         void beginCommand(std::vector<std::string> const & command) 
             { os_ << "beginCommand( " << senf::stringJoin(command, "/") << " )\n"; }
         void endCommand() 
@@ -70,11 +73,15 @@ namespace
         void builtin_cd(std::vector<std::string> const & path)
             { os_ << "builtin_cd( " << senf::stringJoin(path, "/") << " )\n"; }
         void builtin_ls(std::vector<std::string> const & path)
-            { os_ << "builtin_cd( " << senf::stringJoin(path, "/") << " )\n"; }
+            { os_ << "builtin_ls( " << senf::stringJoin(path, "/") << " )\n"; }
+        void builtin_exit()
+            { os_ << "builtin_exit()\n"; }
+        void builtin_help(std::vector<std::string> const & path)
+            { os_ << "builtin_help( " << senf::stringJoin(path, "/") << " )\n"; }
     };
 }
 
-BOOST_AUTO_UNIT_TEST(commandParser)
+BOOST_AUTO_UNIT_TEST(commandGrammar)
 {
     senf::console::detail::CommandGrammar<TestParseDispatcher>::Context context;
     std::stringstream ss;
@@ -91,7 +98,12 @@ BOOST_AUTO_UNIT_TEST(commandParser)
         "                (a,b,c (huhu))"
         "                \"foo\\\"bar\" #\n"
         "                x\"01 02 # Inner comment\n"
-        "                   0304\"";
+        "                   0304\";"
+        "ls /foo/bar;"
+        "cd /foo/bar;"
+        "exit;"
+        "foo/bar/ { ls; }"
+        "help /foo/bar";
 
     BOOST_CHECK( boost::spirit::parse( 
                      text, 
@@ -114,12 +126,25 @@ BOOST_AUTO_UNIT_TEST(commandParser)
                        "closeGroup()\n"
                        "pushArgument( foo\"bar )\n"
                        "pushArgument( \x01\x02\x03\x04 )\n"
-                       "endCommand()\n" );
+                       "endCommand()\n"
+                       "builtin_ls( /foo/bar )\n"
+                       "builtin_cd( /foo/bar )\n"
+                       "builtin_exit()\n"
+                       "pushDirectory( foo/bar/ )\n"
+                       "builtin_ls(  )\n"
+                       "popDirectory()\n"
+                       "builtin_help( /foo/bar )\n" );
 }
 
-BOOST_AUTO_UNIT_TEST(singleCommandParser)
+namespace {
+    senf::console::ParseCommandInfo info;
+    void setInfo(senf::console::ParseCommandInfo const & i)
+    { info = i; }
+}
+
+BOOST_AUTO_UNIT_TEST(commandParser)
 {
-    senf::console::SingleCommandParser parser;
+    senf::console::CommandParser parser;
 
     char const text[] = 
         "# Comment\n"
@@ -131,8 +156,7 @@ BOOST_AUTO_UNIT_TEST(singleCommandParser)
         "                x\"01 02 # Inner comment\n"
         "                   0304\"";
 
-    senf::console::ParseCommandInfo info;
-    BOOST_CHECK( parser.parseCommand(text, info) );
+    BOOST_CHECK( parser.parse(text, &setInfo) );
 
     char const * path[] = { "doo", "bii", "doo" };