From 274faf1e0a7e75da0c15fdf51264f907ee30ceec Mon Sep 17 00:00:00 2001 From: Moritz Gmeiner Date: Mon, 2 Sep 2024 15:35:28 +0200 Subject: [PATCH] autogenerate test suite --- interpreter/Cargo.toml | 2 +- interpreter/build.rs | 48 + interpreter/tests/all_tests.rs | 517 +++--- interpreter/tests/common/mod.rs | 46 +- interpreter/tests/lox/run.t | 1446 ----------------- .../tests/lox/unexpected_character.lox | 3 - .../lox/variable/collide_with_parameter.lox | 2 +- 7 files changed, 332 insertions(+), 1732 deletions(-) create mode 100644 interpreter/build.rs delete mode 100644 interpreter/tests/lox/run.t delete mode 100644 interpreter/tests/lox/unexpected_character.lox diff --git a/interpreter/Cargo.toml b/interpreter/Cargo.toml index ee19381..6178ae5 100644 --- a/interpreter/Cargo.toml +++ b/interpreter/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies.rlox2-frontend] path = "../frontend" -[dev-dependencies] +[build-dependencies] glob = "0.3" [dependencies] diff --git a/interpreter/build.rs b/interpreter/build.rs new file mode 100644 index 0000000..533ef6b --- /dev/null +++ b/interpreter/build.rs @@ -0,0 +1,48 @@ +use std::path::PathBuf; + +use glob::glob; + +fn main() { + generate_tests(); +} + +fn build_test_case(path: PathBuf) -> String { + let mut test_name = path.clone(); + test_name.set_extension(""); + + let mut components = test_name.components(); + + components.next(); + components.next(); + + let mut test_name = components.as_path().to_str().unwrap().to_owned(); + + test_name = test_name.replace('/', "_"); + + format!( + "\n\n#[test] +fn test_{}() {{ + run_test(\"{}\"); +}}", + test_name, + path.to_str().unwrap() + ) +} + +fn generate_tests() { + let preamble = "mod common;\n\nuse common::run_test;"; + + let mut output = preamble.to_owned(); + + for lox_file in glob("tests/lox/**/*.lox").unwrap() { + let lox_file = lox_file.unwrap(); + + println!("found lox file: {}", lox_file.to_str().unwrap()); + + output += &build_test_case(lox_file); + } + + println!("{output}"); + + std::fs::write("tests/all_tests.rs", output).unwrap(); +} diff --git a/interpreter/tests/all_tests.rs b/interpreter/tests/all_tests.rs index f22c6ba..4dd5074 100644 --- a/interpreter/tests/all_tests.rs +++ b/interpreter/tests/all_tests.rs @@ -3,1261 +3,1256 @@ mod common; use common::run_test; #[test] -fn test_lox_assignment_associativity() { +fn test_assignment_associativity() { run_test("tests/lox/assignment/associativity.lox"); } #[test] -fn test_lox_assignment_global() { +fn test_assignment_global() { run_test("tests/lox/assignment/global.lox"); } #[test] -fn test_lox_assignment_grouping() { +fn test_assignment_grouping() { run_test("tests/lox/assignment/grouping.lox"); } #[test] -fn test_lox_assignment_infix_operator() { +fn test_assignment_infix_operator() { run_test("tests/lox/assignment/infix_operator.lox"); } #[test] -fn test_lox_assignment_local() { +fn test_assignment_local() { run_test("tests/lox/assignment/local.lox"); } #[test] -fn test_lox_assignment_prefix_operator() { +fn test_assignment_prefix_operator() { run_test("tests/lox/assignment/prefix_operator.lox"); } #[test] -fn test_lox_assignment_syntax() { +fn test_assignment_syntax() { run_test("tests/lox/assignment/syntax.lox"); } #[test] -fn test_lox_assignment_to_this() { +fn test_assignment_to_this() { run_test("tests/lox/assignment/to_this.lox"); } #[test] -fn test_lox_assignment_undefined() { +fn test_assignment_undefined() { run_test("tests/lox/assignment/undefined.lox"); } #[test] -fn test_lox_block_empty() { +fn test_block_empty() { run_test("tests/lox/block/empty.lox"); } #[test] -fn test_lox_block_scope() { +fn test_block_scope() { run_test("tests/lox/block/scope.lox"); } #[test] -fn test_lox_bool_equality() { +fn test_bool_equality() { run_test("tests/lox/bool/equality.lox"); } #[test] -fn test_lox_bool_not() { +fn test_bool_not() { run_test("tests/lox/bool/not.lox"); } #[test] -fn test_lox_break_for() { +fn test_break_for() { run_test("tests/lox/break/for.lox"); } #[test] -fn test_lox_break_outside_loop() { +fn test_break_outside_loop() { run_test("tests/lox/break/outside_loop.lox"); } #[test] -fn test_lox_break_while() { +fn test_break_while() { run_test("tests/lox/break/while.lox"); } #[test] -fn test_lox_call_bool() { +fn test_call_bool() { run_test("tests/lox/call/bool.lox"); } #[test] -fn test_lox_call_nil() { +fn test_call_nil() { run_test("tests/lox/call/nil.lox"); } #[test] -fn test_lox_call_num() { +fn test_call_num() { run_test("tests/lox/call/num.lox"); } #[test] -fn test_lox_call_object() { +fn test_call_object() { run_test("tests/lox/call/object.lox"); } #[test] -fn test_lox_call_string() { +fn test_call_string() { run_test("tests/lox/call/string.lox"); } #[test] -fn test_lox_class_empty() { +fn test_class_empty() { run_test("tests/lox/class/empty.lox"); } #[test] -fn test_lox_class_inherit_self() { +fn test_class_inherit_self() { run_test("tests/lox/class/inherit_self.lox"); } #[test] -fn test_lox_class_inherited_method() { +fn test_class_inherited_method() { run_test("tests/lox/class/inherited_method.lox"); } #[test] -fn test_lox_class_local_inherit_other() { +fn test_class_local_inherit_other() { run_test("tests/lox/class/local_inherit_other.lox"); } #[test] -fn test_lox_class_local_inherit_self() { +fn test_class_local_inherit_self() { run_test("tests/lox/class/local_inherit_self.lox"); } #[test] -fn test_lox_class_local_reference_self() { +fn test_class_local_reference_self() { run_test("tests/lox/class/local_reference_self.lox"); } #[test] -fn test_lox_class_reference_self() { +fn test_class_reference_self() { run_test("tests/lox/class/reference_self.lox"); } #[test] -fn test_lox_closure_assign_to_closure() { +fn test_closure_assign_to_closure() { run_test("tests/lox/closure/assign_to_closure.lox"); } #[test] -fn test_lox_closure_assign_to_shadowed_later() { +fn test_closure_assign_to_shadowed_later() { run_test("tests/lox/closure/assign_to_shadowed_later.lox"); } #[test] -fn test_lox_closure_close_over_function_parameter() { +fn test_closure_close_over_function_parameter() { run_test("tests/lox/closure/close_over_function_parameter.lox"); } #[test] -fn test_lox_closure_close_over_later_variable() { +fn test_closure_close_over_later_variable() { run_test("tests/lox/closure/close_over_later_variable.lox"); } #[test] -fn test_lox_closure_close_over_method_parameter() { +fn test_closure_close_over_method_parameter() { run_test("tests/lox/closure/close_over_method_parameter.lox"); } #[test] -fn test_lox_closure_closed_closure_in_function() { +fn test_closure_closed_closure_in_function() { run_test("tests/lox/closure/closed_closure_in_function.lox"); } #[test] -fn test_lox_closure_nested_closure() { +fn test_closure_nested_closure() { run_test("tests/lox/closure/nested_closure.lox"); } #[test] -fn test_lox_closure_open_closure_in_function() { +fn test_closure_open_closure_in_function() { run_test("tests/lox/closure/open_closure_in_function.lox"); } #[test] -fn test_lox_closure_reference_closure_multiple_times() { +fn test_closure_reference_closure_multiple_times() { run_test("tests/lox/closure/reference_closure_multiple_times.lox"); } #[test] -fn test_lox_closure_reuse_closure_slot() { +fn test_closure_reuse_closure_slot() { run_test("tests/lox/closure/reuse_closure_slot.lox"); } #[test] -fn test_lox_closure_shadow_closure_with_local() { +fn test_closure_shadow_closure_with_local() { run_test("tests/lox/closure/shadow_closure_with_local.lox"); } #[test] -fn test_lox_closure_unused_closure() { +fn test_closure_unused_closure() { run_test("tests/lox/closure/unused_closure.lox"); } #[test] -fn test_lox_closure_unused_later_closure() { +fn test_closure_unused_later_closure() { run_test("tests/lox/closure/unused_later_closure.lox"); } #[test] -fn test_lox_comments_line_at_eof() { +fn test_comments_line_at_eof() { run_test("tests/lox/comments/line_at_eof.lox"); } #[test] -fn test_lox_comments_only_line_comment() { +fn test_comments_only_line_comment() { run_test("tests/lox/comments/only_line_comment.lox"); } #[test] -fn test_lox_comments_only_line_comment_and_line() { +fn test_comments_only_line_comment_and_line() { run_test("tests/lox/comments/only_line_comment_and_line.lox"); } #[test] -fn test_lox_comments_unicode() { +fn test_comments_unicode() { run_test("tests/lox/comments/unicode.lox"); } #[test] -fn test_lox_constructor_arguments() { +fn test_constructor_arguments() { run_test("tests/lox/constructor/arguments.lox"); } #[test] -fn test_lox_constructor_call_init_early_return() { +fn test_constructor_call_init_early_return() { run_test("tests/lox/constructor/call_init_early_return.lox"); } #[test] -fn test_lox_constructor_call_init_explicitly() { +fn test_constructor_call_init_explicitly() { run_test("tests/lox/constructor/call_init_explicitly.lox"); } #[test] -fn test_lox_constructor_default() { +fn test_constructor_default() { run_test("tests/lox/constructor/default.lox"); } #[test] -fn test_lox_constructor_default_arguments() { +fn test_constructor_default_arguments() { run_test("tests/lox/constructor/default_arguments.lox"); } #[test] -fn test_lox_constructor_early_return() { +fn test_constructor_early_return() { run_test("tests/lox/constructor/early_return.lox"); } #[test] -fn test_lox_constructor_extra_arguments() { +fn test_constructor_extra_arguments() { run_test("tests/lox/constructor/extra_arguments.lox"); } #[test] -fn test_lox_constructor_init_not_method() { +fn test_constructor_init_not_method() { run_test("tests/lox/constructor/init_not_method.lox"); } #[test] -fn test_lox_constructor_missing_arguments() { +fn test_constructor_missing_arguments() { run_test("tests/lox/constructor/missing_arguments.lox"); } #[test] -fn test_lox_constructor_return_in_nested_function() { +fn test_constructor_return_in_nested_function() { run_test("tests/lox/constructor/return_in_nested_function.lox"); } #[test] -fn test_lox_constructor_return_value() { +fn test_constructor_return_value() { run_test("tests/lox/constructor/return_value.lox"); } #[test] -fn test_lox_continue_for() { +fn test_continue_for() { run_test("tests/lox/continue/for.lox"); } #[test] -fn test_lox_continue_outside_loop() { +fn test_continue_outside_loop() { run_test("tests/lox/continue/outside_loop.lox"); } #[test] -fn test_lox_continue_while() { +fn test_continue_while() { run_test("tests/lox/continue/while.lox"); } #[test] -fn test_lox_empty_file() { +fn test_empty_file() { run_test("tests/lox/empty_file.lox"); } #[test] -fn test_lox_field_call_function_field() { +fn test_field_call_function_field() { run_test("tests/lox/field/call_function_field.lox"); } #[test] -fn test_lox_field_call_nonfunction_field() { +fn test_field_call_nonfunction_field() { run_test("tests/lox/field/call_nonfunction_field.lox"); } #[test] -fn test_lox_field_get_and_set_method() { +fn test_field_get_and_set_method() { run_test("tests/lox/field/get_and_set_method.lox"); } #[test] -fn test_lox_field_get_on_bool() { +fn test_field_get_on_bool() { run_test("tests/lox/field/get_on_bool.lox"); } #[test] -fn test_lox_field_get_on_class() { +fn test_field_get_on_class() { run_test("tests/lox/field/get_on_class.lox"); } #[test] -fn test_lox_field_get_on_function() { +fn test_field_get_on_function() { run_test("tests/lox/field/get_on_function.lox"); } #[test] -fn test_lox_field_get_on_nil() { +fn test_field_get_on_nil() { run_test("tests/lox/field/get_on_nil.lox"); } #[test] -fn test_lox_field_get_on_num() { +fn test_field_get_on_num() { run_test("tests/lox/field/get_on_num.lox"); } #[test] -fn test_lox_field_get_on_string() { +fn test_field_get_on_string() { run_test("tests/lox/field/get_on_string.lox"); } #[test] -fn test_lox_field_many() { +fn test_field_many() { run_test("tests/lox/field/many.lox"); } #[test] -fn test_lox_field_method() { +fn test_field_method() { run_test("tests/lox/field/method.lox"); } #[test] -fn test_lox_field_method_binds_this() { +fn test_field_method_binds_this() { run_test("tests/lox/field/method_binds_this.lox"); } #[test] -fn test_lox_field_on_instance() { +fn test_field_on_instance() { run_test("tests/lox/field/on_instance.lox"); } #[test] -fn test_lox_field_set_evaluation_order() { +fn test_field_set_evaluation_order() { run_test("tests/lox/field/set_evaluation_order.lox"); } #[test] -fn test_lox_field_set_on_bool() { +fn test_field_set_on_bool() { run_test("tests/lox/field/set_on_bool.lox"); } #[test] -fn test_lox_field_set_on_class() { +fn test_field_set_on_class() { run_test("tests/lox/field/set_on_class.lox"); } #[test] -fn test_lox_field_set_on_function() { +fn test_field_set_on_function() { run_test("tests/lox/field/set_on_function.lox"); } #[test] -fn test_lox_field_set_on_nil() { +fn test_field_set_on_nil() { run_test("tests/lox/field/set_on_nil.lox"); } #[test] -fn test_lox_field_set_on_num() { +fn test_field_set_on_num() { run_test("tests/lox/field/set_on_num.lox"); } #[test] -fn test_lox_field_set_on_string() { +fn test_field_set_on_string() { run_test("tests/lox/field/set_on_string.lox"); } #[test] -fn test_lox_field_undefined() { +fn test_field_undefined() { run_test("tests/lox/field/undefined.lox"); } #[test] -fn test_lox_for_class_in_body() { +fn test_for_class_in_body() { run_test("tests/lox/for/class_in_body.lox"); } #[test] -fn test_lox_for_closure_in_body() { +fn test_for_closure_in_body() { run_test("tests/lox/for/closure_in_body.lox"); } #[test] -fn test_lox_for_fun_in_body() { +fn test_for_fun_in_body() { run_test("tests/lox/for/fun_in_body.lox"); } #[test] -fn test_lox_for_return_closure() { +fn test_for_return_closure() { run_test("tests/lox/for/return_closure.lox"); } #[test] -fn test_lox_for_return_inside() { +fn test_for_return_inside() { run_test("tests/lox/for/return_inside.lox"); } #[test] -fn test_lox_for_scope() { +fn test_for_scope() { run_test("tests/lox/for/scope.lox"); } #[test] -fn test_lox_for_statement_condition() { +fn test_for_statement_condition() { run_test("tests/lox/for/statement_condition.lox"); } #[test] -fn test_lox_for_statement_increment() { +fn test_for_statement_increment() { run_test("tests/lox/for/statement_increment.lox"); } #[test] -fn test_lox_for_statement_initializer() { +fn test_for_statement_initializer() { run_test("tests/lox/for/statement_initializer.lox"); } #[test] -fn test_lox_for_syntax() { +fn test_for_syntax() { run_test("tests/lox/for/syntax.lox"); } #[test] -fn test_lox_for_var_in_body() { +fn test_for_var_in_body() { run_test("tests/lox/for/var_in_body.lox"); } #[test] -fn test_lox_function_body_must_be_block() { +fn test_function_body_must_be_block() { run_test("tests/lox/function/body_must_be_block.lox"); } #[test] -fn test_lox_function_empty_body() { +fn test_function_empty_body() { run_test("tests/lox/function/empty_body.lox"); } #[test] -fn test_lox_function_extra_arguments() { +fn test_function_extra_arguments() { run_test("tests/lox/function/extra_arguments.lox"); } #[test] -fn test_lox_function_local_mutual_recursion() { +fn test_function_local_mutual_recursion() { run_test("tests/lox/function/local_mutual_recursion.lox"); } #[test] -fn test_lox_function_local_recursion() { +fn test_function_local_recursion() { run_test("tests/lox/function/local_recursion.lox"); } #[test] -fn test_lox_function_missing_arguments() { +fn test_function_missing_arguments() { run_test("tests/lox/function/missing_arguments.lox"); } #[test] -fn test_lox_function_missing_comma_in_parameters() { +fn test_function_missing_comma_in_parameters() { run_test("tests/lox/function/missing_comma_in_parameters.lox"); } #[test] -fn test_lox_function_mutual_recursion() { +fn test_function_mutual_recursion() { run_test("tests/lox/function/mutual_recursion.lox"); } #[test] -fn test_lox_function_nested_call_with_arguments() { +fn test_function_nested_call_with_arguments() { run_test("tests/lox/function/nested_call_with_arguments.lox"); } #[test] -fn test_lox_function_parameters() { +fn test_function_parameters() { run_test("tests/lox/function/parameters.lox"); } #[test] -fn test_lox_function_print() { +fn test_function_print() { run_test("tests/lox/function/print.lox"); } #[test] -fn test_lox_function_recursion() { +fn test_function_recursion() { run_test("tests/lox/function/recursion.lox"); } #[test] -fn test_lox_function_too_many_arguments() { +fn test_function_too_many_arguments() { run_test("tests/lox/function/too_many_arguments.lox"); } #[test] -fn test_lox_function_too_many_parameters() { +fn test_function_too_many_parameters() { run_test("tests/lox/function/too_many_parameters.lox"); } #[test] -fn test_lox_if_class_in_else() { +fn test_if_class_in_else() { run_test("tests/lox/if/class_in_else.lox"); } #[test] -fn test_lox_if_class_in_then() { +fn test_if_class_in_then() { run_test("tests/lox/if/class_in_then.lox"); } #[test] -fn test_lox_if_dangling_else() { +fn test_if_dangling_else() { run_test("tests/lox/if/dangling_else.lox"); } #[test] -fn test_lox_if_else() { +fn test_if_else() { run_test("tests/lox/if/else.lox"); } #[test] -fn test_lox_if_fun_in_else() { +fn test_if_fun_in_else() { run_test("tests/lox/if/fun_in_else.lox"); } #[test] -fn test_lox_if_fun_in_then() { +fn test_if_fun_in_then() { run_test("tests/lox/if/fun_in_then.lox"); } #[test] -fn test_lox_if_if() { +fn test_if_if() { run_test("tests/lox/if/if.lox"); } #[test] -fn test_lox_if_truth() { +fn test_if_truth() { run_test("tests/lox/if/truth.lox"); } #[test] -fn test_lox_if_var_in_else() { +fn test_if_var_in_else() { run_test("tests/lox/if/var_in_else.lox"); } #[test] -fn test_lox_if_var_in_then() { +fn test_if_var_in_then() { run_test("tests/lox/if/var_in_then.lox"); } #[test] -fn test_lox_inheritance_constructor() { +fn test_inheritance_constructor() { run_test("tests/lox/inheritance/constructor.lox"); } #[test] -fn test_lox_inheritance_inherit_from_function() { +fn test_inheritance_inherit_from_function() { run_test("tests/lox/inheritance/inherit_from_function.lox"); } #[test] -fn test_lox_inheritance_inherit_from_nil() { +fn test_inheritance_inherit_from_nil() { run_test("tests/lox/inheritance/inherit_from_nil.lox"); } #[test] -fn test_lox_inheritance_inherit_from_number() { +fn test_inheritance_inherit_from_number() { run_test("tests/lox/inheritance/inherit_from_number.lox"); } #[test] -fn test_lox_inheritance_inherit_methods() { +fn test_inheritance_inherit_methods() { run_test("tests/lox/inheritance/inherit_methods.lox"); } #[test] -fn test_lox_inheritance_parenthesized_superclass() { +fn test_inheritance_parenthesized_superclass() { run_test("tests/lox/inheritance/parenthesized_superclass.lox"); } #[test] -fn test_lox_inheritance_set_fields_from_base_class() { +fn test_inheritance_set_fields_from_base_class() { run_test("tests/lox/inheritance/set_fields_from_base_class.lox"); } #[test] -fn test_lox_limit_loop_too_large() { +fn test_limit_loop_too_large() { run_test("tests/lox/limit/loop_too_large.lox"); } #[test] -fn test_lox_limit_no_reuse_constants() { +fn test_limit_no_reuse_constants() { run_test("tests/lox/limit/no_reuse_constants.lox"); } #[test] -fn test_lox_limit_stack_overflow() { +fn test_limit_stack_overflow() { run_test("tests/lox/limit/stack_overflow.lox"); } #[test] -fn test_lox_limit_too_many_constants() { +fn test_limit_too_many_constants() { run_test("tests/lox/limit/too_many_constants.lox"); } #[test] -fn test_lox_limit_too_many_locals() { +fn test_limit_too_many_locals() { run_test("tests/lox/limit/too_many_locals.lox"); } #[test] -fn test_lox_limit_too_many_upvalues() { +fn test_limit_too_many_upvalues() { run_test("tests/lox/limit/too_many_upvalues.lox"); } #[test] -fn test_lox_logical_operator_and() { +fn test_logical_operator_and() { run_test("tests/lox/logical_operator/and.lox"); } #[test] -fn test_lox_logical_operator_and_truth() { +fn test_logical_operator_and_truth() { run_test("tests/lox/logical_operator/and_truth.lox"); } #[test] -fn test_lox_logical_operator_or() { +fn test_logical_operator_or() { run_test("tests/lox/logical_operator/or.lox"); } #[test] -fn test_lox_logical_operator_or_truth() { +fn test_logical_operator_or_truth() { run_test("tests/lox/logical_operator/or_truth.lox"); } #[test] -fn test_lox_method_arity() { +fn test_method_arity() { run_test("tests/lox/method/arity.lox"); } #[test] -fn test_lox_method_empty_block() { +fn test_method_empty_block() { run_test("tests/lox/method/empty_block.lox"); } #[test] -fn test_lox_method_extra_arguments() { +fn test_method_extra_arguments() { run_test("tests/lox/method/extra_arguments.lox"); } #[test] -fn test_lox_method_missing_arguments() { +fn test_method_missing_arguments() { run_test("tests/lox/method/missing_arguments.lox"); } #[test] -fn test_lox_method_not_found() { +fn test_method_not_found() { run_test("tests/lox/method/not_found.lox"); } #[test] -fn test_lox_method_print_bound_method() { +fn test_method_print_bound_method() { run_test("tests/lox/method/print_bound_method.lox"); } #[test] -fn test_lox_method_refer_to_name() { +fn test_method_refer_to_name() { run_test("tests/lox/method/refer_to_name.lox"); } #[test] -fn test_lox_method_too_many_arguments() { +fn test_method_too_many_arguments() { run_test("tests/lox/method/too_many_arguments.lox"); } #[test] -fn test_lox_method_too_many_parameters() { +fn test_method_too_many_parameters() { run_test("tests/lox/method/too_many_parameters.lox"); } #[test] -fn test_lox_nil_literal() { +fn test_nil_literal() { run_test("tests/lox/nil/literal.lox"); } #[test] -fn test_lox_number_decimal_point_at_eof() { +fn test_number_decimal_point_at_eof() { run_test("tests/lox/number/decimal_point_at_eof.lox"); } #[test] -fn test_lox_number_leading_dot() { +fn test_number_leading_dot() { run_test("tests/lox/number/leading_dot.lox"); } #[test] -fn test_lox_number_literals() { +fn test_number_literals() { run_test("tests/lox/number/literals.lox"); } #[test] -fn test_lox_number_nan_equality() { +fn test_number_nan_equality() { run_test("tests/lox/number/nan_equality.lox"); } #[test] -fn test_lox_number_trailing_dot() { +fn test_number_trailing_dot() { run_test("tests/lox/number/trailing_dot.lox"); } #[test] -fn test_lox_operator_add() { +fn test_operator_add() { run_test("tests/lox/operator/add.lox"); } #[test] -fn test_lox_operator_add_bool_nil() { +fn test_operator_add_bool_nil() { run_test("tests/lox/operator/add_bool_nil.lox"); } #[test] -fn test_lox_operator_add_bool_num() { +fn test_operator_add_bool_num() { run_test("tests/lox/operator/add_bool_num.lox"); } #[test] -fn test_lox_operator_add_bool_string() { +fn test_operator_add_bool_string() { run_test("tests/lox/operator/add_bool_string.lox"); } #[test] -fn test_lox_operator_add_nil_nil() { +fn test_operator_add_nil_nil() { run_test("tests/lox/operator/add_nil_nil.lox"); } #[test] -fn test_lox_operator_add_num_nil() { +fn test_operator_add_num_nil() { run_test("tests/lox/operator/add_num_nil.lox"); } #[test] -fn test_lox_operator_add_string_nil() { +fn test_operator_add_string_nil() { run_test("tests/lox/operator/add_string_nil.lox"); } #[test] -fn test_lox_operator_comparison() { +fn test_operator_comparison() { run_test("tests/lox/operator/comparison.lox"); } #[test] -fn test_lox_operator_divide() { +fn test_operator_divide() { run_test("tests/lox/operator/divide.lox"); } #[test] -fn test_lox_operator_divide_nonnum_num() { +fn test_operator_divide_nonnum_num() { run_test("tests/lox/operator/divide_nonnum_num.lox"); } #[test] -fn test_lox_operator_divide_num_nonnum() { +fn test_operator_divide_num_nonnum() { run_test("tests/lox/operator/divide_num_nonnum.lox"); } #[test] -fn test_lox_operator_equals() { +fn test_operator_equals() { run_test("tests/lox/operator/equals.lox"); } #[test] -fn test_lox_operator_equals_class() { +fn test_operator_equals_class() { run_test("tests/lox/operator/equals_class.lox"); } #[test] -fn test_lox_operator_equals_method() { +fn test_operator_equals_method() { run_test("tests/lox/operator/equals_method.lox"); } #[test] -fn test_lox_operator_greater_nonnum_num() { +fn test_operator_greater_nonnum_num() { run_test("tests/lox/operator/greater_nonnum_num.lox"); } #[test] -fn test_lox_operator_greater_num_nonnum() { +fn test_operator_greater_num_nonnum() { run_test("tests/lox/operator/greater_num_nonnum.lox"); } #[test] -fn test_lox_operator_greater_or_equal_nonnum_num() { +fn test_operator_greater_or_equal_nonnum_num() { run_test("tests/lox/operator/greater_or_equal_nonnum_num.lox"); } #[test] -fn test_lox_operator_greater_or_equal_num_nonnum() { +fn test_operator_greater_or_equal_num_nonnum() { run_test("tests/lox/operator/greater_or_equal_num_nonnum.lox"); } #[test] -fn test_lox_operator_less_nonnum_num() { +fn test_operator_less_nonnum_num() { run_test("tests/lox/operator/less_nonnum_num.lox"); } #[test] -fn test_lox_operator_less_num_nonnum() { +fn test_operator_less_num_nonnum() { run_test("tests/lox/operator/less_num_nonnum.lox"); } #[test] -fn test_lox_operator_less_or_equal_nonnum_num() { +fn test_operator_less_or_equal_nonnum_num() { run_test("tests/lox/operator/less_or_equal_nonnum_num.lox"); } #[test] -fn test_lox_operator_less_or_equal_num_nonnum() { +fn test_operator_less_or_equal_num_nonnum() { run_test("tests/lox/operator/less_or_equal_num_nonnum.lox"); } #[test] -fn test_lox_operator_multiply() { +fn test_operator_multiply() { run_test("tests/lox/operator/multiply.lox"); } #[test] -fn test_lox_operator_multiply_nonnum_num() { +fn test_operator_multiply_nonnum_num() { run_test("tests/lox/operator/multiply_nonnum_num.lox"); } #[test] -fn test_lox_operator_multiply_num_nonnum() { +fn test_operator_multiply_num_nonnum() { run_test("tests/lox/operator/multiply_num_nonnum.lox"); } #[test] -fn test_lox_operator_negate() { +fn test_operator_negate() { run_test("tests/lox/operator/negate.lox"); } #[test] -fn test_lox_operator_negate_nonnum() { +fn test_operator_negate_nonnum() { run_test("tests/lox/operator/negate_nonnum.lox"); } #[test] -fn test_lox_operator_not() { +fn test_operator_not() { run_test("tests/lox/operator/not.lox"); } #[test] -fn test_lox_operator_not_class() { +fn test_operator_not_class() { run_test("tests/lox/operator/not_class.lox"); } #[test] -fn test_lox_operator_not_equals() { +fn test_operator_not_equals() { run_test("tests/lox/operator/not_equals.lox"); } #[test] -fn test_lox_operator_subtract() { +fn test_operator_subtract() { run_test("tests/lox/operator/subtract.lox"); } #[test] -fn test_lox_operator_subtract_nonnum_num() { +fn test_operator_subtract_nonnum_num() { run_test("tests/lox/operator/subtract_nonnum_num.lox"); } #[test] -fn test_lox_operator_subtract_num_nonnum() { +fn test_operator_subtract_num_nonnum() { run_test("tests/lox/operator/subtract_num_nonnum.lox"); } #[test] -fn test_lox_precedence() { +fn test_precedence() { run_test("tests/lox/precedence.lox"); } #[test] -fn test_lox_print_missing_argument() { +fn test_print_missing_argument() { run_test("tests/lox/print/missing_argument.lox"); } #[test] -fn test_lox_regression_40() { - run_test("tests/lox/regression/40.lox"); -} - -#[test] -fn test_lox_regression_394() { +fn test_regression_394() { run_test("tests/lox/regression/394.lox"); } #[test] -fn test_lox_return_after_else() { +fn test_regression_40() { + run_test("tests/lox/regression/40.lox"); +} + +#[test] +fn test_return_after_else() { run_test("tests/lox/return/after_else.lox"); } #[test] -fn test_lox_return_after_if() { +fn test_return_after_if() { run_test("tests/lox/return/after_if.lox"); } #[test] -fn test_lox_return_after_while() { +fn test_return_after_while() { run_test("tests/lox/return/after_while.lox"); } #[test] -fn test_lox_return_at_top_level() { +fn test_return_at_top_level() { run_test("tests/lox/return/at_top_level.lox"); } #[test] -fn test_lox_return_in_function() { +fn test_return_in_function() { run_test("tests/lox/return/in_function.lox"); } #[test] -fn test_lox_return_in_method() { +fn test_return_in_method() { run_test("tests/lox/return/in_method.lox"); } #[test] -fn test_lox_return_return_nil_if_no_value() { +fn test_return_return_nil_if_no_value() { run_test("tests/lox/return/return_nil_if_no_value.lox"); } #[test] -fn test_lox_string_error_after_multiline() { +fn test_string_error_after_multiline() { run_test("tests/lox/string/error_after_multiline.lox"); } #[test] -fn test_lox_string_literals() { +fn test_string_literals() { run_test("tests/lox/string/literals.lox"); } #[test] -fn test_lox_string_multiline() { +fn test_string_multiline() { run_test("tests/lox/string/multiline.lox"); } #[test] -fn test_lox_string_unterminated() { +fn test_string_unterminated() { run_test("tests/lox/string/unterminated.lox"); } #[test] -fn test_lox_super_bound_method() { +fn test_super_bound_method() { run_test("tests/lox/super/bound_method.lox"); } #[test] -fn test_lox_super_call_other_method() { +fn test_super_call_other_method() { run_test("tests/lox/super/call_other_method.lox"); } #[test] -fn test_lox_super_call_same_method() { +fn test_super_call_same_method() { run_test("tests/lox/super/call_same_method.lox"); } #[test] -fn test_lox_super_closure() { +fn test_super_closure() { run_test("tests/lox/super/closure.lox"); } #[test] -fn test_lox_super_constructor() { +fn test_super_constructor() { run_test("tests/lox/super/constructor.lox"); } #[test] -fn test_lox_super_extra_arguments() { +fn test_super_extra_arguments() { run_test("tests/lox/super/extra_arguments.lox"); } #[test] -fn test_lox_super_indirectly_inherited() { +fn test_super_indirectly_inherited() { run_test("tests/lox/super/indirectly_inherited.lox"); } #[test] -fn test_lox_super_missing_arguments() { +fn test_super_missing_arguments() { run_test("tests/lox/super/missing_arguments.lox"); } #[test] -fn test_lox_super_no_superclass_bind() { +fn test_super_no_superclass_bind() { run_test("tests/lox/super/no_superclass_bind.lox"); } #[test] -fn test_lox_super_no_superclass_call() { +fn test_super_no_superclass_call() { run_test("tests/lox/super/no_superclass_call.lox"); } #[test] -fn test_lox_super_no_superclass_method() { +fn test_super_no_superclass_method() { run_test("tests/lox/super/no_superclass_method.lox"); } #[test] -fn test_lox_super_parenthesized() { +fn test_super_parenthesized() { run_test("tests/lox/super/parenthesized.lox"); } #[test] -fn test_lox_super_reassign_superclass() { +fn test_super_reassign_superclass() { run_test("tests/lox/super/reassign_superclass.lox"); } #[test] -fn test_lox_super_super_at_top_level() { +fn test_super_super_at_top_level() { run_test("tests/lox/super/super_at_top_level.lox"); } #[test] -fn test_lox_super_super_in_closure_in_inherited_method() { +fn test_super_super_in_closure_in_inherited_method() { run_test("tests/lox/super/super_in_closure_in_inherited_method.lox"); } #[test] -fn test_lox_super_super_in_inherited_method() { +fn test_super_super_in_inherited_method() { run_test("tests/lox/super/super_in_inherited_method.lox"); } #[test] -fn test_lox_super_super_in_top_level_function() { +fn test_super_super_in_top_level_function() { run_test("tests/lox/super/super_in_top_level_function.lox"); } #[test] -fn test_lox_super_super_without_dot() { +fn test_super_super_without_dot() { run_test("tests/lox/super/super_without_dot.lox"); } #[test] -fn test_lox_super_super_without_name() { +fn test_super_super_without_name() { run_test("tests/lox/super/super_without_name.lox"); } #[test] -fn test_lox_super_this_in_superclass_method() { +fn test_super_this_in_superclass_method() { run_test("tests/lox/super/this_in_superclass_method.lox"); } #[test] -fn test_lox_this_closure() { +fn test_this_closure() { run_test("tests/lox/this/closure.lox"); } #[test] -fn test_lox_this_nested_class() { +fn test_this_nested_class() { run_test("tests/lox/this/nested_class.lox"); } #[test] -fn test_lox_this_nested_closure() { +fn test_this_nested_closure() { run_test("tests/lox/this/nested_closure.lox"); } #[test] -fn test_lox_this_this_at_top_level() { +fn test_this_this_at_top_level() { run_test("tests/lox/this/this_at_top_level.lox"); } #[test] -fn test_lox_this_this_in_method() { +fn test_this_this_in_method() { run_test("tests/lox/this/this_in_method.lox"); } #[test] -fn test_lox_this_this_in_top_level_function() { +fn test_this_this_in_top_level_function() { run_test("tests/lox/this/this_in_top_level_function.lox"); } #[test] -fn test_lox_unexpected_character() { - run_test("tests/lox/unexpected_character.lox"); -} - -#[test] -fn test_lox_variable_collide_with_parameter() { +fn test_variable_collide_with_parameter() { run_test("tests/lox/variable/collide_with_parameter.lox"); } #[test] -fn test_lox_variable_duplicate_local() { +fn test_variable_duplicate_local() { run_test("tests/lox/variable/duplicate_local.lox"); } #[test] -fn test_lox_variable_duplicate_parameter() { +fn test_variable_duplicate_parameter() { run_test("tests/lox/variable/duplicate_parameter.lox"); } #[test] -fn test_lox_variable_early_bound() { +fn test_variable_early_bound() { run_test("tests/lox/variable/early_bound.lox"); } #[test] -fn test_lox_variable_in_middle_of_block() { +fn test_variable_in_middle_of_block() { run_test("tests/lox/variable/in_middle_of_block.lox"); } #[test] -fn test_lox_variable_in_nested_block() { +fn test_variable_in_nested_block() { run_test("tests/lox/variable/in_nested_block.lox"); } #[test] -fn test_lox_variable_local_from_method() { +fn test_variable_local_from_method() { run_test("tests/lox/variable/local_from_method.lox"); } #[test] -fn test_lox_variable_redeclare_global() { +fn test_variable_redeclare_global() { run_test("tests/lox/variable/redeclare_global.lox"); } #[test] -fn test_lox_variable_redefine_global() { +fn test_variable_redefine_global() { run_test("tests/lox/variable/redefine_global.lox"); } #[test] -fn test_lox_variable_scope_reuse_in_different_blocks() { +fn test_variable_scope_reuse_in_different_blocks() { run_test("tests/lox/variable/scope_reuse_in_different_blocks.lox"); } #[test] -fn test_lox_variable_shadow_and_local() { +fn test_variable_shadow_and_local() { run_test("tests/lox/variable/shadow_and_local.lox"); } #[test] -fn test_lox_variable_shadow_global() { +fn test_variable_shadow_global() { run_test("tests/lox/variable/shadow_global.lox"); } #[test] -fn test_lox_variable_shadow_local() { +fn test_variable_shadow_local() { run_test("tests/lox/variable/shadow_local.lox"); } #[test] -fn test_lox_variable_undefined_global() { +fn test_variable_undefined_global() { run_test("tests/lox/variable/undefined_global.lox"); } #[test] -fn test_lox_variable_undefined_local() { +fn test_variable_undefined_local() { run_test("tests/lox/variable/undefined_local.lox"); } #[test] -fn test_lox_variable_uninitialized() { +fn test_variable_uninitialized() { run_test("tests/lox/variable/uninitialized.lox"); } #[test] -fn test_lox_variable_unreached_undefined() { +fn test_variable_unreached_undefined() { run_test("tests/lox/variable/unreached_undefined.lox"); } #[test] -fn test_lox_variable_use_false_as_var() { +fn test_variable_use_false_as_var() { run_test("tests/lox/variable/use_false_as_var.lox"); } #[test] -fn test_lox_variable_use_global_in_initializer() { +fn test_variable_use_global_in_initializer() { run_test("tests/lox/variable/use_global_in_initializer.lox"); } #[test] -fn test_lox_variable_use_local_in_initializer() { +fn test_variable_use_local_in_initializer() { run_test("tests/lox/variable/use_local_in_initializer.lox"); } #[test] -fn test_lox_variable_use_nil_as_var() { +fn test_variable_use_nil_as_var() { run_test("tests/lox/variable/use_nil_as_var.lox"); } #[test] -fn test_lox_variable_use_this_as_var() { +fn test_variable_use_this_as_var() { run_test("tests/lox/variable/use_this_as_var.lox"); } #[test] -fn test_lox_while_class_in_body() { +fn test_while_class_in_body() { run_test("tests/lox/while/class_in_body.lox"); } #[test] -fn test_lox_while_closure_in_body() { +fn test_while_closure_in_body() { run_test("tests/lox/while/closure_in_body.lox"); } #[test] -fn test_lox_while_fun_in_body() { +fn test_while_fun_in_body() { run_test("tests/lox/while/fun_in_body.lox"); } #[test] -fn test_lox_while_return_closure() { +fn test_while_return_closure() { run_test("tests/lox/while/return_closure.lox"); } #[test] -fn test_lox_while_return_inside() { +fn test_while_return_inside() { run_test("tests/lox/while/return_inside.lox"); } #[test] -fn test_lox_while_syntax() { +fn test_while_syntax() { run_test("tests/lox/while/syntax.lox"); } #[test] -fn test_lox_while_var_in_body() { +fn test_while_var_in_body() { run_test("tests/lox/while/var_in_body.lox"); -} +} \ No newline at end of file diff --git a/interpreter/tests/common/mod.rs b/interpreter/tests/common/mod.rs index b57f97c..946abea 100644 --- a/interpreter/tests/common/mod.rs +++ b/interpreter/tests/common/mod.rs @@ -8,6 +8,8 @@ use rlox2_interpreter::{run, Runtime}; #[cfg(test)] pub fn run_test(path: impl Into) { + use smol_str::SmolStr; + let path = &path.into(); // path.insert_str(0, "./tests/lox/"); @@ -15,25 +17,29 @@ pub fn run_test(path: impl Into) { let tokens = rlox2_frontend::lexer::scan_tokens(&source).unwrap(); - let comments: Vec = tokens - .into_iter() - .filter_map(|token| { + let comments: Result, SmolStr> = + tokens.into_iter().try_fold(Vec::new(), |mut acc, token| { if let TokenType::Comment(s) = token.token_type { - if s.starts_with(" expect: ") { - Some(s.strip_prefix(" expect: ").unwrap().trim().to_owned()) - } else if s.contains("Error") || s.contains("error") { - Some(s.trim().into()) - } else { - None + if s.contains("Error") || s.contains("error") { + return Err(s); + } else if s.starts_with(" expect: ") { + acc.push(s.trim().strip_prefix("expect:").unwrap().trim().to_owned()); } - } else { - None } - }) - .collect(); - for comment in comments.iter() { - println!("Comment: \"{comment}\"") + Ok(acc) + }); + + match comments { + Ok(ref comments) => { + println!("Expecting positive result"); + for comment in comments.iter() { + println!("Comment: \"{comment}\"") + } + } + Err(ref e) => { + println!("Expecting error: {e}"); + } } print!("\n\n"); @@ -51,17 +57,17 @@ pub fn run_test(path: impl Into) { Err(e) => { println!("{e}"); - assert_eq!(comments.len(), 1); - - let comment = &*comments[0]; - - assert!(comment.to_lowercase().contains("error")); + assert!(comments.is_err()); return; } } } + let Ok(comments) = comments else { + panic!("Positive outcome, but expected error"); + }; + let mut output = output.as_ref().borrow_mut(); let output = String::from_utf8(std::mem::take(&mut *output)).unwrap(); diff --git a/interpreter/tests/lox/run.t b/interpreter/tests/lox/run.t deleted file mode 100644 index 313dbff..0000000 --- a/interpreter/tests/lox/run.t +++ /dev/null @@ -1,1446 +0,0 @@ -file empty_file.lox - $ mlox empty_file.lox - - -file precedence.lox - $ mlox precedence.lox - 14 - 8 - 4 - 0 - true - true - true - true - 0 - 0 - 0 - 0 - 4 - - -file unexpected_character.lox - $ mlox unexpected_character.lox - found 1 LexerError: - LexerError at line 3, column 6: Unexpected character '|' - [1] - - -file assignment/associativity.lox - $ mlox assignment/associativity.lox - c - c - c - - -file assignment/global.lox - $ mlox assignment/global.lox - before - after - arg - arg - - -file assignment/grouping.lox - $ mlox assignment/grouping.lox - - -file assignment/infix_operator.lox - $ mlox assignment/infix_operator.lox - found 1 ParserError: - ParserError at line 3, column 6: Invalid assignment target - [1] - - -file assignment/local.lox - $ mlox assignment/local.lox - before - after - arg - arg - - -file assignment/prefix_operator.lox - $ mlox assignment/prefix_operator.lox - found 1 ParserError: - ParserError at line 2, column 3: Invalid assignment target - [1] - - -file assignment/syntax.lox - $ mlox assignment/syntax.lox - var - var - - -file assignment/to_this.lox -$ mlox assignment/to_this.lox - - -file assignment/undefined.lox - $ mlox assignment/undefined.lox - RuntimeError at line 1, column 8: tried to assign to undefined variable unknown - [1] - - -file block/empty.lox - $ mlox block/empty.lox - ok - - -file block/scope.lox - $ mlox block/scope.lox - inner - outer - - -file bool/equality.lox - $ mlox bool/equality.lox - true - false - false - true - false - false - false - false - false - false - true - true - false - true - true - true - true - true - - -file bool/not.lox - $ mlox bool/not.lox - false - true - true - - -file break/for.lox - $ mlox break/for.lox - 0 - 1 - 2 - 3 - 4 - - -file break/outside_loop.lox - $ mlox break/outside_loop.lox - found 1 ParserError: - ParserError at line 1, column 0: Can use break only in loops - [1] - - -file break/while.lox - $ mlox break/while.lox - 0 - 1 - 2 - 3 - 4 - - -file call/bool.lox - $ mlox call/bool.lox - RuntimeError at line 1, column 4: Bool object is not callable - [1] - - -file call/nil.lox - $ mlox call/nil.lox - RuntimeError at line 1, column 3: Nil object is not callable - [1] - - -file call/num.lox - $ mlox call/num.lox - RuntimeError at line 1, column 3: Number object is not callable - [1] - - -file call/object.lox -$ mlox call/object.lox - - -file call/string.lox - $ mlox call/string.lox - RuntimeError at line 1, column 5: String object is not callable - [1] - - -file class/empty.lox -$ mlox class/empty.lox - - -file class/inherit_self.lox -$ mlox class/inherit_self.lox - - -file class/inherited_method.lox -$ mlox class/inherited_method.lox - - -file class/local_inherit_other.lox -$ mlox class/local_inherit_other.lox - - -file class/local_inherit_self.lox - $ mlox class/local_inherit_self.lox - - -file class/local_reference_self.lox - $ mlox class/local_reference_self.lox - - -file class/reference_self.lox -$ mlox class/reference_self.lox - - -file closure/assign_to_closure.lox - $ mlox closure/assign_to_closure.lox - local - after f - after f - after g - - -file closure/assign_to_shadowed_later.lox -$ mlox closure/assign_to_shadowed_later.lox -inner -assigned - - -file closure/close_over_function_parameter.lox - $ mlox closure/close_over_function_parameter.lox - param - - -file closure/close_over_later_variable.lox - $ mlox closure/close_over_later_variable.lox - b - a - - -file closure/close_over_method_parameter.lox -$ mlox closure/close_over_method_parameter.lox - - -file closure/closed_closure_in_function.lox - $ mlox closure/closed_closure_in_function.lox - local - - -file closure/nested_closure.lox - $ mlox closure/nested_closure.lox - a - b - c - - -file closure/open_closure_in_function.lox - $ mlox closure/open_closure_in_function.lox - local - - -file closure/reference_closure_multiple_times.lox - $ mlox closure/reference_closure_multiple_times.lox - a - a - - -file closure/reuse_closure_slot.lox - $ mlox closure/reuse_closure_slot.lox - a - - -file closure/shadow_closure_with_local.lox - $ mlox closure/shadow_closure_with_local.lox - closure - shadow - closure - - -file closure/unused_closure.lox - $ mlox closure/unused_closure.lox - ok - - -file closure/unused_later_closure.lox - $ mlox closure/unused_later_closure.lox - a - - -file comments/line_at_eof.lox - $ mlox comments/line_at_eof.lox - ok - - -file comments/only_line_comment.lox - $ mlox comments/only_line_comment.lox - - -file comments/only_line_comment_and_line.lox - $ mlox comments/only_line_comment_and_line.lox - - -file comments/unicode.lox - $ mlox comments/unicode.lox - ok - - -file constructor/arguments.lox -$ mlox constructor/arguments.lox - - -file constructor/call_init_early_return.lox -$ mlox constructor/call_init_early_return.lox - - -file constructor/call_init_explicitly.lox -$ mlox constructor/call_init_explicitly.lox - - -file constructor/default.lox -$ mlox constructor/default.lox - - -file constructor/default_arguments.lox -$ mlox constructor/default_arguments.lox - - -file constructor/early_return.lox -$ mlox constructor/early_return.lox - - -file constructor/extra_arguments.lox -$ mlox constructor/extra_arguments.lox - - -file constructor/init_not_method.lox -$ mlox constructor/init_not_method.lox - - -file constructor/missing_arguments.lox -$ mlox constructor/missing_arguments.lox - - -file constructor/return_in_nested_function.lox -$ mlox constructor/return_in_nested_function.lox - - -file constructor/return_value.lox -$ mlox constructor/return_value.lox - - -file continue/for.lox - $ mlox continue/for.lox - 0 - 1 - 2 - 3 - 4 - 6 - 7 - 8 - 9 - - -file continue/outside_loop.lox - $ mlox continue/outside_loop.lox - found 1 ParserError: - ParserError at line 1, column 0: Can use continue only in loops - [1] - - -file continue/while.lox - $ mlox continue/while.lox - 0 - 1 - 2 - 3 - 4 - 6 - 7 - 8 - 9 - - -file field/call_function_field.lox -$ mlox field/call_function_field.lox - - -file field/call_nonfunction_field.lox -$ mlox field/call_nonfunction_field.lox - - -file field/get_and_set_method.lox -$ mlox field/get_and_set_method.lox - - -file field/get_on_bool.lox -$ mlox field/get_on_bool.lox - - -file field/get_on_class.lox -$ mlox field/get_on_class.lox - - -file field/get_on_function.lox -$ mlox field/get_on_function.lox - - -file field/get_on_nil.lox -$ mlox field/get_on_nil.lox - - -file field/get_on_num.lox -$ mlox field/get_on_num.lox - - -file field/get_on_string.lox -$ mlox field/get_on_string.lox - - -file field/many.lox -$ mlox field/many.lox - - -file field/method.lox -$ mlox field/method.lox - - -file field/method_binds_this.lox -$ mlox field/method_binds_this.lox - - -file field/on_instance.lox -$ mlox field/on_instance.lox - - -file field/set_evaluation_order.lox -$ mlox field/set_evaluation_order.lox - - -file field/set_on_bool.lox -$ mlox field/set_on_bool.lox - - -file field/set_on_class.lox -$ mlox field/set_on_class.lox - - -file field/set_on_function.lox -$ mlox field/set_on_function.lox - - -file field/set_on_nil.lox -$ mlox field/set_on_nil.lox - - -file field/set_on_num.lox -$ mlox field/set_on_num.lox - - -file field/set_on_string.lox -$ mlox field/set_on_string.lox - - -file field/undefined.lox -$ mlox field/undefined.lox - - -file for/class_in_body.lox -$ mlox for/class_in_body.lox - - -file for/closure_in_body.lox -$ mlox for/closure_in_body.lox - - -file for/fun_in_body.lox - $ mlox for/fun_in_body.lox - found 1 ParserError: - ParserError at line 2, column 9: Expected valid expression, got Fun instead - [1] - - -file for/return_closure.lox -$ mlox for/return_closure.lox - - -file for/return_inside.lox - $ mlox for/return_inside.lox - i - - -file for/scope.lox - $ mlox for/scope.lox - 0 - -1 - after - 0 - - -file for/statement_condition.lox - $ mlox for/statement_condition.lox - found 2 ParserErrors: - ParserError at line 3, column 16: Expected valid expression, got LeftBrace instead - ParserError at line 3, column 29: Expected Semicolon, but got RightParen - [1] - - -file for/statement_increment.lox - $ mlox for/statement_increment.lox - found 1 ParserError: - ParserError at line 2, column 23: Expected valid expression, got LeftBrace instead - [1] - -file for/statement_initializer.lox - $ mlox for/statement_initializer.lox - found 2 ParserErrors: - ParserError at line 3, column 5: Expected valid expression, got LeftBrace instead - ParserError at line 3, column 25: Expected Semicolon, but got RightParen - [1] - - -file for/syntax.lox - $ mlox for/syntax.lox - 1 - 2 - 3 - 0 - 1 - 2 - done - 0 - 1 - 0 - 1 - 2 - 0 - 1 - - -file for/var_in_body.lox - $ mlox for/var_in_body.lox - found 1 ParserError: - ParserError at line 2, column 9: Expected valid expression, got Var instead - [1] - -file function/body_must_be_block.lox - $ mlox function/body_must_be_block.lox - found 1 ParserError: - ParserError at line 3, column 8: Expected LeftBrace, but got (Number 123.) - [1] - - -file function/empty_body.lox - $ mlox function/empty_body.lox - nil - - -file function/extra_arguments.lox - $ mlox function/extra_arguments.lox - RuntimeError at line 6, column 1: Function f has arity 4, but was called with 2 args - [1] - - -file function/local_mutual_recursion.lox -$ mlox function/local_mutual_recursion.lox -RuntimeError at line 4, column 11: name "isOdd" is not defined -[1] - -file function/local_recursion.lox -$ mlox function/local_recursion.lox - - -file function/missing_arguments.lox - $ mlox function/missing_arguments.lox - RuntimeError at line 3, column 1: Function f has arity 1, but was called with 2 args - [1] - - -file function/missing_comma_in_parameters.lox - $ mlox function/missing_comma_in_parameters.lox - found 1 ParserError: - ParserError at line 3, column 13: Expected RightParen, but got (Identifier "c") - [1] - - -file function/mutual_recursion.lox - $ mlox function/mutual_recursion.lox - true - true - - -file function/nested_call_with_arguments.lox - $ mlox function/nested_call_with_arguments.lox - hello world - - -file function/parameters.lox - $ mlox function/parameters.lox - 0 - 1 - 3 - 6 - 10 - 15 - 21 - 28 - 36 - - -file function/print.lox - $ mlox function/print.lox - - - - -file function/recursion.lox - $ mlox function/recursion.lox - 21 - - -file function/too_many_arguments.lox - $ mlox function/too_many_arguments.lox - found 2 ParserErrors: - ParserError at line 4, column 5: Can't call with more than 255 arguments - ParserError at line 261, column 0: Expected valid expression, got RightBrace instead - [1] - - -file function/too_many_parameters.lox - $ mlox function/too_many_parameters.lox - found 1 ParserError: - ParserError at line 2, column 0: Function f can't have more than 255 arguments - [1] - - -file if/class_in_else.lox -$ mlox if/class_in_else.lox - - -file if/class_in_then.lox -$ mlox if/class_in_then.lox - - -file if/dangling_else.lox - $ mlox if/dangling_else.lox - good - - -file if/else.lox - $ mlox if/else.lox - good - good - block - - -file if/fun_in_else.lox - $ mlox if/fun_in_else.lox - found 1 ParserError: - ParserError at line 2, column 21: Expected valid expression, got Fun instead - [1] - - -file if/fun_in_then.lox - $ mlox if/fun_in_then.lox - found 1 ParserError: - ParserError at line 2, column 10: Expected valid expression, got Fun instead - [1] - - -file if/if.lox - $ mlox if/if.lox - good - block - true - - -file if/truth.lox - $ mlox if/truth.lox - false - nil - true - 0 - empty - - -file if/var_in_else.lox - $ mlox if/var_in_else.lox - found 1 ParserError: - ParserError at line 2, column 21: Expected valid expression, got Var instead - [1] - - -file if/var_in_then.lox - $ mlox if/var_in_then.lox - found 1 ParserError: - ParserError at line 2, column 10: Expected valid expression, got Var instead - [1] - - -file inheritance/constructor.lox -$ mlox inheritance/constructor.lox - - -file inheritance/inherit_from_function.lox -$ mlox inheritance/inherit_from_function.lox - - -file inheritance/inherit_from_nil.lox -$ mlox inheritance/inherit_from_nil.lox - - -file inheritance/inherit_from_number.lox -$ mlox inheritance/inherit_from_number.lox - - -file inheritance/inherit_methods.lox -$ mlox inheritance/inherit_methods.lox - - -file inheritance/parenthesized_superclass.lox -$ mlox inheritance/parenthesized_superclass.lox - - -file inheritance/set_fields_from_base_class.lox -$ mlox inheritance/set_fields_from_base_class.lox - - -file limit/loop_too_large.lox - $ mlox limit/loop_too_large.lox - - -file limit/no_reuse_constants.lox - $ mlox limit/no_reuse_constants.lox - - -file limit/stack_overflow.lox -$ mlox limit/stack_overflow.lox - - -file limit/too_many_constants.lox - $ mlox limit/too_many_constants.lox - - -file limit/too_many_locals.lox - $ mlox limit/too_many_locals.lox - - -file limit/too_many_upvalues.lox - $ mlox limit/too_many_upvalues.lox - - -file logical_operator/and.lox - $ mlox logical_operator/and.lox - false - 1 - false - true - 3 - true - false - - -file logical_operator/and_truth.lox - $ mlox logical_operator/and_truth.lox - false - nil - ok - ok - ok - - -file logical_operator/or.lox - $ mlox logical_operator/or.lox - 1 - 1 - true - false - false - false - true - - -file logical_operator/or_truth.lox - $ mlox logical_operator/or_truth.lox - ok - ok - true - 0 - s - - -file method/arity.lox -$ mlox method/arity.lox - - -file method/empty_block.lox -$ mlox method/empty_block.lox - - -file method/extra_arguments.lox -$ mlox method/extra_arguments.lox - - -file method/missing_arguments.lox -$ mlox method/missing_arguments.lox - - -file method/not_found.lox -$ mlox method/not_found.lox - - -file method/print_bound_method.lox -$ mlox method/print_bound_method.lox - - -file method/refer_to_name.lox -$ mlox method/refer_to_name.lox - - -file method/too_many_arguments.lox -$ mlox method/too_many_arguments.lox - - -file method/too_many_parameters.lox -$ mlox method/too_many_parameters.lox - - -file nil/literal.lox - $ mlox nil/literal.lox - nil - - -file number/decimal_point_at_eof.lox - $ mlox number/decimal_point_at_eof.lox - found 1 ParserError: - ParserError at line 2, column 4: Expected Semicolon, but got Eof - [1] - - -file number/leading_dot.lox - $ mlox number/leading_dot.lox - found 1 ParserError: - ParserError at line 2, column 0: Expected valid expression, got Dot instead - [1] - - -file number/literals.lox - $ mlox number/literals.lox - 123 - 987654 - 0 - 0 - 123.456 - -0.001 - - -file number/nan_equality.lox - $ mlox number/nan_equality.lox - RuntimeError at line 1, column 11: Division by 0 - [1] -false -true -false -true - - -file number/trailing_dot.lox - $ mlox number/trailing_dot.lox - - -file operator/add.lox - $ mlox operator/add.lox - 579 - string - - -file operator/add_bool_nil.lox - $ mlox operator/add_bool_nil.lox - RuntimeError at line 1, column 5: Invalid operands of type Bool and Nil to operator Plus - [1] - - -file operator/add_bool_num.lox - $ mlox operator/add_bool_num.lox - RuntimeError at line 1, column 5: Invalid operands of type Bool and Number to operator Plus - [1] - - -file operator/add_bool_string.lox - $ mlox operator/add_bool_string.lox - RuntimeError at line 1, column 5: Invalid operands of type Bool and String to operator Plus - [1] - - -file operator/add_nil_nil.lox - $ mlox operator/add_nil_nil.lox - RuntimeError at line 1, column 4: Invalid operands of type Nil and Nil to operator Plus - [1] - - -file operator/add_num_nil.lox - $ mlox operator/add_num_nil.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and Nil to operator Plus - [1] - - -file operator/add_string_nil.lox - $ mlox operator/add_string_nil.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Nil to operator Plus - [1] - - -file operator/comparison.lox - $ mlox operator/comparison.lox - true - false - false - true - true - false - false - false - true - false - true - true - false - false - false - false - true - true - true - true - - -file operator/divide.lox - $ mlox operator/divide.lox - 4 - 1 - - -file operator/divide_nonnum_num.lox - $ mlox operator/divide_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator Div - [1] - - -file operator/divide_num_nonnum.lox - $ mlox operator/divide_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator Div - [1] - - -file operator/equals.lox - $ mlox operator/equals.lox - true - true - false - true - false - true - false - false - false - false - - -file operator/equals_class.lox -$ mlox operator/equals_class.lox - - -file operator/equals_method.lox -$ mlox operator/equals_method.lox - - -file operator/greater_nonnum_num.lox - $ mlox operator/greater_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator Greater - [1] - - -file operator/greater_num_nonnum.lox - $ mlox operator/greater_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator Greater - [1] - - -file operator/greater_or_equal_nonnum_num.lox - $ mlox operator/greater_or_equal_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator GreaterEqual - [1] - - -file operator/greater_or_equal_num_nonnum.lox - $ mlox operator/greater_or_equal_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator GreaterEqual - [1] - - -file operator/less_nonnum_num.lox - $ mlox operator/less_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator Less - [1] - - -file operator/less_num_nonnum.lox - $ mlox operator/less_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator Less - [1] - - -file operator/less_or_equal_nonnum_num.lox - $ mlox operator/less_or_equal_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator LessEqual - [1] - - -file operator/less_or_equal_num_nonnum.lox - $ mlox operator/less_or_equal_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator LessEqual - [1] - - -file operator/multiply.lox - $ mlox operator/multiply.lox - 15 - 3.702 - - -file operator/multiply_nonnum_num.lox - $ mlox operator/multiply_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator Mul - [1] - - -file operator/multiply_num_nonnum.lox - $ mlox operator/multiply_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator Mul - [1] - - -file operator/negate.lox - $ mlox operator/negate.lox - -3 - 3 - -3 - - -file operator/negate_nonnum.lox - $ mlox operator/negate_nonnum.lox - RuntimeError at line 1, column 0: Invalid operant of type String to operator Neg - [1] - - -file operator/not.lox - $ mlox operator/not.lox - false - true - true - false - false - true - false - false - - -file operator/not_class.lox -$ mlox operator/not_class.lox - - -file operator/not_equals.lox - $ mlox operator/not_equals.lox - false - false - true - false - true - false - true - true - true - true - - -file operator/subtract.lox - $ mlox operator/subtract.lox - 1 - 0 - - -file operator/subtract_nonnum_num.lox - $ mlox operator/subtract_nonnum_num.lox - RuntimeError at line 1, column 4: Invalid operands of type String and Number to operator Minus - [1] - - -file operator/subtract_num_nonnum.lox - $ mlox operator/subtract_num_nonnum.lox - RuntimeError at line 1, column 2: Invalid operands of type Number and String to operator Minus - [1] - - -file print/missing_argument.lox - $ mlox print/missing_argument.lox - found 1 ParserError: - ParserError at line 2, column 5: Expected valid expression, got Semicolon instead - [1] - - -file regression/40.lox - $ mlox regression/40.lox - false - - -file regression/394.lox -$ mlox regression/394.lox - - -file return/after_else.lox - $ mlox return/after_else.lox - ok - - -file return/after_if.lox - $ mlox return/after_if.lox - ok - - -file return/after_while.lox - $ mlox return/after_while.lox - ok - - -file return/at_top_level.lox - $ mlox return/at_top_level.lox - found 1 ParserError: - ParserError at line 1, column 0: Can use return only in functions - [1] - -file return/in_function.lox - $ mlox return/in_function.lox - ok - - -file return/in_method.lox -$ mlox return/in_method.lox - - -file return/return_nil_if_no_value.lox - $ mlox return/return_nil_if_no_value.lox - nil - - -file string/error_after_multiline.lox - $ mlox string/error_after_multiline.lox - RuntimeError at line 7, column 0: name "err" is not defined - [1] - - -file string/literals.lox - $ mlox string/literals.lox - () - a string - A~¶Þॐஃ - - -file string/multiline.lox - $ mlox string/multiline.lox - 1 - 2 - 3 - - -file string/unterminated.lox - $ mlox string/unterminated.lox - found 1 LexerError: - LexerError at line 2, column 0: Unterminated string literal - [1] - - -file super/bound_method.lox -$ mlox super/bound_method.lox - - -file super/call_other_method.lox -$ mlox super/call_other_method.lox - - -file super/call_same_method.lox -$ mlox super/call_same_method.lox - - -file super/closure.lox -$ mlox super/closure.lox - - -file super/constructor.lox -$ mlox super/constructor.lox - - -file super/extra_arguments.lox -$ mlox super/extra_arguments.lox - - -file super/indirectly_inherited.lox -$ mlox super/indirectly_inherited.lox - - -file super/missing_arguments.lox -$ mlox super/missing_arguments.lox - - -file super/no_superclass_bind.lox -$ mlox super/no_superclass_bind.lox - - -file super/no_superclass_call.lox -$ mlox super/no_superclass_call.lox - - -file super/no_superclass_method.lox -$ mlox super/no_superclass_method.lox - - -file super/parenthesized.lox -$ mlox super/parenthesized.lox - - -file super/reassign_superclass.lox -$ mlox super/reassign_superclass.lox - - -file super/super_at_top_level.lox -$ mlox super/super_at_top_level.lox - - -file super/super_in_closure_in_inherited_method.lox -$ mlox super/super_in_closure_in_inherited_method.lox - - -file super/super_in_inherited_method.lox -$ mlox super/super_in_inherited_method.lox - - -file super/super_in_top_level_function.lox -$ mlox super/super_in_top_level_function.lox - - -file super/super_without_dot.lox -$ mlox super/super_without_dot.lox - - -file super/super_without_name.lox -$ mlox super/super_without_name.lox - - -file super/this_in_superclass_method.lox -$ mlox super/this_in_superclass_method.lox - - -file this/closure.lox -$ mlox this/closure.lox - - -file this/nested_class.lox -$ mlox this/nested_class.lox - - -file this/nested_closure.lox -$ mlox this/nested_closure.lox - - -file this/this_at_top_level.lox -$ mlox this/this_at_top_level.lox - - -file this/this_in_method.lox -$ mlox this/this_in_method.lox - - -file this/this_in_top_level_function.lox -$ mlox this/this_in_top_level_function.lox - - -file variable/collide_with_parameter.lox - $ mlox variable/collide_with_parameter.lox - - -file variable/duplicate_local.lox - $ mlox variable/duplicate_local.lox - RuntimeError at line 3, column 2: Tried to define a, but a variable of that name was already defined - [1] - - -file variable/duplicate_parameter.lox - $ mlox variable/duplicate_parameter.lox - - -file variable/early_bound.lox -$ mlox variable/early_bound.lox -outer -outer - - -file variable/in_middle_of_block.lox - $ mlox variable/in_middle_of_block.lox - a - a b - a c - a b d - - -file variable/in_nested_block.lox - $ mlox variable/in_nested_block.lox - outer - - -file variable/local_from_method.lox -$ mlox variable/local_from_method.lox - - -file variable/redeclare_global.lox - $ mlox variable/redeclare_global.lox - nil - - -file variable/redefine_global.lox - $ mlox variable/redefine_global.lox - 2 - - -file variable/scope_reuse_in_different_blocks.lox - $ mlox variable/scope_reuse_in_different_blocks.lox - first - second - - -file variable/shadow_and_local.lox - $ mlox variable/shadow_and_local.lox - outer - inner - - -file variable/shadow_global.lox - $ mlox variable/shadow_global.lox - shadow - global - - -file variable/shadow_local.lox - $ mlox variable/shadow_local.lox - shadow - local - - -file variable/undefined_global.lox - $ mlox variable/undefined_global.lox - RuntimeError at line 1, column 6: name "notDefined" is not defined - [1] - - -file variable/undefined_local.lox - $ mlox variable/undefined_local.lox - RuntimeError at line 2, column 8: name "notDefined" is not defined - [1] - - -file variable/uninitialized.lox - $ mlox variable/uninitialized.lox - nil - - -file variable/unreached_undefined.lox - $ mlox variable/unreached_undefined.lox - ok - - -file variable/use_false_as_var.lox - $ mlox variable/use_false_as_var.lox - found 1 ParserError: - ParserError at line 2, column 4: Expected identifier, but got False - [1] - - -file variable/use_global_in_initializer.lox - $ mlox variable/use_global_in_initializer.lox - value - - -TODO: what to do here? -file variable/use_local_in_initializer.lox - $ mlox variable/use_local_in_initializer.lox - - -file variable/use_nil_as_var.lox - $ mlox variable/use_nil_as_var.lox - found 1 ParserError: - ParserError at line 2, column 4: Expected identifier, but got Nil - [1] - - -file variable/use_this_as_var.lox - $ mlox variable/use_this_as_var.lox - found 1 ParserError: - ParserError at line 2, column 4: Expected identifier, but got This - [1] - - -file while/class_in_body.lox -$ mlox while/class_in_body.lox - - -file while/closure_in_body.lox - $ mlox while/closure_in_body.lox - 1 - 2 - 3 - - -file while/fun_in_body.lox - $ mlox while/fun_in_body.lox - found 1 ParserError: - ParserError at line 2, column 13: Expected valid expression, got Fun instead - [1] - - -file while/return_closure.lox - $ mlox while/return_closure.lox - i - - -file while/return_inside.lox - $ mlox while/return_inside.lox - i - - -file while/syntax.lox - $ mlox while/syntax.lox - 1 - 2 - 3 - 0 - 1 - 2 - - -file while/var_in_body.lox - $ mlox while/var_in_body.lox - found 1 ParserError: - ParserError at line 2, column 13: Expected valid expression, got Var instead - [1] - - diff --git a/interpreter/tests/lox/unexpected_character.lox b/interpreter/tests/lox/unexpected_character.lox deleted file mode 100644 index 5e51396..0000000 --- a/interpreter/tests/lox/unexpected_character.lox +++ /dev/null @@ -1,3 +0,0 @@ -// [line 3] Error: Unexpected character. -// [java line 3] Error at 'b': Expect ')' after arguments. -foo(a | b); diff --git a/interpreter/tests/lox/variable/collide_with_parameter.lox b/interpreter/tests/lox/variable/collide_with_parameter.lox index 2c06bd1..d00e08a 100644 --- a/interpreter/tests/lox/variable/collide_with_parameter.lox +++ b/interpreter/tests/lox/variable/collide_with_parameter.lox @@ -1,3 +1,3 @@ fun foo(a) { - var a; // Error at 'a': Already a variable with this name in this scope. + var a; }