summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-08-22 10:25:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-08-22 10:25:12 +0200
commitfabbe60b014a02b2ab94e57ab3866e28c67d36ce (patch)
tree4d776980683dcc118392bd7b67520383918be8ab /tests
parent1470fed809be7b11f147f8a6ca924a252b473c97 (diff)
Add a test for the parser
Diffstat (limited to 'tests')
-rw-r--r--tests/makefile2
-rw-r--r--tests/parser/driver.cxx34
-rw-r--r--tests/parser/makefile83
-rw-r--r--tests/parser/test-000.cli3
-rw-r--r--tests/parser/test-000.std0
-rw-r--r--tests/parser/test-001.cli2
-rw-r--r--tests/parser/test-001.std0
-rw-r--r--tests/parser/test-002.cli13
-rw-r--r--tests/parser/test-002.std0
-rw-r--r--tests/parser/test-003.cli13
-rw-r--r--tests/parser/test-003.std0
-rw-r--r--tests/parser/test-004.cli7
-rw-r--r--tests/parser/test-004.std0
-rw-r--r--tests/parser/test-005.cli6
-rw-r--r--tests/parser/test-005.std0
-rw-r--r--tests/parser/test-006.cli51
-rw-r--r--tests/parser/test-006.std0
17 files changed, 213 insertions, 1 deletions
diff --git a/tests/makefile b/tests/makefile
index fa8b833..7e54132 100644
--- a/tests/makefile
+++ b/tests/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
-tests := lexer
+tests := lexer parser
default := $(out_base)/
test := $(out_base)/.test
diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx
new file mode 100644
index 0000000..c783503
--- /dev/null
+++ b/tests/parser/driver.cxx
@@ -0,0 +1,34 @@
+// file : tests/parser/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <fstream>
+#include <iostream>
+
+#include <cli/parser.hxx>
+
+using namespace std;
+
+int main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " file.cli" << endl;
+ return 1;
+ }
+
+ try
+ {
+ ifstream ifs;
+ ifs.exceptions (ifstream::failbit | ifstream::badbit);
+ ifs.open (argv[1]);
+
+ Parser parser;
+ parser.parse (ifs, argv[1]);
+ }
+ catch (Parser::InvalidInput const&)
+ {
+ return 1;
+ }
+}
diff --git a/tests/parser/makefile b/tests/parser/makefile
new file mode 100644
index 0000000..4642b6d
--- /dev/null
+++ b/tests/parser/makefile
@@ -0,0 +1,83 @@
+# file : tests/parser/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+
+tests := 000 001 002 003 004 005 006
+
+#
+#
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+
+# Build.
+#
+$(driver): $(cxx_obj) $(out_root)/cli/lexer.o $(out_root)/cli/parser.o
+
+$(cxx_obj) $(cxx_od): cpp_options := -I$(src_base) -I$(src_root)
+
+$(call include-dep,$(cxx_od))
+
+
+# Alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+test_targets := $(addprefix $(out_base)/.test-,$(tests))
+
+.PHONY: $(test)
+$(test): $(test_targets)
+
+
+$(test_targets): driver := $(driver)
+
+.PHONY: $(out_base)/.test-%
+$(out_base)/.test-%: $(driver) $(src_base)/test-%.cli $(src_base)/test-%.std
+ $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.cli | diff -u $(src_base)/test-$*.std -)
+
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od))
+
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/install.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/cli/makefile)
diff --git a/tests/parser/test-000.cli b/tests/parser/test-000.cli
new file mode 100644
index 0000000..5951dc6
--- /dev/null
+++ b/tests/parser/test-000.cli
@@ -0,0 +1,3 @@
+include <string>;
+namespace n {}
+class c {};
diff --git a/tests/parser/test-000.std b/tests/parser/test-000.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-000.std
diff --git a/tests/parser/test-001.cli b/tests/parser/test-001.cli
new file mode 100644
index 0000000..a27e027
--- /dev/null
+++ b/tests/parser/test-001.cli
@@ -0,0 +1,2 @@
+include <string>;
+include "types.hxx";
diff --git a/tests/parser/test-001.std b/tests/parser/test-001.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-001.std
diff --git a/tests/parser/test-002.cli b/tests/parser/test-002.cli
new file mode 100644
index 0000000..2413b71
--- /dev/null
+++ b/tests/parser/test-002.cli
@@ -0,0 +1,13 @@
+namespace n1 {}
+
+namespace n1
+{
+ namespace n2 {}
+ class c {};
+ namespace n2
+ {
+ namespace n3 {}
+ }
+}
+
+namespace n4 {}
diff --git a/tests/parser/test-002.std b/tests/parser/test-002.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-002.std
diff --git a/tests/parser/test-003.cli b/tests/parser/test-003.cli
new file mode 100644
index 0000000..2413b71
--- /dev/null
+++ b/tests/parser/test-003.cli
@@ -0,0 +1,13 @@
+namespace n1 {}
+
+namespace n1
+{
+ namespace n2 {}
+ class c {};
+ namespace n2
+ {
+ namespace n3 {}
+ }
+}
+
+namespace n4 {}
diff --git a/tests/parser/test-003.std b/tests/parser/test-003.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-003.std
diff --git a/tests/parser/test-004.cli b/tests/parser/test-004.cli
new file mode 100644
index 0000000..5497dca
--- /dev/null
+++ b/tests/parser/test-004.cli
@@ -0,0 +1,7 @@
+class c1
+{
+};
+
+class c2
+{
+}; \ No newline at end of file
diff --git a/tests/parser/test-004.std b/tests/parser/test-004.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-004.std
diff --git a/tests/parser/test-005.cli b/tests/parser/test-005.cli
new file mode 100644
index 0000000..84dc24f
--- /dev/null
+++ b/tests/parser/test-005.cli
@@ -0,0 +1,6 @@
+class c
+{
+ bool -a;
+ int -b;
+ float -c;
+};
diff --git a/tests/parser/test-005.std b/tests/parser/test-005.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-005.std
diff --git a/tests/parser/test-006.cli b/tests/parser/test-006.cli
new file mode 100644
index 0000000..7c70887
--- /dev/null
+++ b/tests/parser/test-006.cli
@@ -0,0 +1,51 @@
+class c
+{
+ bool --bool;
+ char --char;
+
+ int -i1;
+ unsigned int -i2;
+ int unsigned -i3;
+ long -i4;
+ long int -i5;
+ int long -i6;
+ unsigned long -i7;
+ long unsigned -i8;
+
+ unsigned long int -i9;
+ long unsigned int -i10;
+ int long unsigned -i11;
+ unsigned int long -i12;
+
+ short -i13;
+ unsigned short -i14;
+ short unsigned -i15;
+
+ char -i16;
+ signed char -i17;
+ char signed -i18;
+ unsigned char -i19;
+ char unsigned -i20;
+
+ double -d1;
+ long double -d2;
+ double long -d3;
+
+ foo -o1;
+ ::foo -o2;
+ ::foo<bar> -o3;
+ foo::bar -o4;
+ ::foo::bar -o5;
+ ::foo<bar>::baz -o6;
+ ::foo<bar>::baz< ::fox<2> > -o7;
+
+ bool -n|--name|/name;
+
+ string -init1 = "string";
+ char -init2 = 'c';
+ int -init3 = -5;
+ bool -inti4 = true;
+ long -init5 = (2 * 4 - 5);
+ type -init6 = type::default_value;
+ type -init7 (abc, 2 - 1);
+};
diff --git a/tests/parser/test-006.std b/tests/parser/test-006.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/parser/test-006.std