aboutsummaryrefslogtreecommitdiff
path: root/tests/build/parser/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-12-12 11:30:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-12-12 11:30:04 +0200
commit257ad3c2c5e633d2fd3f2228021ac3ae8d6d07cb (patch)
treeecfa5df6e8abca5bd483d5498bf84412ae58930e /tests/build/parser/driver.cxx
parent0dcf07989b4b942f6ff872023b2886b7f698d711 (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/parser/driver.cxx')
-rw-r--r--tests/build/parser/driver.cxx70
1 files changed, 70 insertions, 0 deletions
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;
+}