Remove parse_ prefix from parse tests

This commit is contained in:
Richard Feldman 2019-05-27 16:55:13 -04:00
parent a9f5e258c6
commit ae53e611c7

View file

@ -53,12 +53,12 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_empty_string() { fn empty_string() {
expect_parsed_str("", "\"\""); expect_parsed_str("", "\"\"");
} }
#[test] #[test]
fn parse_string_without_escape() { fn string_without_escape() {
expect_parsed_str("a", "\"a\""); expect_parsed_str("a", "\"a\"");
expect_parsed_str("ab", "\"ab\""); expect_parsed_str("ab", "\"ab\"");
expect_parsed_str("abc", "\"abc\""); expect_parsed_str("abc", "\"abc\"");
@ -69,7 +69,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_string_with_special_escapes() { fn string_with_special_escapes() {
expect_parsed_str("x\\x", "\"x\\\\x\""); expect_parsed_str("x\\x", "\"x\\\\x\"");
expect_parsed_str("x\"x", "\"x\\\"x\""); expect_parsed_str("x\"x", "\"x\\\"x\"");
expect_parsed_str("x\tx", "\"x\\tx\""); expect_parsed_str("x\tx", "\"x\\tx\"");
@ -78,19 +78,19 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_string_with_single_qoute() { fn string_with_single_qoute() {
// This shoud NOT be escaped in a string. // This shoud NOT be escaped in a string.
expect_parsed_str("x'x", "\"x'x\""); expect_parsed_str("x'x", "\"x'x\"");
} }
#[test] #[test]
fn parse_string_with_valid_unicode_escapes() { fn string_with_valid_unicode_escapes() {
expect_parsed_str("x\u{00A0}x", "\"x\\u{00A0}x\""); expect_parsed_str("x\u{00A0}x", "\"x\\u{00A0}x\"");
expect_parsed_str("x\u{101010}x", "\"x\\u{101010}x\""); expect_parsed_str("x\u{101010}x", "\"x\\u{101010}x\"");
} }
#[test] #[test]
fn parse_string_with_invalid_unicode_escapes() { fn string_with_invalid_unicode_escapes() {
// Should be too big - max size should be 10FFFF. // Should be too big - max size should be 10FFFF.
// (Rust has this restriction. I assume it's a good idea.) // (Rust has this restriction. I assume it's a good idea.)
expect_parsed_str_error("\"x\\u{110000}x\""); expect_parsed_str_error("\"x\\u{110000}x\"");
@ -122,7 +122,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_empty_char() { fn empty_char() {
match easy_parse_standalone("''") { match easy_parse_standalone("''") {
Ok(_) => panic!("Expected parse error"), Ok(_) => panic!("Expected parse error"),
Err(err) => { Err(err) => {
@ -139,14 +139,14 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_char_without_escape() { fn char_without_escape() {
expect_parsed_char('a', "'a'"); expect_parsed_char('a', "'a'");
expect_parsed_char('1', "'1'"); expect_parsed_char('1', "'1'");
expect_parsed_char(' ', "' '"); expect_parsed_char(' ', "' '");
} }
#[test] #[test]
fn parse_char_with_special_escapes() { fn char_with_special_escapes() {
expect_parsed_char('\\', "'\\\\'"); expect_parsed_char('\\', "'\\\\'");
expect_parsed_char('\'', "'\\''"); expect_parsed_char('\'', "'\\''");
expect_parsed_char('\t', "'\\t'"); expect_parsed_char('\t', "'\\t'");
@ -155,19 +155,19 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_char_with_double_qoute() { fn char_with_double_qoute() {
// This shoud NOT be escaped in a char. // This shoud NOT be escaped in a char.
expect_parsed_char('"', "'\"'"); expect_parsed_char('"', "'\"'");
} }
#[test] #[test]
fn parse_char_with_unicode_escapes() { fn char_with_unicode_escapes() {
expect_parsed_char('\u{00A0}', "'\\u{00A0}'"); expect_parsed_char('\u{00A0}', "'\\u{00A0}'");
expect_parsed_char('\u{101010}', "'\\u{101010}'"); expect_parsed_char('\u{101010}', "'\\u{101010}'");
} }
#[test] #[test]
fn parse_char_with_invalid_unicode_escapes() { fn char_with_invalid_unicode_escapes() {
// Should be too big - max size should be 10FFFF. // Should be too big - max size should be 10FFFF.
// (Rust has this rechariction. I assume it's a good idea.) // (Rust has this rechariction. I assume it's a good idea.)
expect_parsed_char_error("\"x\\u{110000}x\""); expect_parsed_char_error("\"x\\u{110000}x\"");
@ -196,35 +196,35 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_positive_int() { fn positive_int() {
expect_parsed_int(1234, "1234"); expect_parsed_int(1234, "1234");
} }
#[test] #[test]
fn parse_negative_int() { fn negative_int() {
expect_parsed_int(-1234, "-1234"); expect_parsed_int(-1234, "-1234");
} }
#[test] #[test]
fn parse_positive_ratio() { fn positive_ratio() {
expect_parsed_ratio(12345, 100, "123.45"); expect_parsed_ratio(12345, 100, "123.45");
expect_parsed_ratio(4200, 100, "42.00"); expect_parsed_ratio(4200, 100, "42.00");
} }
#[test] #[test]
fn parse_negative_ratio() { fn negative_ratio() {
expect_parsed_ratio(-1234567, 1000, "-1234.567"); expect_parsed_ratio(-1234567, 1000, "-1234.567");
expect_parsed_ratio(-1920, 10, "-192.0"); expect_parsed_ratio(-1920, 10, "-192.0");
} }
#[test] #[test]
fn parse_ints_with_spaces() { fn ints_with_spaces() {
expect_parsed_int(987654321, "987 6 5 432 1"); expect_parsed_int(987654321, "987 6 5 432 1");
expect_parsed_int(-1234567890, "-1 234 567 890"); expect_parsed_int(-1234567890, "-1 234 567 890");
} }
#[test] #[test]
fn parse_ratios_with_spaces() { fn ratios_with_spaces() {
expect_parsed_ratio(-1234567, 1000, "-1 23 4.567"); expect_parsed_ratio(-1234567, 1000, "-1 23 4.567");
expect_parsed_ratio(-1920, 10, "-19 2.0"); expect_parsed_ratio(-1920, 10, "-19 2.0");
expect_parsed_ratio(12345, 100, "1 2 3.45"); expect_parsed_ratio(12345, 100, "1 2 3.45");
@ -232,7 +232,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_single_operator_with_var() { fn single_operator_with_var() {
assert_eq!( assert_eq!(
// It's important that this isn't mistaken for // It's important that this isn't mistaken for
// a declaration like (x = 1) // a declaration like (x = 1)
@ -247,7 +247,7 @@ mod parse_tests {
#[test] #[test]
fn parse_single_operator() { fn single_operator() {
match parse_standalone("1234 + 567") { match parse_standalone("1234 + 567") {
Ok((Operator(v1, op, v2), "")) => { Ok((Operator(v1, op, v2), "")) => {
assert_eq!(*v1, Int(1234)); assert_eq!(*v1, Int(1234));
@ -260,7 +260,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_multiple_operators() { fn multiple_operators() {
assert_eq!(parse_standalone("1 + 2 * 3"), assert_eq!(parse_standalone("1 + 2 * 3"),
Ok((Operator( Ok((Operator(
Box::new(Int(1)), Box::new(Int(1)),
@ -271,7 +271,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_operators_with_parens() { fn operators_with_parens() {
assert_eq!(parse_standalone("(1 + 2)"), assert_eq!(parse_standalone("(1 + 2)"),
Ok((Operator( Ok((Operator(
Box::new(Int(1)), Box::new(Int(1)),
@ -338,7 +338,7 @@ mod parse_tests {
#[test] #[test]
fn parse_var() { fn var() {
expect_parsed_var("x"); expect_parsed_var("x");
expect_parsed_var("x2"); expect_parsed_var("x2");
expect_parsed_var("foo"); expect_parsed_var("foo");
@ -346,7 +346,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_invalid_var() { fn invalid_var() {
expect_parsed_var_error("5x"); expect_parsed_var_error("5x");
expect_parsed_var_error("2foo2furious"); expect_parsed_var_error("2foo2furious");
expect_parsed_var_error("2Foo2Furious"); expect_parsed_var_error("2Foo2Furious");
@ -376,7 +376,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_apply() { fn apply() {
expect_parsed_apply( expect_parsed_apply(
"(x) y", "(x) y",
Var("x".to_string()), Var("x".to_string()),
@ -403,7 +403,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_invalid_apply() { fn invalid_apply() {
expect_parsed_apply_error("(x 5)y"); expect_parsed_apply_error("(x 5)y");
} }
@ -437,21 +437,21 @@ mod parse_tests {
#[test] #[test]
fn parse_single_arg_func() { fn single_arg_func() {
expect_parsed_func("f 1", "f", vec![Int(1)]); expect_parsed_func("f 1", "f", vec![Int(1)]);
expect_parsed_func("foo bar", "foo", vec![Var("bar".to_string())]); expect_parsed_func("foo bar", "foo", vec![Var("bar".to_string())]);
expect_parsed_func("foo \"hi\"", "foo", vec![Str("hi".to_string())]); expect_parsed_func("foo \"hi\"", "foo", vec![Str("hi".to_string())]);
} }
#[test] #[test]
fn parse_multi_arg_func() { fn multi_arg_func() {
expect_parsed_func("f 1, 23, 456", "f", vec![Int(1), Int(23), Int(456)]); expect_parsed_func("f 1, 23, 456", "f", vec![Int(1), Int(23), Int(456)]);
expect_parsed_func("foo bar, 'z'", "foo", vec![Var("bar".to_string()), Char('z')]); expect_parsed_func("foo bar, 'z'", "foo", vec![Var("bar".to_string()), Char('z')]);
expect_parsed_func("foo \"hi\", 1, blah", "foo", vec![Str("hi".to_string()), Int(1), Var("blah".to_string())]); expect_parsed_func("foo \"hi\", 1, blah", "foo", vec![Str("hi".to_string()), Int(1), Var("blah".to_string())]);
} }
#[test] #[test]
fn parse_func_with_operator() { fn func_with_operator() {
assert_eq!( assert_eq!(
parse_standalone("f 5 + 6"), parse_standalone("f 5 + 6"),
Ok( Ok(
@ -471,7 +471,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_func_with_operator_and_multiple_args() { fn func_with_operator_and_multiple_args() {
assert_eq!( assert_eq!(
parse_standalone("f 1, 2, 3 + 6"), parse_standalone("f 1, 2, 3 + 6"),
Ok( Ok(
@ -492,7 +492,7 @@ mod parse_tests {
#[test] #[test]
fn parse_invalid_func() { fn invalid_func() {
expect_parsed_func_syntax_problem("1 f"); expect_parsed_func_syntax_problem("1 f");
expect_parsed_func_syntax_problem("(1 f)"); expect_parsed_func_syntax_problem("(1 f)");
} }
@ -500,7 +500,7 @@ mod parse_tests {
// PARENS // PARENS
#[test] #[test]
fn parse_parens() { fn parens() {
expect_parsed_int(1, "(1)"); expect_parsed_int(1, "(1)");
expect_parsed_int(-2, "((-2))"); expect_parsed_int(-2, "((-2))");
expect_parsed_str("a", "(\"a\")"); expect_parsed_str("a", "(\"a\")");
@ -511,7 +511,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_invalid_parens_func() { fn invalid_parens_func() {
expect_parsed_func_error("(1 f"); expect_parsed_func_error("(1 f");
expect_parsed_func_error("(f 1"); expect_parsed_func_error("(f 1");
} }
@ -519,7 +519,7 @@ mod parse_tests {
// IF // IF
#[test] #[test]
fn parse_indented_if() { fn indented_if() {
assert_eq!( assert_eq!(
parse_standalone("if 12 34 5 then\n 5 4 32 1\n else 1 3 37"), parse_standalone("if 12 34 5 then\n 5 4 32 1\n else 1 3 37"),
Ok( Ok(
@ -535,7 +535,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_if_space_separated_number() { fn if_space_separated_number() {
assert_eq!( assert_eq!(
parse_standalone("if 12 34 5 then 5 4 32 1 else 1 3 37"), parse_standalone("if 12 34 5 then 5 4 32 1 else 1 3 37"),
Ok( Ok(
@ -551,7 +551,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_if() { fn single_line_if() {
assert_eq!( assert_eq!(
parse_standalone("if foo then 1 else 2"), parse_standalone("if foo then 1 else 2"),
Ok( Ok(
@ -569,7 +569,7 @@ mod parse_tests {
// COMPLEX EXPRESSIONS // COMPLEX EXPRESSIONS
#[test] #[test]
fn parse_complex_expressions() { fn complex_expressions() {
expect_parsed_apply( expect_parsed_apply(
"(x 5) (y + (f 6))", "(x 5) (y + (f 6))",
Func("x".to_string(), vec![Int(5)]), Func("x".to_string(), vec![Int(5)]),
@ -674,7 +674,7 @@ mod parse_tests {
// LET // LET
#[test] #[test]
fn parse_let_returning_number() { fn let_returning_number() {
assert_eq!( assert_eq!(
// let x = 5 in -10 // let x = 5 in -10
parse_standalone("x = 5\n-10"), parse_standalone("x = 5\n-10"),
@ -695,7 +695,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_let_with_operator() { fn let_with_operator() {
assert_eq!( assert_eq!(
// let x = 5 + 10 in -20 // let x = 5 + 10 in -20
parse_standalone("x =(5 + 10)\n-20"), parse_standalone("x =(5 + 10)\n-20"),
@ -731,7 +731,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_invalid_let_returning_number() { fn invalid_let_returning_number() {
assert!( assert!(
parse_standalone("x=5\n -10").is_err(), parse_standalone("x=5\n -10").is_err(),
"Expected parsing error" "Expected parsing error"
@ -739,7 +739,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_nested_let() { fn nested_let() {
assert_eq!( assert_eq!(
// let x = 5 in let y = 12 in 3 // let x = 5 in let y = 12 in 3
parse_standalone("x = 5\ny = 12\n3"), parse_standalone("x = 5\ny = 12\n3"),
@ -779,7 +779,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_let_returning_var() { fn let_returning_var() {
assert_eq!( assert_eq!(
parse_standalone("x=5\nx"), parse_standalone("x=5\nx"),
Ok(( Ok((
@ -790,7 +790,7 @@ mod parse_tests {
} }
#[test] #[test]
fn parse_bad_equals_indent_let() { fn bad_equals_indent_let() {
assert!( assert!(
parse_standalone(" x=\n5\n\n5").is_err(), parse_standalone(" x=\n5\n\n5").is_err(),
"Expected parsing error" "Expected parsing error"