use crate::repl::tests::{fail_test, run_test, TestResult}; use rstest::rstest; #[test] fn list_annotations() -> TestResult { let input = "def run [list: list] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_unknown_prefix() -> TestResult { let input = "def run [list: listint>] {$list | length}; run [2 5 4]"; let expected = "unknown type"; fail_test(input, expected) } #[test] fn list_annotations_empty_1() -> TestResult { let input = "def run [list: list] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_empty_2() -> TestResult { let input = "def run [list: list<>] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_empty_3() -> TestResult { let input = "def run [list: list< >] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_empty_4() -> TestResult { let input = "def run [list: list<\n>] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_nested() -> TestResult { let input = "def run [list: list>] {$list | length}; run [ [2.0] [5.0] [4.0]]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_unknown_inner_type() -> TestResult { let input = "def run [list: list] {$list | length}; run ['nushell' 'nunu' 'nana']"; let expected = "unknown type"; fail_test(input, expected) } #[test] fn list_annotations_nested_unknown_inner() -> TestResult { let input = "def run [list: list>] {$list | length}; run [ [nushell] [nunu] [nana]]"; let expected = "unknown type"; fail_test(input, expected) } #[test] fn list_annotations_unterminated() -> TestResult { let input = "def run [list: list TestResult { let input = "def run [list: list] {$list | length}; run [2 5 4]"; let expected = "expected closing >"; fail_test(input, expected) } #[test] fn list_annotations_space_within_1() -> TestResult { let input = "def run [list: list< range>] {$list | length}; run [2..32 5..<64 4..128]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_space_within_2() -> TestResult { let input = "def run [list: list] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_space_within_3() -> TestResult { let input = "def run [list: list< int >] {$list | length}; run [2 5 4]"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_space_before() -> TestResult { let input = "def run [list: list ] {$list | length}; run [2 5 4]"; let expected = "expected valid variable name for this parameter"; fail_test(input, expected) } #[test] fn list_annotations_unknown_separators() -> TestResult { let input = "def run [list: list] {$list | length}; run [2 5 4]"; let expected = "unknown type"; fail_test(input, expected) } #[test] fn list_annotations_with_default_val_1() -> TestResult { let input = "def run [list: list = [2 5 4]] {$list | length}; run"; let expected = "3"; run_test(input, expected) } #[test] fn list_annotations_with_default_val_2() -> TestResult { let input = "def run [list: list = [2 5 4]] {$list | length}; run"; let expected = "Default value wrong type"; fail_test(input, expected) } #[test] fn list_annotations_with_extra_characters() -> TestResult { let input = "def run [list: listextra] {$list | length}; run [1 2 3]"; let expected = "Extra characters in the parameter name"; fail_test(input, expected) } #[test] fn record_annotations_none() -> TestResult { let input = "def run [rec: record] { $rec }; run {} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations() -> TestResult { let input = "def run [rec: record] { $rec }; run {age: 3} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_two_types() -> TestResult { let input = "def run [rec: record] { $rec }; run {name: nushell age: 3} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_two_types_comma_sep() -> TestResult { let input = "def run [rec: record] { $rec }; run {name: nushell age: 3} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_key_with_no_type() -> TestResult { let input = "def run [rec: record] { $rec }; run {name: nushell} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_two_types_one_with_no_type() -> TestResult { let input = "def run [rec: record] { $rec }; run {name: nushell age: 3} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_two_types_both_with_no_types() -> TestResult { let input = "def run [rec: record] { $rec }; run {name: nushell age: 3} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_nested() -> TestResult { let input = "def run [ err: record< msg: string, label: record< text: string start: int, end: int, >> ] { $err }; run { msg: 'error message' label: { text: 'here is the error' start: 0 end: 69 } } | describe"; let expected = "record>"; run_test(input, expected) } #[test] fn record_annotations_type_inference_1() -> TestResult { let input = "def run [rec: record] { $rec }; run {age: 2wk} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_type_inference_2() -> TestResult { let input = "def run [rec: record] { $rec }; run {size: 2mb} | describe"; let expected = "record"; run_test(input, expected) } #[test] fn record_annotations_not_terminated() -> TestResult { let input = "def run [rec: record TestResult { let input = "def run [rec: record] { $rec }"; let expected = "expected closing >"; fail_test(input, expected) } #[test] fn record_annotations_no_type_after_colon() -> TestResult { let input = "def run [rec: record] { $rec }"; let expected = "type after colon"; fail_test(input, expected) } #[test] fn record_annotations_type_mismatch_key() -> TestResult { let input = "def run [rec: record] { $rec }; run {nme: nushell}"; let expected = "expected record, found record"; fail_test(input, expected) } #[test] fn record_annotations_type_mismatch_shape() -> TestResult { let input = "def run [rec: record] { $rec }; run {age: 2wk}"; let expected = "expected record, found record"; fail_test(input, expected) } #[test] fn record_annotations_with_extra_characters() -> TestResult { let input = "def run [list: recordextra] {$list | length}; run [1 2 3]"; let expected = "Extra characters in the parameter name"; fail_test(input, expected) } #[test] fn table_annotations_none() -> TestResult { let input = "def run [t: table] { $t }; run [[]; []] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations() -> TestResult { let input = "def run [t: table] { $t }; run [[age]; [3]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_two_types() -> TestResult { let input = "\ def run [t: table] { $t }; run [[name, age]; [nushell, 3]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_two_types_comma_sep() -> TestResult { let input = "\ def run [t: table] { $t }; run [[name, age]; [nushell, 3]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_key_with_no_type() -> TestResult { let input = "def run [t: table] { $t }; run [[name]; [nushell]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_two_types_one_with_no_type() -> TestResult { let input = "\ def run [t: table] { $t }; run [[name, age]; [nushell, 3]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_two_types_both_with_no_types() -> TestResult { let input = "\ def run [t: table] { $t }; run [[name, age]; [nushell, 3]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_type_inference_1() -> TestResult { let input = "def run [t: table] { $t }; run [[age]; [2wk]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_type_inference_2() -> TestResult { let input = "def run [t: table] { $t }; run [[size]; [2mb]] | describe"; let expected = "table"; run_test(input, expected) } #[test] fn table_annotations_not_terminated() -> TestResult { let input = "def run [t: table TestResult { let input = "def run [t: table] { $t }"; let expected = "expected closing >"; fail_test(input, expected) } #[test] fn table_annotations_no_type_after_colon() -> TestResult { let input = "def run [t: table] { $t }"; let expected = "type after colon"; fail_test(input, expected) } #[test] fn table_annotations_type_mismatch_column() -> TestResult { let input = "def run [t: table] { $t }; run [[nme]; [nushell]]"; let expected = "expected table, found table"; fail_test(input, expected) } #[test] fn table_annotations_type_mismatch_shape() -> TestResult { let input = "def run [t: table] { $t }; run [[age]; [2wk]]"; let expected = "expected table, found table"; fail_test(input, expected) } #[test] fn table_annotations_with_extra_characters() -> TestResult { let input = "def run [t: tableextra] {$t | length}; run [[int]; [8]]"; let expected = "Extra characters in the parameter name"; fail_test(input, expected) } #[rstest] #[case("{ |a $a }")] #[case("{ |a, b $a + $b }")] #[case("do { |a $a } 1")] #[case("do { |a $a } 1 2")] fn closure_param_list_not_terminated(#[case] input: &str) -> TestResult { fail_test(input, "unclosed |") }