Initial commit
Includes: runtime base from a previous project, syn(tax) module with parser and lexer Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
73
runtime/src/obj/test.rs
Normal file
73
runtime/src/obj/test.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use crate::obj::{names::*, prelude::*};
|
||||
use once_cell::sync::Lazy;
|
||||
use shredder::*;
|
||||
use std::sync::Mutex;
|
||||
|
||||
static TEST_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
||||
|
||||
#[test]
|
||||
fn test_sym_plumbing() {
|
||||
// Most of this test is making sure we are free of runtime infinite recursion issues with
|
||||
// initializing static data (NIL_OBJ, SYM_TY, SYM_ATTRS)
|
||||
|
||||
let _guard = TEST_LOCK.lock().unwrap();
|
||||
let start = number_of_tracked_allocations(); // need 'start' because of static allocations
|
||||
run_with_gc_cleanup(|| {
|
||||
assert_eq!(number_of_tracked_allocations(), start + 0);
|
||||
|
||||
let nil = NIL_OBJ.clone();
|
||||
|
||||
// nil sym obj
|
||||
assert_eq!(number_of_tracked_allocations(), start + 1);
|
||||
|
||||
{
|
||||
read_obj!(let nil_obj = nil);
|
||||
let sym: Sym = **nil_obj;
|
||||
assert_eq!(*NIL_SYM, sym);
|
||||
assert_eq!(number_of_tracked_allocations(), start + 1);
|
||||
|
||||
// nil_obj.attrs will initialize:
|
||||
// - SYM_ATTRS (not an object)
|
||||
// + SYM_TY
|
||||
// + SYM_TY_SYM_OBJ
|
||||
// - SYM_TY_SYM (not an object)
|
||||
// + TY_MEMBER_SYM
|
||||
// + TY_TY
|
||||
// - SYM_TY_SYM_OBJ (already initialized)
|
||||
nil_obj.attrs();
|
||||
let ty_sym_obj = SYM_TY_SYM_OBJ.clone();
|
||||
assert_eq!(number_of_tracked_allocations(), start + 5);
|
||||
}
|
||||
|
||||
let on = TRUE_OBJ.clone();
|
||||
// true sym obj, sym ty obj shouldn't be duplicated
|
||||
assert_eq!(number_of_tracked_allocations(), start + 6);
|
||||
|
||||
let off = FALSE_OBJ.clone();
|
||||
// false sym obj, sym ty obj shouldn't be duplicated
|
||||
assert_eq!(number_of_tracked_allocations(), start + 7);
|
||||
});
|
||||
// these are *static* values, so there will always remain at least one reference.
|
||||
assert_eq!(number_of_tracked_allocations(), start + 7);
|
||||
// TODO ^ prove the above
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dyn_obj_ref_eq() {
|
||||
#[derive(Default, Debug, Scan)]
|
||||
struct FooObj { attrs: Attrs }
|
||||
|
||||
impl_obj!(FooObj, attrs);
|
||||
|
||||
let _guard = TEST_LOCK.lock().unwrap();
|
||||
let start = number_of_tracked_allocations(); // need 'start' because of static allocations
|
||||
run_with_gc_cleanup(|| {
|
||||
let rf1: ObjRef = ObjRef::new(FooObj::default());
|
||||
let rf2 = rf1.clone();
|
||||
|
||||
assert!(rf1.ref_eq(&rf2));
|
||||
assert!(rf2.ref_eq(&rf1));
|
||||
assert_eq!(number_of_tracked_allocations(), start + 1);
|
||||
});
|
||||
assert_eq!(number_of_tracked_allocations(), start + 0);
|
||||
}
|
||||
Reference in New Issue
Block a user