1
//! `PP` and `APROPOS` builtins (DESCRIBE tests live in
2
//! `compile_eval_form.rs`). PP returns the formatted-text form of
3
//! its arg; APROPOS returns a quoted list of registry names matching
4
//! a substring.
5

            
6
use super::common::{compile_and_validate, compile_expect_error};
7

            
8
#[test]
9
1
fn pp_of_constant_number() {
10
1
    compile_and_validate("(pp 42)");
11
1
}
12

            
13
#[test]
14
1
fn pp_of_string() {
15
1
    compile_and_validate("(pp \"hello\")");
16
1
}
17

            
18
#[test]
19
1
fn pp_of_list() {
20
1
    compile_and_validate("(pp '(1 2 3))");
21
1
}
22

            
23
#[test]
24
1
fn pp_of_bool() {
25
1
    compile_and_validate("(pp t)");
26
1
}
27

            
28
#[test]
29
1
fn pp_of_nil() {
30
1
    compile_and_validate("(pp nil)");
31
1
}
32

            
33
#[test]
34
1
fn pp_wrong_arity_errors() {
35
1
    let err = compile_expect_error("(pp)");
36
1
    assert!(err.contains("PP"), "got: {err}");
37
1
}
38

            
39
#[test]
40
1
fn pp_too_many_args_errors() {
41
1
    let err = compile_expect_error("(pp 1 2)");
42
1
    assert!(err.contains("PP"), "got: {err}");
43
1
}
44

            
45
/// APROPOS answers a list of symbols, a `$pair` chain of `$symbol` cells in
46
/// every position (plan 0014 Stage 8).
47
#[test]
48
1
fn apropos_result_is_a_symbol_list() {
49
1
    for src in [
50
1
        "(apropos \"entity\")",
51
1
        "(apropos \"transaction\")",
52
1
        "(apropos 'list)",
53
1
    ] {
54
3
        compile_and_validate(src);
55
    }
56
1
}
57

            
58
#[test]
59
1
fn apropos_empty_match_is_empty_list() {
60
1
    compile_and_validate("(apropos \"no-such-thing-anywhere\")");
61
1
}
62

            
63
#[test]
64
1
fn apropos_wrong_arity_errors() {
65
1
    let err = compile_expect_error("(apropos)");
66
1
    assert!(err.contains("APROPOS"), "got: {err}");
67
1
}
68

            
69
#[test]
70
1
fn apropos_non_string_errors() {
71
1
    let err = compile_expect_error("(apropos 42)");
72
1
    assert!(err.contains("APROPOS"), "got: {err}");
73
1
}