1
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
2
// Cranelift backend refuses to run under Miri.
3
#![cfg(not(miri))]
4

            
5
//! `1+` / `1-` over a runtime argument lower like `(+ x 1)` / `(- x 1)`.
6

            
7
use nms::interpreter::Interpreter;
8
use scripting::nomiscript::format_value;
9

            
10
3
fn printed(src: &str) -> String {
11
3
    let mut interp = Interpreter::new(false).unwrap();
12
3
    let results = interp
13
3
        .eval(src)
14
        .unwrap_or_else(|e| panic!("eval {src:?}: {e}"));
15
3
    let value = results
16
3
        .into_iter()
17
3
        .next_back()
18
        .unwrap_or_else(|| panic!("eval {src:?} produced no value"));
19
3
    format_value(&value)
20
3
}
21

            
22
#[test]
23
1
fn a_runtime_index_steps_by_one() {
24
1
    assert_eq!(
25
1
        printed("(let ((g 0)) (dolist (y '(2)) (setf g y)) (list (1+ g) (1- g)))"),
26
1
        "(3 1)"
27
    );
28
1
}
29

            
30
#[test]
31
1
fn a_host_index_steps_by_one() {
32
1
    assert_eq!(
33
1
        printed("(list (1+ (entity-count)) (1- (entity-count)))"),
34
1
        "(1 -1)"
35
    );
36
1
}
37

            
38
#[test]
39
1
fn a_runtime_ratio_is_not_stepped_by_an_index() {
40
1
    let source = "(let ((g 1/2)) (dolist (y '(3/2)) (setf g y)) (list (1+ g) (1- g)))";
41
1
    let refused = Interpreter::new(false)
42
1
        .unwrap()
43
1
        .eval(source)
44
1
        .expect_err("a mix, CL (5/2 1/2)");
45
1
    assert!(
46
1
        refused
47
1
            .to_string()
48
1
            .contains("+ cannot mix an index (count) with a scalar"),
49
        "{refused}"
50
    );
51
1
}
52

            
53
#[test]
54
1
fn a_literal_argument_still_folds() {
55
1
    assert_eq!(printed("(list (1+ 5) (1- 5))"), "(6 4)");
56
1
}