flok 0.0.40 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/drivers/chrome/src/dispatch.js +7 -2
- data/app/kern/dispatch.js +10 -1
- data/app/kern/mod/event.js +9 -0
- data/app/kern/pagers/pg_mem.js +21 -0
- data/app/kern/pagers/pg_net_sim.js +44 -0
- data/app/kern/pagers/pg_spec.js +23 -0
- data/app/kern/services/vm.rb +60 -64
- data/bin/flok +44 -23
- data/docs/callout.md +1 -1
- data/docs/client_api.md +5 -2
- data/docs/config_yml.md +41 -0
- data/docs/controllers.md +4 -0
- data/docs/datatypes.md +5 -2
- data/docs/debug_server.md +2 -0
- data/docs/dispatch.md +8 -3
- data/docs/known_issues.md +6 -0
- data/docs/mod/event.md +25 -20
- data/docs/mod/persist.md +1 -1
- data/docs/mod/speech.md +12 -0
- data/docs/project.md +2 -2
- data/docs/services/vm.md +46 -17
- data/docs/services/vm/pagers.md +22 -2
- data/lib/flok/build.rb +0 -4
- data/lib/flok/user_compiler.rb +123 -47
- data/lib/flok/user_compiler_templates/ctable.js.erb +39 -1
- data/lib/flok/version.rb +1 -1
- data/spec/env/global.rb +1 -0
- data/spec/env/kern.rb +5 -1
- data/spec/etc/cli_spec.rb +337 -322
- data/spec/etc/service_compiler/config0.rb +1 -1
- data/spec/etc/service_compiler/config0b.rb +1 -0
- data/spec/etc/services_compiler_spec.rb +29 -29
- data/spec/etc/user_compiler/controller0b.rb +9 -0
- data/spec/etc/user_compiler/controller0timer.rb +16 -0
- data/spec/etc/user_compiler_spec.rb +24 -1
- data/spec/iface/driver/dispatch_spec.rb +8 -2
- data/spec/iface/driver/persist_spec.rb +11 -0
- data/spec/kern/assets/controller0defer.rb +18 -0
- data/spec/kern/assets/controller0defer0.rb +13 -0
- data/spec/kern/assets/controller0defer2.rb +17 -0
- data/spec/kern/assets/global_on_entry.rb +8 -0
- data/spec/kern/assets/global_on_entry2.rb +16 -0
- data/spec/kern/assets/global_on_entry3.rb +17 -0
- data/spec/kern/assets/global_on_entry4.rb +12 -0
- data/spec/kern/assets/interval.rb +29 -0
- data/spec/kern/assets/interval2.rb +33 -0
- data/spec/kern/assets/interval3.rb +39 -0
- data/spec/kern/assets/service1.rb +4 -1
- data/spec/kern/assets/service_controller1.rb +11 -0
- data/spec/kern/assets/specimin/controller0.rb +74 -0
- data/spec/kern/assets/vm/config5.rb +20 -0
- data/spec/kern/assets/vm/config6.rb +20 -0
- data/spec/kern/assets/vm/controller10.rb +1 -1
- data/spec/kern/assets/vm/controller11.rb +1 -1
- data/spec/kern/assets/vm/controller12.rb +1 -1
- data/spec/kern/assets/vm/controller13.rb +1 -1
- data/spec/kern/assets/vm/controller16b.rb +28 -0
- data/spec/kern/assets/vm/controller18.rb +1 -1
- data/spec/kern/assets/vm/controller21.rb +1 -1
- data/spec/kern/assets/vm/controller22.rb +8 -0
- data/spec/kern/assets/vm/controller_exc_ewatch.rb +1 -0
- data/spec/kern/assets/vm/controller_exc_ewatch2.rb +30 -0
- data/spec/kern/assets/vm/controller_exc_ewatch3.rb +16 -0
- data/spec/kern/assets/vm/controller_exc_ewatch4.rb +16 -0
- data/spec/kern/assets/vm/macros/copy_page_c.rb +1 -0
- data/spec/kern/assets/vm/macros/copy_page_ch.rb +25 -0
- data/spec/kern/assets/vm/macros/entry_del_c.rb +1 -0
- data/spec/kern/assets/vm/macros/entry_del_ch.rb +20 -0
- data/spec/kern/assets/vm/macros/entry_insert_c.rb +1 -0
- data/spec/kern/assets/vm/macros/entry_insert_ch.rb +23 -0
- data/spec/kern/assets/vm/macros/entry_mutable_c.rb +8 -7
- data/spec/kern/assets/vm/macros/entry_mutable_ch.rb +34 -0
- data/spec/kern/assets/vm/macros/new_page_c.rb +1 -1
- data/spec/kern/assets/vm/macros/new_page_c2.rb +1 -1
- data/spec/kern/assets/vm/macros/new_page_ch.rb +7 -0
- data/spec/kern/assets/vm/pg_mem/config.rb +10 -0
- data/spec/kern/assets/vm/pg_mem/config1.rb +10 -0
- data/spec/kern/assets/vm/pg_mem/config2.rb +10 -0
- data/spec/kern/assets/vm/pg_mem/config3.rb +15 -0
- data/spec/kern/assets/vm/pg_mem/write.rb +23 -0
- data/spec/kern/assets/vm/pg_mem/write2.rb +38 -0
- data/spec/kern/assets/vm/pg_net_sim/config.rb +10 -0
- data/spec/kern/assets/vm/pg_net_sim/nothing.rb +12 -0
- data/spec/kern/assets/vm/pg_net_sim/pages.json +1 -0
- data/spec/kern/assets/vm/pg_net_sim/watch.rb +18 -0
- data/spec/kern/callout_spec.rb +1 -1
- data/spec/kern/controller_macro_spec.rb +153 -20
- data/spec/kern/controller_spec.rb +232 -1
- data/spec/kern/debug_ui_spec.rb +235 -235
- data/spec/kern/event_spec.rb +112 -0
- data/spec/kern/service_controller_spec.rb +14 -2
- data/spec/kern/vm_service_mem_pagers_spec.rb +117 -0
- data/spec/kern/vm_service_net_sim_pager_spec.rb +97 -0
- data/spec/kern/vm_service_spec.rb +304 -17
- data/spec/kern/vm_service_spec2.rb +39 -0
- metadata +88 -6
- data/app/kern/pagers/mem_pager.js +0 -2
- data/app/kern/pagers/pg_spec0.js +0 -20
- data/lib/flok/project_template/Guardfile +0 -7
- data/lib/flok/project_template/config/config.yml +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#Simple service config that uses built-in spec service to create a instance called 'spec'
|
|
2
|
+
service_instance :vm, :vm, {
|
|
3
|
+
:pagers => [
|
|
4
|
+
{
|
|
5
|
+
:name => "pg_mem0",
|
|
6
|
+
:namespace => "local0",
|
|
7
|
+
:options => {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
:name => "pg_mem1",
|
|
11
|
+
:namespace => "local1",
|
|
12
|
+
:options => {}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
controller :my_controller do
|
|
2
|
+
services :vm
|
|
3
|
+
|
|
4
|
+
action :my_action do
|
|
5
|
+
on_entry %{
|
|
6
|
+
var entry = {
|
|
7
|
+
hello: "world"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
page = NewPage("test");
|
|
11
|
+
SetPageHead(page, "head");
|
|
12
|
+
SetPageNext(page, "next");
|
|
13
|
+
EntryInsert(page, 0, entry);
|
|
14
|
+
|
|
15
|
+
var write_info = {
|
|
16
|
+
ns: "local",
|
|
17
|
+
page: page
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Request("vm", "write", write_info);
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
controller :my_controller do
|
|
2
|
+
services :vm
|
|
3
|
+
|
|
4
|
+
action :my_action do
|
|
5
|
+
on_entry %{
|
|
6
|
+
var entry = {
|
|
7
|
+
hello: "world"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var entry2 = {
|
|
11
|
+
hello: "world"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
page = NewPage("test");
|
|
16
|
+
SetPageHead(page, "head");
|
|
17
|
+
SetPageNext(page, "next");
|
|
18
|
+
EntryInsert(page, 0, entry);
|
|
19
|
+
|
|
20
|
+
var write_info = {
|
|
21
|
+
ns: "local0",
|
|
22
|
+
page: page
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
page2 = CopyPage(page);
|
|
26
|
+
EntryInsert(page2, 0, entry);
|
|
27
|
+
|
|
28
|
+
var write_info2 = {
|
|
29
|
+
ns: "local1",
|
|
30
|
+
page: page2
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Request("vm", "write", write_info);
|
|
35
|
+
Request("vm", "write", write_info2);
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"_head":null,"_next":"7f3d373","_id":"weight","entries":[],"_hash":"1822752852"},{"_head":"weight","_next":"9ffd52a","_id":"7f3d373","entries":[{"_id":"a85c876","_sig":"9349266","date":1434381745,"value":220},{"_id":"050bc6a","_sig":"f824a7b","date":0,"value":202},{"_id":"8977e46","_sig":"30d51c1","date":0,"value":203},{"_id":"99bbc39","_sig":"f868f7c","date":0,"value":208},{"_id":"ff6854e","_sig":"517513c","date":0,"value":224},{"_id":"8fb9997","_sig":"da00718","date":0,"value":212},{"_id":"0ff5e6c","_sig":"d336c63","date":0,"value":208},{"_id":"56c7036","_sig":"9d36d3a","date":0,"value":227},{"_id":"a94507a","_sig":"edd2a57","date":0,"value":223},{"_id":"80d494a","_sig":"7834992","date":0,"value":218}],"_hash":"140966661"}]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
controller :my_controller do
|
|
2
|
+
services :vm
|
|
3
|
+
|
|
4
|
+
action :my_action do
|
|
5
|
+
on_entry %{
|
|
6
|
+
var watch_info = {
|
|
7
|
+
ns: "net",
|
|
8
|
+
id: "weight",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
Request("vm", "watch", watch_info);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
on "read_res", %{
|
|
15
|
+
read_res_params = params;
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
end
|
data/spec/kern/callout_spec.rb
CHANGED
|
@@ -4,7 +4,7 @@ require './spec/lib/helpers.rb'
|
|
|
4
4
|
require './spec/lib/io_extensions.rb'
|
|
5
5
|
require './spec/lib/rspec_extensions.rb'
|
|
6
6
|
|
|
7
|
-
RSpec.describe "kern:
|
|
7
|
+
RSpec.describe "kern:callout_spec" do
|
|
8
8
|
include_context "kern"
|
|
9
9
|
|
|
10
10
|
it "Can register for single-shot a callout event 1 tick in the future" do
|
|
@@ -12,7 +12,7 @@ require './spec/lib/rspec_extensions.rb'
|
|
|
12
12
|
RSpec.describe "kern:controller_macro_spec" do
|
|
13
13
|
include_context "kern"
|
|
14
14
|
|
|
15
|
-
it "Can use the NewPage macro" do
|
|
15
|
+
it "Can use the NewPage macro for an array" do
|
|
16
16
|
#Compile the controller
|
|
17
17
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/new_page_c.rb')
|
|
18
18
|
ctx.eval %{
|
|
@@ -26,11 +26,31 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
26
26
|
"_head" => nil,
|
|
27
27
|
"_next" => nil,
|
|
28
28
|
"entries" => [],
|
|
29
|
-
"_id" => nil
|
|
29
|
+
"_id" => nil,
|
|
30
|
+
"_type" => "array"
|
|
30
31
|
})
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
it "Can use the NewPage macro
|
|
34
|
+
it "Can use the NewPage macro for an hash" do
|
|
35
|
+
#Compile the controller
|
|
36
|
+
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/new_page_ch.rb')
|
|
37
|
+
ctx.eval %{
|
|
38
|
+
base = _embed("controller", 0, {}, null);
|
|
39
|
+
int_dispatch([]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#Check the page variable
|
|
43
|
+
page = JSON.parse(ctx.eval("JSON.stringify(page)"))
|
|
44
|
+
expect(page).to eq({
|
|
45
|
+
"_head" => nil,
|
|
46
|
+
"_next" => nil,
|
|
47
|
+
"entries" => {},
|
|
48
|
+
"_id" => nil,
|
|
49
|
+
"_type" => "hash"
|
|
50
|
+
})
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "Can use the NewPage macro with id for array" do
|
|
34
54
|
#Compile the controller
|
|
35
55
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/new_page_c2.rb')
|
|
36
56
|
ctx.eval %{
|
|
@@ -44,13 +64,36 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
44
64
|
"_head" => nil,
|
|
45
65
|
"_next" => nil,
|
|
46
66
|
"entries" => [],
|
|
47
|
-
"_id" => "test"
|
|
67
|
+
"_id" => "test",
|
|
68
|
+
"_type" => "array"
|
|
48
69
|
})
|
|
49
70
|
end
|
|
50
71
|
|
|
51
|
-
it "Can use the CopyPage macro" do
|
|
72
|
+
it "Can use the CopyPage macro for array" do
|
|
52
73
|
#Compile the controller
|
|
53
74
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/copy_page_c.rb')
|
|
75
|
+
ctx.eval %{
|
|
76
|
+
base = _embed("controller", 1, {}, null);
|
|
77
|
+
int_dispatch([]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#not_copied page is just a reference to original_page, checked for sanity
|
|
81
|
+
original_page = JSON.parse(ctx.eval("JSON.stringify(original_page)"))
|
|
82
|
+
not_copied_page = JSON.parse(ctx.eval("JSON.stringify(not_copied_page)"))
|
|
83
|
+
copied_page = JSON.parse(ctx.eval("JSON.stringify(copied_page)"))
|
|
84
|
+
|
|
85
|
+
#What the copied page should look like after a copy
|
|
86
|
+
copied_should_look_like = JSON.parse(original_page.to_json)
|
|
87
|
+
copied_should_look_like["_next"] = "test" #Set in controller
|
|
88
|
+
copied_should_look_like.delete "_hash"
|
|
89
|
+
|
|
90
|
+
expect(not_copied_page).to eq(original_page)
|
|
91
|
+
expect(copied_page).to eq(copied_should_look_like)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "Can use the CopyPage macro for hash" do
|
|
95
|
+
#Compile the controller
|
|
96
|
+
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/copy_page_ch.rb')
|
|
54
97
|
ctx.eval %{
|
|
55
98
|
base = _embed("controller", 0, {}, null);
|
|
56
99
|
int_dispatch([]);
|
|
@@ -70,7 +113,7 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
70
113
|
expect(copied_page).to eq(copied_should_look_like)
|
|
71
114
|
end
|
|
72
115
|
|
|
73
|
-
it "Can use the EntryDel macro" do
|
|
116
|
+
it "Can use the EntryDel macro for an array" do
|
|
74
117
|
#Compile the controller
|
|
75
118
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_del_c.rb')
|
|
76
119
|
ctx.eval %{
|
|
@@ -86,6 +129,7 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
86
129
|
"_head" => "head",
|
|
87
130
|
"_id" => "id",
|
|
88
131
|
"_next" => "next",
|
|
132
|
+
"_type" => "array",
|
|
89
133
|
"entries" => []
|
|
90
134
|
})
|
|
91
135
|
|
|
@@ -96,11 +140,50 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
96
140
|
"entries" => [{
|
|
97
141
|
"_id" => "id", "_sig" => "sig"
|
|
98
142
|
}],
|
|
99
|
-
"_hash" => "hash"
|
|
143
|
+
"_hash" => "hash",
|
|
144
|
+
"_type" => "array"
|
|
100
145
|
})
|
|
101
146
|
end
|
|
102
147
|
|
|
103
|
-
it "Can use the
|
|
148
|
+
it "Can use the EntryDel macro for an hash" do
|
|
149
|
+
#Compile the controller
|
|
150
|
+
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_del_ch.rb')
|
|
151
|
+
ctx.eval %{
|
|
152
|
+
base = _embed("controller", 0, {}, null);
|
|
153
|
+
int_dispatch([]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#not_copied page is just a reference to original_page, checked for sanity
|
|
157
|
+
original_page = JSON.parse(ctx.eval("JSON.stringify(original_page)"))
|
|
158
|
+
page = JSON.parse(ctx.eval("JSON.stringify(page)"))
|
|
159
|
+
|
|
160
|
+
#The new page, Making sure it's not referenced
|
|
161
|
+
expect(page).to eq({
|
|
162
|
+
"_head" => "head",
|
|
163
|
+
"_id" => "id",
|
|
164
|
+
"_next" => "next",
|
|
165
|
+
"_type" => "hash",
|
|
166
|
+
"entries" => {
|
|
167
|
+
"id1" => {
|
|
168
|
+
"_sig" => "sig2"
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
expect(original_page).to eq({
|
|
174
|
+
"_head" => "head",
|
|
175
|
+
"_id" => "id",
|
|
176
|
+
"_next" => "next",
|
|
177
|
+
"_hash" => "hash",
|
|
178
|
+
"_type" => "hash",
|
|
179
|
+
"entries" => {
|
|
180
|
+
"id0" => {"_sig" => "sig"},
|
|
181
|
+
"id1" => {"_sig" => "sig2"},
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "Can use the EntryInsert macro on an array" do
|
|
104
187
|
#Compile the controller
|
|
105
188
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_insert_c.rb')
|
|
106
189
|
ctx.eval %{
|
|
@@ -117,13 +200,38 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
117
200
|
expect(page["entries"][2]["hello"]).to eq("world2")
|
|
118
201
|
|
|
119
202
|
expect(page["entries"][0]["_sig"]).not_to eq(nil)
|
|
203
|
+
expect(page["entries"][0]["_sig"]).not_to eq("sig")
|
|
120
204
|
expect(page["entries"][0]["_sig"]).not_to eq(page["entries"][1]["_sig"])
|
|
121
205
|
expect(page["entries"][0]["_id"]).not_to eq(nil)
|
|
122
206
|
expect(page["entries"][2]["_id"]).not_to eq(page["entries"][0]["_id"])
|
|
123
207
|
expect(page["entries"][2]["_id"]).not_to eq(page["entries"][1]["_id"])
|
|
124
208
|
end
|
|
125
209
|
|
|
126
|
-
it "Can use the
|
|
210
|
+
it "Can use the EntryInsert macro on a hash" do
|
|
211
|
+
#Compile the controller
|
|
212
|
+
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_insert_ch.rb')
|
|
213
|
+
ctx.eval %{
|
|
214
|
+
base = _embed("controller", 0, {}, null);
|
|
215
|
+
int_dispatch([]);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
#not_copied page is just a reference to original_page, checked for sanity
|
|
219
|
+
original_page = JSON.parse(ctx.eval("JSON.stringify(original_page)"))
|
|
220
|
+
page = JSON.parse(ctx.eval("JSON.stringify(page)"))
|
|
221
|
+
|
|
222
|
+
expect(page["entries"].keys.count).to eq(3)
|
|
223
|
+
expect(page["entries"]["id0"]["hello"]).to eq("world")
|
|
224
|
+
expect(page["entries"]["id2"]["hello"]).to eq("world2")
|
|
225
|
+
|
|
226
|
+
expect(page["entries"]["id0"]["_sig"]).not_to eq(nil)
|
|
227
|
+
expect(page["entries"]["id0"]["_sig"]).not_to eq("sig0")
|
|
228
|
+
expect(page["entries"]["id1"]["_sig"]).to eq("sig1")
|
|
229
|
+
expect(page["entries"]["id0"]["_sig"]).not_to eq(page["entries"]["id1"]["_sig"])
|
|
230
|
+
expect(page["entries"]["id2"]["_sig"]).not_to eq(nil)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
it "Can use the EntryMutable macro for array" do
|
|
127
235
|
#Compile the controller
|
|
128
236
|
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_mutable_c.rb')
|
|
129
237
|
ctx.eval %{
|
|
@@ -135,23 +243,48 @@ RSpec.describe "kern:controller_macro_spec" do
|
|
|
135
243
|
original_page = JSON.parse(ctx.eval("JSON.stringify(original_page)"))
|
|
136
244
|
page = JSON.parse(ctx.eval("JSON.stringify(page)"))
|
|
137
245
|
|
|
246
|
+
#This should remain unchanged
|
|
247
|
+
expect(original_page["entries"]).to eq([
|
|
248
|
+
{"_id" => "id1", "_sig" => "sig1", "foo" => "bar"},
|
|
249
|
+
{"_id" => "id2", "_sig" => "sig2"},
|
|
250
|
+
])
|
|
251
|
+
|
|
252
|
+
#New page
|
|
138
253
|
entries = page["entries"]
|
|
139
|
-
original_entries = original_page["entries"]
|
|
140
254
|
expect(entries[0]["hello"]).to eq("world")
|
|
255
|
+
expect(entries[0]["_sig"]).not_to eq("sig1")
|
|
141
256
|
expect(entries[0]["foo"]).to eq(nil)
|
|
142
|
-
expect(entries[
|
|
143
|
-
expect(entries[
|
|
257
|
+
expect(entries[1]["hello"]).to eq("world")
|
|
258
|
+
expect(entries[1]["_sig"]).not_to eq("sig2")
|
|
259
|
+
expect(entries[1]["foo"]).to eq(nil)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it "Can use the EntryMutable macro for hash" do
|
|
263
|
+
#Compile the controller
|
|
264
|
+
ctx = flok_new_user File.read('./spec/kern/assets/vm/macros/entry_mutable_ch.rb')
|
|
265
|
+
ctx.eval %{
|
|
266
|
+
base = _embed("controller", 0, {}, null);
|
|
267
|
+
int_dispatch([]);
|
|
268
|
+
}
|
|
144
269
|
|
|
145
|
-
#
|
|
146
|
-
|
|
147
|
-
|
|
270
|
+
#not_copied page is just a reference to original_page, checked for sanity
|
|
271
|
+
original_page = JSON.parse(ctx.eval("JSON.stringify(original_page)"))
|
|
272
|
+
page = JSON.parse(ctx.eval("JSON.stringify(page)"))
|
|
148
273
|
|
|
149
274
|
#This should remain unchanged
|
|
150
|
-
expect(original_page["entries"]).to eq(
|
|
151
|
-
{"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
275
|
+
expect(original_page["entries"]).to eq({
|
|
276
|
+
"id1" => {"_sig" => "sig1", "foo" => "bar"},
|
|
277
|
+
"id2" => {"_sig" => "sig2"},
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
#New page
|
|
281
|
+
entries = page["entries"]
|
|
282
|
+
expect(entries["id1"]["hello"]).to eq("world")
|
|
283
|
+
expect(entries["id1"]["_sig"]).not_to eq("sig1")
|
|
284
|
+
expect(entries["id1"]["foo"]).to eq(nil)
|
|
285
|
+
expect(entries["id2"]["hello"]).to eq("world")
|
|
286
|
+
expect(entries["id2"]["_sig"]).not_to eq("sig2")
|
|
287
|
+
expect(entries["id2"]["foo"]).to eq(nil)
|
|
155
288
|
end
|
|
156
289
|
|
|
157
290
|
it "Can use the SetPageNext macro" do
|
|
@@ -497,7 +497,7 @@ RSpec.describe "kern:controller_spec" do
|
|
|
497
497
|
expect(raise_res_context).to eq({"secret" => "#{secret}", "hello" => "world"})
|
|
498
498
|
end
|
|
499
499
|
|
|
500
|
-
|
|
500
|
+
#Can signal a spot from a parent controller
|
|
501
501
|
it "Can signal a spot sub-controller and trigger an event" do
|
|
502
502
|
#Compile the controller
|
|
503
503
|
ctx = flok_new_user File.read('./spec/kern/assets/lower_event.rb')
|
|
@@ -517,4 +517,235 @@ RSpec.describe "kern:controller_spec" do
|
|
|
517
517
|
|
|
518
518
|
expect(lower_request_called_with).to eq({"secret" => "#{secret}"})
|
|
519
519
|
end
|
|
520
|
+
|
|
521
|
+
it "Does run the global on_entry function when it is present upon entering the first action" do
|
|
522
|
+
#Compile the controller
|
|
523
|
+
ctx = flok_new_user File.read('./spec/kern/assets/global_on_entry.rb')
|
|
524
|
+
|
|
525
|
+
#Run the embed function
|
|
526
|
+
secret = SecureRandom.hex
|
|
527
|
+
ctx.eval %{
|
|
528
|
+
//Call embed on main root view
|
|
529
|
+
base = _embed("my_controller", 0, {}, null);
|
|
530
|
+
|
|
531
|
+
//Drain queue
|
|
532
|
+
int_dispatch([]);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
expect(ctx.eval("global_on_entry_called")).to eq(true)
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
it "Does run the global on_entry function only on the first action and not subsequent actions" do
|
|
539
|
+
#Compile the controller
|
|
540
|
+
ctx = flok_new_user File.read('./spec/kern/assets/global_on_entry2.rb')
|
|
541
|
+
|
|
542
|
+
#Run the embed function
|
|
543
|
+
secret = SecureRandom.hex
|
|
544
|
+
ctx.eval %{
|
|
545
|
+
global_on_entry_called_count = 0;
|
|
546
|
+
|
|
547
|
+
//Call embed on main root view
|
|
548
|
+
base = _embed("my_controller", 0, {}, null);
|
|
549
|
+
|
|
550
|
+
//Drain queue
|
|
551
|
+
int_dispatch([3, "int_event", base, "test", {}]);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
expect(ctx.eval("global_on_entry_called_count")).to eq(1)
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
it "Does allow macros in the global on_entry function" do
|
|
558
|
+
#Compile the controller
|
|
559
|
+
ctx = flok_new_user File.read('./spec/kern/assets/global_on_entry3.rb')
|
|
560
|
+
|
|
561
|
+
#Run the embed function
|
|
562
|
+
secret = SecureRandom.hex
|
|
563
|
+
ctx.eval %{
|
|
564
|
+
global_on_entry_called_count = 0;
|
|
565
|
+
|
|
566
|
+
//Call embed on main root view
|
|
567
|
+
base = _embed("my_controller", 0, {}, null);
|
|
568
|
+
|
|
569
|
+
//Drain queue
|
|
570
|
+
int_dispatch([3, "int_event", base, "test", {}]);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
base = ctx.eval("base")
|
|
574
|
+
expect(ctx.eval("global_on_entry_called_count")).to eq(1)
|
|
575
|
+
@driver.ignore_up_to "if_event"
|
|
576
|
+
@driver.mexpect("if_event", [base, "test", {}])
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
it "Does allow context in the global on_entry function" do
|
|
580
|
+
#Compile the controller
|
|
581
|
+
ctx = flok_new_user File.read('./spec/kern/assets/global_on_entry4.rb')
|
|
582
|
+
|
|
583
|
+
#Run the embed function
|
|
584
|
+
secret = SecureRandom.hex
|
|
585
|
+
ctx.eval %{
|
|
586
|
+
global_on_entry_called_count = 0;
|
|
587
|
+
|
|
588
|
+
//Call embed on main root view
|
|
589
|
+
base = _embed("my_controller", 0, {}, null);
|
|
590
|
+
|
|
591
|
+
int_dispatch([]);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
base = ctx.eval("base")
|
|
595
|
+
@driver.ignore_up_to "if_event"
|
|
596
|
+
@driver.mexpect("if_event", [base, "context", {"base" => base, "secret" => "foo"}])
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
it "Does allow interval (every) events" do
|
|
600
|
+
#Compile the controller
|
|
601
|
+
ctx = flok_new_user File.read('./spec/kern/assets/interval.rb')
|
|
602
|
+
|
|
603
|
+
#Run the embed function
|
|
604
|
+
ctx.eval %{
|
|
605
|
+
//Call embed on main root view
|
|
606
|
+
base = _embed("my_controller", 0, {}, null);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
base = ctx.eval("base")
|
|
610
|
+
|
|
611
|
+
@driver.int "int_timer"
|
|
612
|
+
expect(ctx.eval("every_025_called_count")).to eq(1)
|
|
613
|
+
expect(ctx.eval("every_05_called_count")).to eq(0)
|
|
614
|
+
expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
615
|
+
|
|
616
|
+
@driver.int "int_timer"
|
|
617
|
+
expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
618
|
+
expect(ctx.eval("every_05_called_count")).to eq(1)
|
|
619
|
+
expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
620
|
+
|
|
621
|
+
@driver.int "int_timer"
|
|
622
|
+
expect(ctx.eval("every_025_called_count")).to eq(3)
|
|
623
|
+
expect(ctx.eval("every_05_called_count")).to eq(1)
|
|
624
|
+
expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
625
|
+
|
|
626
|
+
@driver.int "int_timer"
|
|
627
|
+
expect(ctx.eval("every_025_called_count")).to eq(4)
|
|
628
|
+
expect(ctx.eval("every_05_called_count")).to eq(2)
|
|
629
|
+
expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
630
|
+
|
|
631
|
+
@driver.int "int_timer"
|
|
632
|
+
expect(ctx.eval("every_025_called_count")).to eq(5)
|
|
633
|
+
expect(ctx.eval("every_05_called_count")).to eq(2)
|
|
634
|
+
expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
635
|
+
|
|
636
|
+
@driver.int "int_timer"
|
|
637
|
+
expect(ctx.eval("every_025_called_count")).to eq(6)
|
|
638
|
+
expect(ctx.eval("every_05_called_count")).to eq(3)
|
|
639
|
+
expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
640
|
+
|
|
641
|
+
@driver.int "int_timer"
|
|
642
|
+
expect(ctx.eval("every_025_called_count")).to eq(7)
|
|
643
|
+
expect(ctx.eval("every_05_called_count")).to eq(3)
|
|
644
|
+
expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
645
|
+
|
|
646
|
+
@driver.int "int_timer"
|
|
647
|
+
expect(ctx.eval("every_025_called_count")).to eq(8)
|
|
648
|
+
expect(ctx.eval("every_05_called_count")).to eq(4)
|
|
649
|
+
expect(ctx.eval("every_1_called_count")).to eq(2)
|
|
650
|
+
|
|
651
|
+
#Ignore up to, block must pass as well; if_event would otherwise include action
|
|
652
|
+
@driver.ignore_up_to("if_event", 0) do |args|
|
|
653
|
+
args[1] == "025_message"
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
#Now we expect our if_event messages
|
|
657
|
+
8.times do
|
|
658
|
+
@driver.ignore_up_to("if_event")
|
|
659
|
+
@driver.mexpect "if_event", [base, "025_message", {}]
|
|
660
|
+
end
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
#See 0000 docs/known_problems.md
|
|
664
|
+
#it "Does not call intervals of other actions; and still works when switching back actions" do
|
|
665
|
+
##Compile the controller
|
|
666
|
+
#ctx = flok_new_user File.read('./spec/kern/assets/interval2.rb')
|
|
667
|
+
|
|
668
|
+
##Run the embed function
|
|
669
|
+
#ctx.eval %{
|
|
670
|
+
#//Call embed on main root view
|
|
671
|
+
#base = _embed("my_controller", 0, {}, null);
|
|
672
|
+
#}
|
|
673
|
+
|
|
674
|
+
#base = ctx.eval("base")
|
|
675
|
+
|
|
676
|
+
##In first action, only 025 is enabled
|
|
677
|
+
#@driver.int "int_timer"
|
|
678
|
+
#expect(ctx.eval("every_025_called_count")).to eq(1)
|
|
679
|
+
#expect(ctx.eval("every_05_called_count")).to eq(0)
|
|
680
|
+
#expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
681
|
+
|
|
682
|
+
#@driver.int "int_timer"
|
|
683
|
+
#expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
684
|
+
#expect(ctx.eval("every_05_called_count")).to eq(0)
|
|
685
|
+
#expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
686
|
+
|
|
687
|
+
##Switch actions, only 05 and 01 are enabled
|
|
688
|
+
#ctx.eval %{ int_dispatch([base, "int_event", base, "next", {}]); }
|
|
689
|
+
|
|
690
|
+
#@driver.int "int_timer"
|
|
691
|
+
#expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
692
|
+
#expect(ctx.eval("every_05_called_count")).to eq(0)
|
|
693
|
+
#expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
694
|
+
|
|
695
|
+
#@driver.int "int_timer"
|
|
696
|
+
#expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
697
|
+
#expect(ctx.eval("every_05_called_count")).to eq(1)
|
|
698
|
+
#expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
699
|
+
|
|
700
|
+
#@driver.int "int_timer"
|
|
701
|
+
#expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
702
|
+
#expect(ctx.eval("every_05_called_count")).to eq(1)
|
|
703
|
+
#expect(ctx.eval("every_1_called_count")).to eq(0)
|
|
704
|
+
|
|
705
|
+
#@driver.int "int_timer"
|
|
706
|
+
#expect(ctx.eval("every_025_called_count")).to eq(2)
|
|
707
|
+
#expect(ctx.eval("every_05_called_count")).to eq(2)
|
|
708
|
+
#expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
709
|
+
|
|
710
|
+
##Now switch back to first action again, only 025 is enabled
|
|
711
|
+
#ctx.eval %{ int_dispatch([base, "int_event", base, "back", {}]); }
|
|
712
|
+
|
|
713
|
+
#@driver.int "int_timer"
|
|
714
|
+
#expect(ctx.eval("every_025_called_count")).to eq(3)
|
|
715
|
+
#expect(ctx.eval("every_05_called_count")).to eq(2)
|
|
716
|
+
#expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
717
|
+
|
|
718
|
+
#@driver.int "int_timer"
|
|
719
|
+
#expect(ctx.eval("every_025_called_count")).to eq(4)
|
|
720
|
+
#expect(ctx.eval("every_05_called_count")).to eq(2)
|
|
721
|
+
#expect(ctx.eval("every_1_called_count")).to eq(1)
|
|
722
|
+
#end
|
|
723
|
+
|
|
724
|
+
it "Does not fire interval after leaving a controller" do
|
|
725
|
+
#Compile the controller
|
|
726
|
+
ctx = flok_new_user File.read('./spec/kern/assets/interval3.rb')
|
|
727
|
+
|
|
728
|
+
#Run the embed function
|
|
729
|
+
ctx.eval %{
|
|
730
|
+
//Call embed on main root view
|
|
731
|
+
base = _embed("my_controller", 0, {}, null);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
base = ctx.eval("base")
|
|
735
|
+
|
|
736
|
+
@driver.int "int_timer"
|
|
737
|
+
expect(ctx.eval("timer_called")).to eq(1)
|
|
738
|
+
@driver.int "int_timer"
|
|
739
|
+
expect(ctx.eval("timer_called")).to eq(2)
|
|
740
|
+
|
|
741
|
+
#Switch controllers via Goto
|
|
742
|
+
ctx.eval %{ int_dispatch([base, "int_event", base, "next", {}]); }
|
|
743
|
+
|
|
744
|
+
#Now we expect our if_event messages
|
|
745
|
+
4.times do
|
|
746
|
+
@driver.int "int_timer"
|
|
747
|
+
end
|
|
748
|
+
|
|
749
|
+
expect(ctx.eval("timer_called")).to eq(2)
|
|
750
|
+
end
|
|
520
751
|
end
|