summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/fib.nim13
-rw-r--r--tests/src/negate.nim5
-rw-r--r--tests/test_parser.rs47
3 files changed, 46 insertions, 19 deletions
diff --git a/tests/src/fib.nim b/tests/src/fib.nim
new file mode 100644
index 0000000..34d38f0
--- /dev/null
+++ b/tests/src/fib.nim
@@ -0,0 +1,13 @@
+# fake nim
+
+func fib(x): int -> int =
+ if eq(x, 0):
+ 0
+ else:
+ if eq(x, 1):
+ 1
+ else: # comment
+ add(fib(sub(x, 1)), fib(sub(x, 2)))
+
+negate(negate(1))
+fib(5)
diff --git a/tests/src/negate.nim b/tests/src/negate.nim
new file mode 100644
index 0000000..c775e74
--- /dev/null
+++ b/tests/src/negate.nim
@@ -0,0 +1,5 @@
+func negate(x): bool -> bool =
+ if x:
+ 0
+ else:
+ 1
diff --git a/tests/test_parser.rs b/tests/test_parser.rs
index c619745..e33cdfa 100644
--- a/tests/test_parser.rs
+++ b/tests/test_parser.rs
@@ -52,43 +52,36 @@ fn test_complex_annotations() {
}
const program: &'static str =
-"func foo() =
- bar
- if this:
+"func foo(x): (int -> int) =
+ if this =
that
- else:
+ else =
this
hello
foo
bar
baz
-func foo =
+func foo: (bool -> int) =
this
- if that:
- then this
";
const lexed: &'static str =
-"func foo() = {
- bar;
- if this: {
+"func foo(x): (int -> int) = {
+ if this = {
that;
- }
- else: {
+ };
+ else = {
this;
- }
-}
+ };
+};
hello;
foo;
bar;
baz;
-func foo = {
+func foo: (bool -> int) = {
this;
- if that: {
- then this;
- }
-}";
+};";
#[test]
fn test_lexer() {
@@ -96,3 +89,19 @@ fn test_lexer() {
assert!(result.is_ok());
assert_eq!(result.unwrap(), lexed);
}
+
+#[test]
+fn test_parser() {
+ let result = parse_lang(lexed);
+ assert!(result.is_err());
+
+ let file = std::fs::read_to_string("tests/src/negate.nim");
+ assert!(file.is_ok());
+ let result = parse_lang(&file.unwrap());
+ assert!(result.is_err());
+
+ let file = std::fs::read_to_string("tests/src/fib.nim");
+ assert!(file.is_ok());
+ let result = parse_lang(&file.unwrap());
+ assert!(result.is_err());
+}