diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 17:40:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 17:40:06 +0200 |
commit | 82ad80de9a967f253026c4874b47486c69402288 (patch) | |
tree | 8bdc35b1a59e324b401291d7ea015cc0deb00c7d /tests/parser/driver.cxx | |
parent | 902f3763af4931c5c04c47d10e4d24dba96487cd (diff) |
Add headers to buildfiles, move tests/build/ to tests/
Diffstat (limited to 'tests/parser/driver.cxx')
-rw-r--r-- | tests/parser/driver.cxx | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx new file mode 100644 index 0000000..fef2f41 --- /dev/null +++ b/tests/parser/driver.cxx @@ -0,0 +1,102 @@ +// file : tests/build/parser/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <cassert> +#include <sstream> +#include <iostream> + +#include <build/types> +#include <build/scope> +#include <build/target> +#include <build/native> + +#include <build/lexer> +#include <build/parser> + +using namespace std; +using namespace build; + +static bool +parse (const char*); + +int +main () +{ + ostream cnull (nullptr); + diag_stream = &cnull; + + target_types.insert (file::static_type); + target_types.insert (exe::static_type); + target_types.insert (obj::static_type); + + 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 file{fox}")); + + assert (!parse (":")); + assert (!parse ("foo")); + assert (!parse ("{")); + assert (!parse ("{foo:")); + assert (!parse ("{foo{:")); + assert (!parse ("foo: bar:")); + assert (!parse ("exe{foo:")); + + // Directory prefix. + // + assert (parse ("../{foo}: ../{bar}")); + assert (parse ("../exe{foo}: ../obj{bar}")); + assert (!parse ("../exe{exe{foo}}:")); + + // Directory scope. + // + assert (parse ("test/:\n{\n}")); + assert (parse ("test/:\n{\n}\n")); + assert (parse ("test/:\n{\nfoo:bar\n}")); + assert (parse ("test/:\n{\nfoo:bar\n}")); + assert (parse ("test/:\n{\nmore/:\n{\n}\n}")); + assert (parse ("test/:\n{\nmore/:\n{\nfoo:{bar baz}\n}\n}")); + + assert (!parse ("test/:\n{")); + assert (!parse ("test/:\n{\n")); + assert (!parse ("test/:\n{\n:")); + assert (!parse ("test/:\n{\n} foo: bar\n")); + assert (!parse ("test/ foo:\n{\n}")); + assert (!parse ("test foo/:\n{\n}")); + assert (!parse ("test/ foo/:\n{\n}")); +} + +static bool +parse (const char* s) +{ + istringstream is (s); + + is.exceptions (istream::failbit | istream::badbit); + parser p; + + try + { + p.parse (is, path (), scopes[path::current ()]); + } + catch (const failed&) + { + return false; + } + + return true; +} |