forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.test.ts
148 lines (101 loc) · 2.21 KB
/
mem.test.ts
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
namespace $ {
$mol_test( {
'Property method' ($) {
class App extends $mol_object2 {
static $ = $
@ $mol_mem
static value( next = 1 ) { return next + 1 }
}
$mol_assert_equal( App.value() , 2 )
App.value( 2 )
$mol_assert_equal( App.value() , 3 )
} ,
'auto sync of properties'($) {
class X extends $mol_object2 {
@ $mol_mem
foo( next? : number ) {
return next || 1
}
@ $mol_mem
bar() {
return this.foo() + 1
}
@ $mol_mem
xxx() {
return this.bar() + 1
}
}
const x = new X
x.$ = $
$mol_assert_equal( x.bar() , 2 )
$mol_assert_equal( x.xxx() , 3 )
x.foo( 5 )
$mol_assert_equal( x.xxx() , 7 )
} ,
// 'must fail on recursive dependency'() {
// class App extends $mol_object {
// @ $mol_mem
// static foo() : number {
// return this.foo() + 1
// }
// }
// $mol_assert_fail( ()=> App.foo() )
// } ,
async 'must be deferred destroyed when no longer referenced'($) {
let foo : any
let foo_destroyed = false
class B extends $mol_object2 {
@ $mol_mem
showing( next? : boolean ) {
if( next === void 0 ) return true
return next
}
@ $mol_mem
foo() {
return foo = new class extends $mol_object {
destructor() {
foo_destroyed = true
}
}
}
@ $mol_mem
bar() {
return this.showing() ? this.foo() : null
}
}
var b = new B
b.$ = $
var bar = b.bar()
$mol_assert_ok( bar )
b.showing( false )
b.bar()
await $mol_fiber_warp()
$mol_assert_ok( foo_destroyed )
$mol_assert_not( b.bar() )
b.showing( true )
$mol_defer.run()
$mol_assert_unique( b.bar() , bar )
} ,
async 'wait for data'($) {
class Test extends $mol_object2 {
@ $mol_mem
source() : string {
return $mol_fiber_sync( ()=> new Promise< string >( done => done( 'Jin' ) ) )()
}
@ $mol_mem
middle() {
return this.source()
}
@ $mol_mem
target() {
return this.middle()
}
}
const t = new Test
t.$ = $
$mol_assert_fail( ()=> t.target().valueOf() , Promise )
await $mol_fiber_warp()
$mol_assert_equal( t.target() , 'Jin' )
} ,
} )
}