1
//! `UPCASE-STRING` and `STRING=` native fn codegen.
2

            
3
use super::common::{compile_and_validate, compile_expect_error, wrap_with_runtime_ratio};
4

            
5
#[test]
6
1
fn upcase_string_constant_folds() {
7
    // Static-string arg constant-folds to the upcased literal; the wasm
8
    // still validates as a script that prints/uses the string.
9
1
    compile_and_validate("(upcase-string \"hello\")");
10
1
}
11

            
12
#[test]
13
1
fn upcase_string_wrong_arity_errors() {
14
1
    let err = compile_expect_error("(upcase-string)");
15
1
    assert!(err.contains("UPCASE-STRING"), "got: {err}");
16
1
}
17

            
18
#[test]
19
1
fn upcase_string_non_string_errors() {
20
1
    let err = compile_expect_error("(upcase-string 42)");
21
1
    assert!(
22
1
        err.contains("UPCASE-STRING") && err.contains("string"),
23
        "got: {err}",
24
    );
25
1
}
26

            
27
#[test]
28
1
fn string_eq_constant_folds_equal() {
29
1
    compile_and_validate("(string= \"foo\" \"foo\")");
30
1
}
31

            
32
#[test]
33
1
fn string_eq_constant_folds_unequal() {
34
1
    compile_and_validate("(string= \"foo\" \"bar\")");
35
1
}
36

            
37
#[test]
38
1
fn string_eq_wrong_arity_errors() {
39
1
    let err = compile_expect_error("(string= \"foo\")");
40
1
    assert!(err.contains("STRING="), "got: {err}");
41
1
}
42

            
43
/// Non-string operand at compile_for_stack must surface a structured
44
/// error. `X` here is a Ratio runtime local — not a string — and the
45
/// arg-coercion path refuses it.
46
#[test]
47
1
fn string_eq_non_string_runtime_arg_errors() {
48
1
    let err = compile_expect_error(&wrap_with_runtime_ratio("(string= X \"foo\")"));
49
1
    assert!(
50
1
        err.contains("STRING=") && err.contains("string"),
51
        "got: {err}",
52
    );
53
1
}