[valadoc] Add tests for libvaladoc/parser and gtkdoc-scanner
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] Add tests for libvaladoc/parser and gtkdoc-scanner
- Date: Fri, 17 Aug 2012 23:24:03 +0000 (UTC)
commit 74f52f6aa195af2df445e1e5887331f69542156b
Author: Florian Brosch <flo brosch gmail com>
Date: Mon Aug 13 03:06:46 2012 +0200
Add tests for libvaladoc/parser and gtkdoc-scanner
tests/Makefile.am | 6 +
tests/helpers.vala | 70 +++++++++
tests/libvaladoc/errorreporter.vala | 24 +++-
tests/libvaladoc/gtkdoc-scanner.vala | 225 +++++++++++++++++++++++++++++
tests/libvaladoc/parser/manyrule.vala | 90 ++++++++++++
tests/libvaladoc/parser/oneofrule.vala | 99 +++++++++++++
tests/libvaladoc/parser/optionalrule.vala | 84 +++++++++++
tests/libvaladoc/parser/sequencerule.vala | 103 +++++++++++++
tests/libvaladoc/parser/stubrule.vala | 92 ++++++++++++
tests/testrunner.sh | 2 +-
10 files changed, 793 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa3e37f..2885334 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 0000000..183bd5e
--- /dev/null
+++ b/tests/helpers.vala
@@ -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 "";
+ }
+}
+
diff --git a/tests/libvaladoc/errorreporter.vala b/tests/libvaladoc/errorreporter.vala
index 93ec7b4..2b77ffa 100644
--- a/tests/libvaladoc/errorreporter.vala
+++ b/tests/libvaladoc/errorreporter.vala
@@ -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
index 0000000..5144803
--- /dev/null
+++ b/tests/libvaladoc/gtkdoc-scanner.vala
@@ -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
index 0000000..2af76d3
--- /dev/null
+++ b/tests/libvaladoc/parser/manyrule.vala
@@ -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
index 0000000..fb77085
--- /dev/null
+++ b/tests/libvaladoc/parser/oneofrule.vala
@@ -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
index 0000000..b7b68ea
--- /dev/null
+++ b/tests/libvaladoc/parser/optionalrule.vala
@@ -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
index 0000000..13b4eec
--- /dev/null
+++ b/tests/libvaladoc/parser/sequencerule.vala
@@ -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
index 0000000..6a097fd
--- /dev/null
+++ b/tests/libvaladoc/parser/stubrule.vala
@@ -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);
+}
+
+
diff --git a/tests/testrunner.sh b/tests/testrunner.sh
index 70fe8b4..7eb43ff 100755
--- a/tests/testrunner.sh
+++ b/tests/testrunner.sh
@@ -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=
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]