X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParse.test.cc;h=9d465b7ebbde33e3620a5cbf96044658effc584b;hb=bf1d8ba5ce6fc6a169a938183f8d01c8bdbccf32;hp=11d8a383b4845115f1167b88d962a81f2f89f403;hpb=412cf8e222086fb5d89b15cb11556799e131f390;p=senf.git diff --git a/Console/Parse.test.cc b/Console/Parse.test.cc index 11d8a38..9d465b7 100644 --- a/Console/Parse.test.cc +++ b/Console/Parse.test.cc @@ -35,7 +35,7 @@ #include "Parse.ih" #include "../Utils/String.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #define prefix_ @@ -43,14 +43,17 @@ namespace { - - struct TestParseDispatcher { TestParseDispatcher(std::ostream & os) : os_ (os) {} std::ostream & os_; + void pushDirectory(std::vector const & path) + { os_ << "pushDirectory( " << senf::stringJoin(path,"/") << " )\n"; } + void popDirectory() + { os_ << "popDirectory()\n"; } + void beginCommand(std::vector const & command) { os_ << "beginCommand( " << senf::stringJoin(command, "/") << " )\n"; } void endCommand() @@ -70,11 +73,15 @@ namespace void builtin_cd(std::vector const & path) { os_ << "builtin_cd( " << senf::stringJoin(path, "/") << " )\n"; } void builtin_ls(std::vector 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 const & path) + { os_ << "builtin_help( " << senf::stringJoin(path, "/") << " )\n"; } }; } -BOOST_AUTO_UNIT_TEST(commandParser) +BOOST_AUTO_UNIT_TEST(commandGrammar) { senf::console::detail::CommandGrammar::Context context; std::stringstream ss; @@ -88,10 +95,15 @@ BOOST_AUTO_UNIT_TEST(commandParser) "doo / bii / doo arg" " flab::blub" " 123.434>a" - " (a,b,c (huhu))" + " (a,b;c (huhu/{haha}))" " \"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, @@ -106,20 +118,37 @@ BOOST_AUTO_UNIT_TEST(commandParser) "pushWord( a )\n" "pushPunctuation( , )\n" "pushWord( b )\n" - "pushPunctuation( , )\n" + "pushPunctuation( ; )\n" "pushWord( c )\n" "pushPunctuation( ( )\n" "pushWord( huhu )\n" + "pushPunctuation( / )\n" + "pushPunctuation( { )\n" + "pushWord( haha )\n" + "pushPunctuation( } )\n" "pushPunctuation( ) )\n" "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" ); +} + +namespace { + senf::console::ParseCommandInfo info; + void setInfo(senf::console::ParseCommandInfo const & i) + { info = i; } } -BOOST_AUTO_UNIT_TEST(singleCommandParser) +BOOST_AUTO_UNIT_TEST(commandParser) { - senf::console::SingleCommandParser parser; + senf::console::CommandParser parser; char const text[] = "# Comment\n" @@ -131,8 +160,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" };