Skip to content

Commit 388de61

Browse files
authored
Merge pull request #9 from dyne/fix/up_zenexplorer
fix(zenexplorer): include new scenarios, if and foreach statements
2 parents fd8b27e + 1f976f6 commit 388de61

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
restroom-test
22
zendebug
33
zenexplorer
4+
breakroom
5+
breakroom-read

src/zenexplorer/default_statements.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/zenexplorer/load_statements.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ local function only_statements(steps, defaults)
77
end
88
local given_stms = only_statements(ZEN.given_steps)
99
local then_stms = only_statements(ZEN.then_steps)
10+
local foreach_stms = only_statements(ZEN.foreach_steps)
1011

1112
local SCENARIOS = {
1213
"array",
14+
"bbs",
1315
"bitcoin",
1416
"credential",
1517
"data",
@@ -18,38 +20,56 @@ local SCENARIOS = {
1820
"dp3t",
1921
"ecdh",
2022
"eddsa",
23+
"es256",
2124
"ethereum",
25+
"foreach",
26+
"fsp",
2227
"given",
2328
"hash",
2429
"http",
2530
"keyring",
2631
"pack",
2732
"petition",
33+
"planetmint",
34+
"pvss",
2835
"qp",
2936
"random",
3037
"reflow",
3138
"schnorr",
39+
"sd_jwt",
3240
"secshare",
41+
"table",
3342
"then",
43+
"time",
3444
"verify",
3545
"w3c",
3646
"when"
3747
}
3848

3949
local when_stms = {}
4050
when_stms["default"] = only_statements(ZEN.when_steps)
51+
local if_stms = {}
52+
if_stms["default"] = only_statements(ZEN.if_steps)
53+
4154
-- Load one scenario at a time
4255
for _, scenario in ipairs(SCENARIOS) do
4356
ZEN.when_steps = {}
57+
ZEN.if_steps = {}
4458
load_scenario("zencode_" .. scenario)
4559
local statements = only_statements(ZEN.when_steps)
4660
if #statements > 0 then
4761
when_stms[scenario] = statements
4862
end
63+
local if_statements = only_statements(ZEN.if_steps)
64+
if #if_statements > 0 then
65+
if_stms[scenario] = if_statements
66+
end
4967
end
5068

5169
print(JSON.encode({
5270
["given"] = given_stms,
5371
["then"] = then_stms,
5472
["when"] = when_stms,
73+
["if"] = if_stms,
74+
["foreach"] = foreach_stms
5575
}))

src/zenexplorer/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ func createKeyValueList(z ZenStatements) []list.Item {
133133
})
134134
}
135135
}
136+
for k, v := range z.If {
137+
for i := 0; i < len(v); i++ {
138+
var scenario = ""
139+
if k != "default" {
140+
scenario = k
141+
}
142+
statements = append(statements, ZencodeStatement {
143+
scenario: scenario,
144+
statement: "If I " + v[i],
145+
})
146+
}
147+
}
148+
for i := 0; i < len(z.Foreach); i++ {
149+
statements = append(statements, ZencodeStatement {
150+
scenario: "",
151+
statement: "Foreach " + z.Foreach[i],
152+
})
153+
}
136154
for i := 0; i < len(z.Then); i++ {
137155
statements = append(statements, ZencodeStatement {
138156
scenario: "",

src/zenexplorer/zencodeStatements.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import (
2828
)
2929

3030
type ZenStatements struct {
31-
Given []string `json:"given"`
32-
When map[string][]string `json:"when"`
33-
Then []string `json:"then"`
34-
mtx *sync.Mutex
31+
Given []string `json:"given"`
32+
When map[string][]string `json:"when"`
33+
If map[string][]string `json:"if"`
34+
Foreach []string `json:"foreach"`
35+
Then []string `json:"then"`
36+
mtx *sync.Mutex
3537
}
3638

3739
//go:embed load_statements.lua
@@ -71,6 +73,9 @@ func (z *ZenStatements) count() int {
7173
for _, v := range z.When {
7274
count = count + len(v)
7375
}
74-
return count + len(z.Given) + len(z.Then)
76+
for _, v := range z.If {
77+
count = count + len(v)
78+
}
79+
return count + len(z.Given) + len(z.Then) + len(z.Foreach)
7580
}
7681

0 commit comments

Comments
 (0)