diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-12 11:30:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-12 11:30:04 +0200 |
commit | 257ad3c2c5e633d2fd3f2228021ac3ae8d6d07cb (patch) | |
tree | ecfa5df6e8abca5bd483d5498bf84412ae58930e /tests/build | |
parent | 0dcf07989b4b942f6ff872023b2886b7f698d711 (diff) |
Initial buildfile parser implementation
g++-4.9 -std=c++14 -g -I../../.. -o driver driver.cxx ../../../build/lexer.cxx ../../../build/parser.cxx && ./driver
Diffstat (limited to 'tests/build')
-rw-r--r-- | tests/build/lexer/driver.cxx | 4 | ||||
-rw-r--r-- | tests/build/parser/driver.cxx | 70 |
2 files changed, 73 insertions, 1 deletions
diff --git a/tests/build/lexer/driver.cxx b/tests/build/lexer/driver.cxx index b1af9d9..e329b1c 100644 --- a/tests/build/lexer/driver.cxx +++ b/tests/build/lexer/driver.cxx @@ -71,6 +71,8 @@ main () tokens ({"foo", ":", "\n", "bar", ""})); } +ostream cnull (nullptr); + static tokens lex (const char* s) { @@ -78,7 +80,7 @@ lex (const char* s) istringstream is (s); is.exceptions (istream::failbit | istream::badbit); - lexer l (is, ""); + lexer l (is, "", cnull); try { diff --git a/tests/build/parser/driver.cxx b/tests/build/parser/driver.cxx new file mode 100644 index 0000000..4ba589d --- /dev/null +++ b/tests/build/parser/driver.cxx @@ -0,0 +1,70 @@ +// file : tests/build/parser/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <cassert> +#include <sstream> +#include <iostream> + +#include <build/path> +#include <build/lexer> +#include <build/parser> + +using namespace std; +using namespace build; + +static bool +parse (const char*); + +int +main () +{ + assert (parse ("")); + assert (parse ("foo:")); + assert (parse ("foo bar:")); + assert (parse ("foo:\nbar:")); + assert (parse ("foo: bar")); + assert (parse ("foo: bar baz")); + assert (parse ("foo bar: baz biz")); + + assert (parse ("{foo}:")); + assert (parse ("{foo bar}:")); + assert (parse ("{{foo bar}}:")); + assert (parse ("{{foo bar} {baz} {biz fox} fix}:")); + + assert (parse ("exe{foo}:")); + assert (parse ("exe{foo bar}:")); + assert (parse ("{exe{foo bar}}:")); + assert (parse ("exe{{foo bar} fox}:")); + assert (parse ("exe{foo}: obj{bar baz} biz.o lib{fox}")); + + assert (!parse (":")); + assert (!parse ("foo")); + assert (!parse ("{")); + assert (!parse ("{foo:")); + assert (!parse ("{foo{:")); + assert (!parse ("foo: bar:")); + assert (!parse ("exe{foo:")); +} + +ostream cnull (nullptr); + +static bool +parse (const char* s) +{ + istringstream is (s); + + is.exceptions (istream::failbit | istream::badbit); + parser p (cnull); + + try + { + p.parse (is, path ()); + } + catch (const parser_error&) + { + return false; + } + + return true; +} |