|
|
|
@ -13,7 +13,7 @@ fn test_parse_empty_function() {
|
|
|
|
|
fn test_parse_function_with_return() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return 1; |
|
|
|
|
return 1 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -22,10 +22,10 @@ fn test_parse_function_with_return() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_parse_missing_semicolon() { |
|
|
|
|
fn test_parse_redundant_semicolon() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return 1 |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -36,7 +36,7 @@ fn test_parse_missing_semicolon() {
|
|
|
|
|
#[test] |
|
|
|
|
fn test_parse_no_function_context() { |
|
|
|
|
let raw = " |
|
|
|
|
let x = 1; |
|
|
|
|
let x = 1 |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
|
let tree = parse(tokens, Some(raw.to_string())); |
|
|
|
@ -47,13 +47,13 @@ fn test_parse_no_function_context() {
|
|
|
|
|
fn test_parse_multiple_functions() { |
|
|
|
|
let raw = " |
|
|
|
|
foo :: () { |
|
|
|
|
let x = 2; |
|
|
|
|
return x; |
|
|
|
|
let x = 2 |
|
|
|
|
return x |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bar :: () { |
|
|
|
|
let y = 5; |
|
|
|
|
return y; |
|
|
|
|
let y = 5 |
|
|
|
|
return y |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -65,8 +65,8 @@ fn test_parse_multiple_functions() {
|
|
|
|
|
fn test_parse_variable_declaration() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
let x = 1; |
|
|
|
|
return x; |
|
|
|
|
let x = 1 |
|
|
|
|
return x |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -78,7 +78,7 @@ fn test_parse_variable_declaration() {
|
|
|
|
|
fn test_parse_function_with_args() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: (foo) { |
|
|
|
|
return foo; |
|
|
|
|
return foo |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -90,11 +90,11 @@ fn test_parse_function_with_args() {
|
|
|
|
|
fn test_parse_function_call() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: (foo) { |
|
|
|
|
foo(); |
|
|
|
|
foo() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foo :: () { |
|
|
|
|
foo(2); |
|
|
|
|
foo(2) |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -106,11 +106,11 @@ fn test_parse_function_call() {
|
|
|
|
|
fn test_parse_return_function_call() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return fib(2); |
|
|
|
|
return fib(2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fib :: () { |
|
|
|
|
return fib(2); |
|
|
|
|
return fib(2) |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -122,11 +122,11 @@ fn test_parse_return_function_call() {
|
|
|
|
|
fn test_parse_function_call_multiple_arguments() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
fib(1, 2, 3); |
|
|
|
|
fib(1, 2, 3) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fib :: () { |
|
|
|
|
return 2; |
|
|
|
|
return 2 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -138,11 +138,11 @@ fn test_parse_function_call_multiple_arguments() {
|
|
|
|
|
fn test_parse_nexted_function_call() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
fib(fib(2), 2); |
|
|
|
|
fib(fib(2), 2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fib :: (n) { |
|
|
|
|
return 2; |
|
|
|
|
return 2 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -154,7 +154,7 @@ fn test_parse_nexted_function_call() {
|
|
|
|
|
fn test_parse_basic_ops() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return 2 * 5; |
|
|
|
|
return 2 * 5 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -166,7 +166,7 @@ fn test_parse_basic_ops() {
|
|
|
|
|
fn test_parse_compound_ops() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
2 * 5 / 3; |
|
|
|
|
2 * 5 / 3 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -178,7 +178,7 @@ fn test_parse_compound_ops() {
|
|
|
|
|
fn test_parse_compound_ops_with_function_call() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return 2 * fib(1) / 3; |
|
|
|
|
return 2 * fib(1) / 3 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -190,7 +190,7 @@ fn test_parse_compound_ops_with_function_call() {
|
|
|
|
|
fn test_parse_compound_ops_with_strings() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: () { |
|
|
|
|
return 2 * \"Hello\"; |
|
|
|
|
return 2 * \"Hello\" |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -202,7 +202,7 @@ fn test_parse_compound_ops_with_strings() {
|
|
|
|
|
fn test_parse_compound_ops_with_identifier() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: (n) { |
|
|
|
|
return 2 * n; |
|
|
|
|
return 2 * n |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -215,7 +215,7 @@ fn test_parse_compound_ops_with_identifier() {
|
|
|
|
|
fn test_parse_compound_ops_with_identifier_first() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: (n) { |
|
|
|
|
return n * 2; |
|
|
|
|
return n * 2 |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
@ -227,7 +227,7 @@ fn test_parse_compound_ops_with_identifier_first() {
|
|
|
|
|
fn test_parse_compound_ops_return() { |
|
|
|
|
let raw = " |
|
|
|
|
main :: (n) { |
|
|
|
|
return 2 * n; |
|
|
|
|
return 2 * n |
|
|
|
|
} |
|
|
|
|
"; |
|
|
|
|
let tokens = tokenize(raw); |
|
|
|
|