|
|
@ -3,7 +3,7 @@ use crate::parser::*; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_empty_function() { |
|
|
|
fn test_parse_empty_function() { |
|
|
|
let raw = "fn main() {}"; |
|
|
|
let raw = "main :: () {}"; |
|
|
|
let tokens = tokenize(raw); |
|
|
|
let tokens = tokenize(raw); |
|
|
|
let tree = parse(tokens, Some(raw.to_string())); |
|
|
|
let tree = parse(tokens, Some(raw.to_string())); |
|
|
|
assert!(tree.is_ok()) |
|
|
|
assert!(tree.is_ok()) |
|
|
@ -12,7 +12,7 @@ fn test_parse_empty_function() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_function_with_return() { |
|
|
|
fn test_parse_function_with_return() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -24,7 +24,7 @@ fn test_parse_function_with_return() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_missing_semicolon() { |
|
|
|
fn test_parse_missing_semicolon() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -46,12 +46,12 @@ fn test_parse_no_function_context() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_multiple_functions() { |
|
|
|
fn test_parse_multiple_functions() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn foo() { |
|
|
|
foo :: () { |
|
|
|
let x = 2; |
|
|
|
let x = 2; |
|
|
|
return x; |
|
|
|
return x; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn bar() { |
|
|
|
bar :: () { |
|
|
|
let y = 5; |
|
|
|
let y = 5; |
|
|
|
return y; |
|
|
|
return y; |
|
|
|
} |
|
|
|
} |
|
|
@ -64,7 +64,7 @@ fn test_parse_multiple_functions() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_variable_declaration() { |
|
|
|
fn test_parse_variable_declaration() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
let x = 1; |
|
|
|
let x = 1; |
|
|
|
return x; |
|
|
|
return x; |
|
|
|
} |
|
|
|
} |
|
|
@ -77,7 +77,7 @@ fn test_parse_variable_declaration() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_function_with_args() { |
|
|
|
fn test_parse_function_with_args() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main(foo) { |
|
|
|
main :: (foo) { |
|
|
|
return foo; |
|
|
|
return foo; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -89,11 +89,11 @@ fn test_parse_function_with_args() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_function_call() { |
|
|
|
fn test_parse_function_call() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main(foo) { |
|
|
|
main :: (foo) { |
|
|
|
foo(); |
|
|
|
foo(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn foo() { |
|
|
|
foo :: () { |
|
|
|
foo(2); |
|
|
|
foo(2); |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -105,11 +105,11 @@ fn test_parse_function_call() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_return_function_call() { |
|
|
|
fn test_parse_return_function_call() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return fib(2); |
|
|
|
return fib(2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn fib() { |
|
|
|
fib :: () { |
|
|
|
return fib(2); |
|
|
|
return fib(2); |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -121,11 +121,11 @@ fn test_parse_return_function_call() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_function_call_multiple_arguments() { |
|
|
|
fn test_parse_function_call_multiple_arguments() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
fib(1, 2, 3); |
|
|
|
fib(1, 2, 3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn fib() { |
|
|
|
fib :: () { |
|
|
|
return 2; |
|
|
|
return 2; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -137,11 +137,11 @@ fn test_parse_function_call_multiple_arguments() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_nexted_function_call() { |
|
|
|
fn test_parse_nexted_function_call() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
fib(fib(2), 2); |
|
|
|
fib(fib(2), 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn fib(n) { |
|
|
|
fib :: (n) { |
|
|
|
return 2; |
|
|
|
return 2; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -153,7 +153,7 @@ fn test_parse_nexted_function_call() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_basic_ops() { |
|
|
|
fn test_parse_basic_ops() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return 2 * 5; |
|
|
|
return 2 * 5; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -165,7 +165,7 @@ fn test_parse_basic_ops() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_compound_ops() { |
|
|
|
fn test_parse_compound_ops() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
2 * 5 / 3; |
|
|
|
2 * 5 / 3; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -177,7 +177,7 @@ fn test_parse_compound_ops() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_compound_ops_with_function_call() { |
|
|
|
fn test_parse_compound_ops_with_function_call() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return 2 * fib(1) / 3; |
|
|
|
return 2 * fib(1) / 3; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -189,7 +189,7 @@ fn test_parse_compound_ops_with_function_call() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_compound_ops_with_strings() { |
|
|
|
fn test_parse_compound_ops_with_strings() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main() { |
|
|
|
main :: () { |
|
|
|
return 2 * \"Hello\"; |
|
|
|
return 2 * \"Hello\"; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -201,7 +201,7 @@ fn test_parse_compound_ops_with_strings() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_compound_ops_with_identifier() { |
|
|
|
fn test_parse_compound_ops_with_identifier() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main(n) { |
|
|
|
main :: (n) { |
|
|
|
return 2 * n; |
|
|
|
return 2 * n; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -214,7 +214,7 @@ fn test_parse_compound_ops_with_identifier() { |
|
|
|
#[ignore] |
|
|
|
#[ignore] |
|
|
|
fn test_parse_compound_ops_with_identifier_first() { |
|
|
|
fn test_parse_compound_ops_with_identifier_first() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main(n) { |
|
|
|
main :: (n) { |
|
|
|
return n * 2; |
|
|
|
return n * 2; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
@ -226,7 +226,7 @@ fn test_parse_compound_ops_with_identifier_first() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_parse_compound_ops_return() { |
|
|
|
fn test_parse_compound_ops_return() { |
|
|
|
let raw = " |
|
|
|
let raw = " |
|
|
|
fn main(n) { |
|
|
|
main :: (n) { |
|
|
|
return 2 * n; |
|
|
|
return 2 * n; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
"; |
|
|
|