]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add tests for libvaladoc/parser and gtkdoc-scanner
authorFlorian Brosch <flo.brosch@gmail.com>
Mon, 13 Aug 2012 01:06:46 +0000 (03:06 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Mon, 13 Aug 2012 01:24:08 +0000 (03:24 +0200)
tests/Makefile.am
tests/helpers.vala [new file with mode: 0644]
tests/libvaladoc/errorreporter.vala
tests/libvaladoc/gtkdoc-scanner.vala [new file with mode: 0644]
tests/libvaladoc/parser/manyrule.vala [new file with mode: 0644]
tests/libvaladoc/parser/oneofrule.vala [new file with mode: 0644]
tests/libvaladoc/parser/optionalrule.vala [new file with mode: 0644]
tests/libvaladoc/parser/sequencerule.vala [new file with mode: 0644]
tests/libvaladoc/parser/stubrule.vala [new file with mode: 0644]
tests/testrunner.sh

index fa3e37f05f4eb1cdfa61545f37d054157a9d175b..288533443c62a6141018cf6b38ea811b95db24f4 100644 (file)
@@ -16,6 +16,12 @@ TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) $(srcdir)/testrunner.sh
 
 TESTS = \
        libvaladoc/errorreporter.vala \
+       libvaladoc/gtkdoc-scanner.vala \
+       libvaladoc/parser/manyrule.vala \
+       libvaladoc/parser/oneofrule.vala \
+       libvaladoc/parser/sequencerule.vala \
+       libvaladoc/parser/optionalrule.vala \
+       libvaladoc/parser/stubrule.vala \
        $(NULL)
 
 check-TESTS: $(TESTS)
diff --git a/tests/helpers.vala b/tests/helpers.vala
new file mode 100644 (file)
index 0000000..183bd5e
--- /dev/null
@@ -0,0 +1,70 @@
+/* helpers.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public class TestScanner : Object, Valadoc.Scanner {
+       Valadoc.Parser parser;
+
+       Valadoc.TokenType[] seq = {};
+       bool _stop = false;
+       int pos = 0;
+
+       public void set_pattern (Valadoc.TokenType[] seq) {
+               this.seq = seq;
+       }
+
+       private void emit_token (Valadoc.TokenType type) throws Valadoc.ParserError {
+               Valadoc.SourceLocation loc = SourceLocation (pos, pos);
+               parser.accept_token (new Token.from_type (type, loc, loc));
+       }
+
+       public void set_parser (Valadoc.Parser parser) {
+               this.parser = parser;
+       }
+
+       public void reset () {
+               _stop = false;
+               pos = 0;
+       }
+
+       public void scan (string content) throws Valadoc.ParserError {
+               while (!_stop && pos < seq.length) {
+                       emit_token (seq[pos]);
+                       pos++;
+               }
+       }
+
+       public void end () throws Valadoc.ParserError {
+               emit_token (Valadoc.TokenType.EOF);
+       }
+
+       public void stop () {
+               _stop = true;
+       }
+
+       public string get_line_content () {
+               return "";
+       }
+}
+
index 93ec7b4e025bacf8f23cee56be160bc303e7ce22..2b77ffa2a99ec50e4d9774c1f77544ffff9b837c 100644 (file)
@@ -1,8 +1,30 @@
+/* errorreporter.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
 
 using Valadoc;
 
 void main () {
-       var reporter = new ErrorReporter ();
+       var reporter = new Valadoc.ErrorReporter ();
        assert (reporter.warnings == 0);
        assert (reporter.errors == 0);
 
diff --git a/tests/libvaladoc/gtkdoc-scanner.vala b/tests/libvaladoc/gtkdoc-scanner.vala
new file mode 100644 (file)
index 0000000..5144803
--- /dev/null
@@ -0,0 +1,225 @@
+/* gtkdoc-scanner.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+
+using Valadoc;
+
+
+void main () {
+       var scanner = new Gtkdoc.Scanner ();
+       scanner.reset ("""<element1>
+<element2 a="a-val" b="b-val">
+</element3>
+<element4 />
+<element5 a="a-val" b="b-val"/>
+<!---->
+<!--
+AAAA
+-->
+foo_bar ()
+%aaa
+@param
+#TypeName
+myword      
+
+|[]|
+::my-signal
+:my-property
+""");
+
+       var token = scanner.next ();
+
+       assert (token.type == Gtkdoc.TokenType.XML_OPEN);
+       assert (token.content == "element1");
+       assert (((Gee.Map) token.attributes).size == 0);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_OPEN);
+       assert (token.content == "element2");
+       assert (token.attributes.get ("a") == "a-val");
+       assert (token.attributes.get ("b") == "b-val");
+       assert (((Gee.Map) token.attributes).size == 2);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_CLOSE);
+       assert (token.content == "element3");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_OPEN);
+       assert (token.content == "element4");
+       assert (((Gee.Map) token.attributes).size == 0);
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_CLOSE);
+       assert (token.content == "element4");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_OPEN);
+       assert (token.content == "element5");
+       assert (token.attributes.get ("a") == "a-val");
+       assert (token.attributes.get ("b") == "b-val");
+       assert (((Gee.Map) token.attributes).size == 2);
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_CLOSE);
+       assert (token.content == "element5");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_COMMENT);
+       assert (token.content == "");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.XML_COMMENT);
+       assert (token.content == "");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_FUNCTION);
+       assert (token.content == "foo_bar");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_CONST);
+       assert (token.content == "aaa");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_PARAM);
+       assert (token.content == "param");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_TYPE);
+       assert (token.content == "TypeName");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.WORD);
+       assert (token.content == "myword");
+       assert (token.attributes == null);
+       
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.SPACE);
+       assert (token.content == "      ");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_PARAGRAPH);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_SOURCE_OPEN);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_SOURCE_CLOSE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_SIGNAL);
+       assert (token.content == "my-signal");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.GTKDOC_PROPERTY);
+       assert (token.content == "my-property");
+       assert (token.attributes == null);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.NEWLINE);
+
+
+       token = scanner.next ();
+       assert (token.type == Gtkdoc.TokenType.EOF);
+
+}
diff --git a/tests/libvaladoc/parser/manyrule.vala b/tests/libvaladoc/parser/manyrule.vala
new file mode 100644 (file)
index 0000000..2af76d3
--- /dev/null
@@ -0,0 +1,90 @@
+/* manyrule.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public static void main () {
+       var settings = new Valadoc.Settings ();
+       var scanner = new TestScanner ();
+       var reporter = new ErrorReporter ();
+       var parser = new Parser (settings, scanner, reporter);
+       scanner.set_parser (parser);
+
+       Rule rule = Rule.many ({
+                       Valadoc.TokenType.EQUAL_1
+               });
+
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // negative test:
+       bool reached = false;
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_2
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+}
+
+
diff --git a/tests/libvaladoc/parser/oneofrule.vala b/tests/libvaladoc/parser/oneofrule.vala
new file mode 100644 (file)
index 0000000..fb77085
--- /dev/null
@@ -0,0 +1,99 @@
+/* oneofrule.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public static void main () {
+       var settings = new Valadoc.Settings ();
+       var scanner = new TestScanner ();
+       var reporter = new ErrorReporter ();
+       var parser = new Parser (settings, scanner, reporter);
+       scanner.set_parser (parser);
+
+       Rule rule = Rule.one_of ({
+                       Valadoc.TokenType.EQUAL_1,
+                       Valadoc.TokenType.EQUAL_2,
+                       Valadoc.TokenType.EQUAL_3,
+               });
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_2
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_3
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // negative test:
+       bool reached = false;
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_4
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+}
+
diff --git a/tests/libvaladoc/parser/optionalrule.vala b/tests/libvaladoc/parser/optionalrule.vala
new file mode 100644 (file)
index 0000000..b7b68ea
--- /dev/null
@@ -0,0 +1,84 @@
+/* optionalrule.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public static void main () {
+       var settings = new Valadoc.Settings ();
+       var scanner = new TestScanner ();
+       var reporter = new ErrorReporter ();
+       var parser = new Parser (settings, scanner, reporter);
+       scanner.set_parser (parser);
+
+       Rule rule = Rule.option ({
+                       Valadoc.TokenType.EQUAL_1
+               });
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // negative test:
+       bool reached = false;
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_2
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+}
+
+
diff --git a/tests/libvaladoc/parser/sequencerule.vala b/tests/libvaladoc/parser/sequencerule.vala
new file mode 100644 (file)
index 0000000..13b4eec
--- /dev/null
@@ -0,0 +1,103 @@
+/* sequencerule.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public static void main () {
+       var settings = new Valadoc.Settings ();
+       var scanner = new TestScanner ();
+       var reporter = new ErrorReporter ();
+       var parser = new Parser (settings, scanner, reporter);
+       scanner.set_parser (parser);
+
+       Rule rule = Rule.seq ({
+                       Valadoc.TokenType.EQUAL_1,
+                       Valadoc.TokenType.EQUAL_2,
+                       Valadoc.TokenType.EQUAL_3,
+                       Valadoc.TokenType.EQUAL_4,
+                       Valadoc.TokenType.EQUAL_5
+               });
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_2,
+                               Valadoc.TokenType.EQUAL_3,
+                               Valadoc.TokenType.EQUAL_4,
+                               Valadoc.TokenType.EQUAL_5
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // negative test:
+       bool reached = false;
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_2,
+                               Valadoc.TokenType.EQUAL_3
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+
+
+
+       // negative test:
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_2,
+                               Valadoc.TokenType.EQUAL_4,
+                               Valadoc.TokenType.EQUAL_3,
+                               Valadoc.TokenType.EQUAL_5
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+
+}
+
+
diff --git a/tests/libvaladoc/parser/stubrule.vala b/tests/libvaladoc/parser/stubrule.vala
new file mode 100644 (file)
index 0000000..6a097fd
--- /dev/null
@@ -0,0 +1,92 @@
+/* stubrule.vala
+ *
+ * Copyright (C) 2012       Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Florian Brosch <flo.brosch@gmail.com>
+ */
+
+using Valadoc;
+
+
+public static void main () {
+       var settings = new Valadoc.Settings ();
+       var scanner = new TestScanner ();
+       var reporter = new ErrorReporter ();
+       var parser = new Parser (settings, scanner, reporter);
+       scanner.set_parser (parser);
+
+       StubRule rule = new StubRule ();
+
+       Rule inner_rule = Rule.many ({
+                       Valadoc.TokenType.EQUAL_1
+               });
+
+       rule.set_rule (inner_rule);
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // positive test:
+       try {
+               parser.set_root_rule (rule);
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               assert_not_reached ();
+       }
+
+
+       // negative test:
+       bool reached = false;
+       try {
+               parser.set_root_rule (rule);
+               reached = false;
+
+               scanner.set_pattern ({
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_1,
+                               Valadoc.TokenType.EQUAL_2
+                       });
+
+               parser.parse ("", "", 0, 0);
+       } catch (Error e) {
+               reached = true;
+       }
+
+       assert (reached);
+}
+
+
index 70fe8b433f1e7966198f6b1d8234ed091cfdd522..7eb43fff90a6b1a8fb40167a85b7cc708fd901c2 100755 (executable)
@@ -30,7 +30,7 @@ export G_DEBUG=fatal_warnings
 export PKG_CONFIG_PATH=../../src/libvaladoc
 
 VALAC=valac
-VALAFLAGS="--vapidir ../../src/libvaladoc --pkg valadoc-1.0 --pkg gee-1.0 --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -L../../src/libvaladoc/.libs -X -I../../src/libvaladoc"
+VALAFLAGS="--vapidir ../../src/libvaladoc --pkg valadoc-1.0 --pkg gee-1.0 --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -L../../src/libvaladoc/.libs -X -I../../src/libvaladoc ../helpers.vala"
 VAPIGEN=$topbuilddir/vapigen/vapigen
 VAPIGENFLAGS=