-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlazy_val_test.rs
78 lines (63 loc) · 2.12 KB
/
lazy_val_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
extern crate gdlisp;
use super::common::*;
#[test]
pub fn simple_lazy_test() {
assert_eq!(parse_compile_decl("((deflazy x 100))"),
r#"extends Reference
static func _lazy_0():
var _this_file_1 = load("res://TEST.gd")
var _cond = null
if _this_file_1.has_meta("__gdlisp_Lazy__G_3"):
_cond = _this_file_1.get_meta("__gdlisp_Lazy__G_3")
else:
if true:
var _value_2 = 100
_this_file_1.set_meta("__gdlisp_Lazy__G_3", _value_2)
_cond = _value_2
else:
_cond = null
return _cond
static func x():
return GDLisp.cons(GDLisp.cons(GDLisp.intern("access-slot"), GDLisp.cons(GDLisp.cons(GDLisp.intern("contextual-load"), GDLisp.cons("res://TEST.gd", null)), GDLisp.cons(GDLisp.intern("_lazy_0"), null))), null)
"#);
}
#[test]
pub fn simple_private_lazy_test() {
// The private modifier should parse and work correctly, but it
// doesn't change the output compared to the simple_lazy_test case.
assert_eq!(parse_compile_decl("((deflazy x 100 private))"),
r#"extends Reference
static func _lazy_0():
var _this_file_1 = load("res://TEST.gd")
var _cond = null
if _this_file_1.has_meta("__gdlisp_Lazy__G_3"):
_cond = _this_file_1.get_meta("__gdlisp_Lazy__G_3")
else:
if true:
var _value_2 = 100
_this_file_1.set_meta("__gdlisp_Lazy__G_3", _value_2)
_cond = _value_2
else:
_cond = null
return _cond
static func x():
return GDLisp.cons(GDLisp.cons(GDLisp.intern("access-slot"), GDLisp.cons(GDLisp.cons(GDLisp.intern("contextual-load"), GDLisp.cons("res://TEST.gd", null)), GDLisp.cons(GDLisp.intern("_lazy_0"), null))), null)
"#);
}
#[test]
pub fn simple_lazy_run_test_1() {
assert_eq!(parse_and_run(r#"
((deflazy x 100)
(print x))
"#), "\n100\n");
}
#[test]
pub fn simple_lazy_run_test_2() {
// The 3 should only print once
assert_eq!(parse_and_run(r#"
((deflazy x (progn (print 3) 100))
(print x)
(print x))
"#), "\n3\n100\n100\n");
}
// TODO Test lazy vals getting reinitialized after a file is unloaded and reloaded