<commit_before>use helpers::*;
use helpers::values::*;

#[test]
fn integers() {
    assert_eval_err("(0 1 2)", unappliable_value_error(integer(0)));
}

#[test]
fn dotted_lists() {
    assert_eval_err("(1 . 2)", irreducible_value(ast::dotted_list(vec!(ast::integer(1)), ast::integer(2))));
}

#[test]
fn booleans() {
    assert_eval_err("(#t #f #t)", unappliable_value_error(bool(true)));
}

#[test]
fn atoms() {
    assert_eval_err("(a b c)", unbound_variable_error("a"));
}

#[test]
fn lists() {
    assert_eval_err("('(1))", unappliable_value_error(list(vec!(atom("quote"),
                                                                list(vec!(integer(1)))))));
}

#[test]
fn expressions_in_first_position() {
    assert_eval("(define (x) 1)
                 ((if #t x))", "1");
}

#[test]
fn procedure_with_no_args() {
    assert_eval("(define (x) 1)
                 (x)", "1");
}

#[test]
fn procedure_with_one_arg() {
    assert_eval("(define (x y) y)
                 (x (+ 2 9))", "11");
}

#[test]
fn procedure_with_two_args() {
    assert_eval("(define (sum x y) (+ x y))
                 (sum 4 9)", "13");
}

#[test]
fn procedure_with_var_args() {
    assert_eval("(define (sum x . y) y)
                 (sum 4 9)", "'(9)");
}

#[test]
fn procedure_with_any_args() {
    assert_eval("(define (sum . y) y)
                 (sum 4 9)", "'(4 9)");
}

#[test]
fn procedure_with_two_args_scoping() {
    assert_eval("(define x 10)
                 (define (sum x y) (+ x y))
                 (sum 4 9)", "13");
}

#[test]
fn procedure_with_two_args_previous_scoping_is_kept() {
    assert_eval("(define x 10)
                 (define (sum x y) (+ x y))
                 (sum 4 9)
                 x", "10");
}

#[test]
fn procedure_with_mismatched_arity() {
    assert_eval_err("(define (sum x y) (+ x y))
                     (sum 4)", bad_arity("sum"));
}

#[test]
fn lambda_multiple_expressions_are_evaluated_sequentially() {
    assert_eval("(define (foo)
                    (define a 10)
                    (define b (+ a 1))
                    (define c (+ b 1))
                    c)
                  (foo)",
                "12");
}

#[test]
fn lambda_with_fixed_arguments_number() {
    assert_eval("((lambda () 1))", "1");
    assert_eval("((lambda (x y) (+ x y)) 6 8)", "14");
}

#[test]
fn lambda_with_fixed_arguments_number_bad_arity() {
    assert_eval_err("((lambda (x y) (+ x y)) 6 8 9)", bad_arity_lambda());
}

#[test]
fn lambda_with_any_arguments_number() {
    assert_eval("((lambda x x))", "'()");
    assert_eval("((lambda x x) 1 2 3)", "'(1 2 3)");
}

#[test]
fn lambda_with_variable_arguments_number() {
    assert_eval("((lambda (x . y) x) 1)", "1");
    assert_eval("((lambda (x . y) y) 1)", "'()");
    assert_eval("((lambda (x . y) y) 1 2 3)", "'(2 3)");
    assert_eval("((lambda (x y . z) z) 1 2 3)", "'(3)");
}

#[test]
fn lambda_with_variable_arguments_number_bad_arity() {
    assert_eval_err("((lambda (x . y) 1))", bad_arity_lambda());
    assert_eval_err("((lambda (x y . z) 1) 1)", bad_arity_lambda());
}
<commit_msg>Moved some tests on function application to use the vm.<commit_after>use helpers::*;
use helpers::values::*;

#[test]
fn integers() {
    assert_eval_vm_err("(0 1 2)", malformed_expr());
}

#[test]
fn dotted_lists() {
    assert_eval_vm_err("(1 . 2)", malformed_expr());
}

#[test]
fn booleans() {
    assert_eval_vm_err("(#t #f #t)", malformed_expr());
}

#[test]
fn atoms() {
    assert_eval_vm_err("(a b c)", unbound_variable_error("b"));
}

#[test]
fn lists() {
    assert_eval_vm_err("('(1))", malformed_expr());
}

#[test]
fn expressions_in_first_position() {
    assert_eval("(define (x) 1)
                 ((if #t x))", "1");
}

#[test]
fn procedure_with_no_args() {
    assert_eval("(define (x) 1)
                 (x)", "1");
}

#[test]
fn procedure_with_one_arg() {
    assert_eval("(define (x y) y)
                 (x (+ 2 9))", "11");
}

#[test]
fn procedure_with_two_args() {
    assert_eval("(define (sum x y) (+ x y))
                 (sum 4 9)", "13");
}

#[test]
fn procedure_with_var_args() {
    assert_eval("(define (sum x . y) y)
                 (sum 4 9)", "'(9)");
}

#[test]
fn procedure_with_any_args() {
    assert_eval("(define (sum . y) y)
                 (sum 4 9)", "'(4 9)");
}

#[test]
fn procedure_with_two_args_scoping() {
    assert_eval("(define x 10)
                 (define (sum x y) (+ x y))
                 (sum 4 9)", "13");
}

#[test]
fn procedure_with_two_args_previous_scoping_is_kept() {
    assert_eval("(define x 10)
                 (define (sum x y) (+ x y))
                 (sum 4 9)
                 x", "10");
}

#[test]
fn procedure_with_mismatched_arity() {
    assert_eval_err("(define (sum x y) (+ x y))
                     (sum 4)", bad_arity("sum"));
}

#[test]
fn lambda_multiple_expressions_are_evaluated_sequentially() {
    assert_eval("(define (foo)
                    (define a 10)
                    (define b (+ a 1))
                    (define c (+ b 1))
                    c)
                  (foo)",
                "12");
}

#[test]
fn lambda_with_fixed_arguments_number() {
    assert_eval("((lambda () 1))", "1");
    assert_eval("((lambda (x y) (+ x y)) 6 8)", "14");
}

#[test]
fn lambda_with_fixed_arguments_number_bad_arity() {
    assert_eval_err("((lambda (x y) (+ x y)) 6 8 9)", bad_arity_lambda());
}

#[test]
fn lambda_with_any_arguments_number() {
    assert_eval("((lambda x x))", "'()");
    assert_eval("((lambda x x) 1 2 3)", "'(1 2 3)");
}

#[test]
fn lambda_with_variable_arguments_number() {
    assert_eval("((lambda (x . y) x) 1)", "1");
    assert_eval("((lambda (x . y) y) 1)", "'()");
    assert_eval("((lambda (x . y) y) 1 2 3)", "'(2 3)");
    assert_eval("((lambda (x y . z) z) 1 2 3)", "'(3)");
}

#[test]
fn lambda_with_variable_arguments_number_bad_arity() {
    assert_eval_err("((lambda (x . y) 1))", bad_arity_lambda());
    assert_eval_err("((lambda (x y . z) 1) 1)", bad_arity_lambda());
}

{'fraction_non_alphanumeric': 0.1979933110367893, 'fraction_numerical': 0.025418060200668897, 'mean_word_length': 2.69882498453927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254920', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2202, 'n_words': 519}