Skip to main content

tulisp/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod eval;
4mod macros;
5mod parse;
6
7pub mod builtin;
8
9mod cons;
10pub use cons::{BaseIter, Iter};
11
12mod context;
13pub use context::{Plist, Plistable, Rest, TulispContext};
14
15mod error;
16pub use error::{Error, ErrorKind};
17
18pub mod lists;
19
20mod number;
21pub use number::Number;
22
23mod value;
24pub use value::TulispAny;
25#[doc(hidden)]
26pub use value::TulispValue;
27
28mod object;
29pub use {
30    object::TulispObject, object::conversions::TulispConvertible, object::wrappers::generic::Shared,
31};
32
33#[cfg(test)]
34mod test_utils {
35    #[track_caller]
36    fn eval_string(ctx: &mut crate::TulispContext, s: &str) -> Result<crate::TulispObject, String> {
37        ctx.eval_string(s).map_err(|e| e.format(ctx))
38    }
39
40    #[track_caller]
41    fn must_eval_string(ctx: &mut crate::TulispContext, s: &str) -> crate::TulispObject {
42        match eval_string(ctx, s) {
43            Ok(t) => t,
44            Err(e) => {
45                panic!("{e}");
46            }
47        }
48    }
49
50    #[track_caller]
51    pub(crate) fn eval_assert_equal(ctx: &mut crate::TulispContext, a: &str, b: &str) {
52        let av = must_eval_string(ctx, a);
53        let bv = must_eval_string(ctx, b);
54        assert!(
55            crate::TulispObject::equal(&av, &bv),
56            "{}(=> {}) != {}(=> {})",
57            a,
58            av,
59            b,
60            bv
61        );
62    }
63
64    #[track_caller]
65    pub(crate) fn eval_assert(ctx: &mut crate::TulispContext, a: &str) {
66        let av = must_eval_string(ctx, a);
67        assert!(av.is_truthy(), "{}(=> {}) is not true", a, av);
68    }
69
70    #[track_caller]
71    pub(crate) fn eval_assert_not(ctx: &mut crate::TulispContext, a: &str) {
72        let av = must_eval_string(ctx, a);
73        assert!(av.null(), "{}(=> {}) is not nil", a, av);
74    }
75
76    #[track_caller]
77    pub(crate) fn eval_assert_error(ctx: &mut crate::TulispContext, a: &str, msg: &str) {
78        match eval_string(ctx, a) {
79            Ok(v) => panic!("Expected error but got {} for {}", v, a),
80            Err(e) => {
81                assert_eq!(e.to_string(), msg, "Error message mismatch for {}", a);
82            }
83        }
84    }
85}