Skip to content

Commit

Permalink
Merge pull request #9 from dyne/fix/up_zenexplorer
Browse files Browse the repository at this point in the history
fix(zenexplorer): include new scenarios, if and foreach statements
  • Loading branch information
jaromil authored May 6, 2024
2 parents fd8b27e + 1f976f6 commit 388de61
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
restroom-test
zendebug
zenexplorer
breakroom
breakroom-read
2 changes: 1 addition & 1 deletion src/zenexplorer/default_statements.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/zenexplorer/load_statements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ local function only_statements(steps, defaults)
end
local given_stms = only_statements(ZEN.given_steps)
local then_stms = only_statements(ZEN.then_steps)
local foreach_stms = only_statements(ZEN.foreach_steps)

local SCENARIOS = {
"array",
"bbs",
"bitcoin",
"credential",
"data",
Expand All @@ -18,38 +20,56 @@ local SCENARIOS = {
"dp3t",
"ecdh",
"eddsa",
"es256",
"ethereum",
"foreach",
"fsp",
"given",
"hash",
"http",
"keyring",
"pack",
"petition",
"planetmint",
"pvss",
"qp",
"random",
"reflow",
"schnorr",
"sd_jwt",
"secshare",
"table",
"then",
"time",
"verify",
"w3c",
"when"
}

local when_stms = {}
when_stms["default"] = only_statements(ZEN.when_steps)
local if_stms = {}
if_stms["default"] = only_statements(ZEN.if_steps)

-- Load one scenario at a time
for _, scenario in ipairs(SCENARIOS) do
ZEN.when_steps = {}
ZEN.if_steps = {}
load_scenario("zencode_" .. scenario)
local statements = only_statements(ZEN.when_steps)
if #statements > 0 then
when_stms[scenario] = statements
end
local if_statements = only_statements(ZEN.if_steps)
if #if_statements > 0 then
if_stms[scenario] = if_statements
end
end

print(JSON.encode({
["given"] = given_stms,
["then"] = then_stms,
["when"] = when_stms,
["if"] = if_stms,
["foreach"] = foreach_stms
}))
18 changes: 18 additions & 0 deletions src/zenexplorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ func createKeyValueList(z ZenStatements) []list.Item {
})
}
}
for k, v := range z.If {
for i := 0; i < len(v); i++ {
var scenario = ""
if k != "default" {
scenario = k
}
statements = append(statements, ZencodeStatement {
scenario: scenario,
statement: "If I " + v[i],
})
}
}
for i := 0; i < len(z.Foreach); i++ {
statements = append(statements, ZencodeStatement {
scenario: "",
statement: "Foreach " + z.Foreach[i],
})
}
for i := 0; i < len(z.Then); i++ {
statements = append(statements, ZencodeStatement {
scenario: "",
Expand Down
15 changes: 10 additions & 5 deletions src/zenexplorer/zencodeStatements.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
)

type ZenStatements struct {
Given []string `json:"given"`
When map[string][]string `json:"when"`
Then []string `json:"then"`
mtx *sync.Mutex
Given []string `json:"given"`
When map[string][]string `json:"when"`
If map[string][]string `json:"if"`
Foreach []string `json:"foreach"`
Then []string `json:"then"`
mtx *sync.Mutex
}

//go:embed load_statements.lua
Expand Down Expand Up @@ -71,6 +73,9 @@ func (z *ZenStatements) count() int {
for _, v := range z.When {
count = count + len(v)
}
return count + len(z.Given) + len(z.Then)
for _, v := range z.If {
count = count + len(v)
}
return count + len(z.Given) + len(z.Then) + len(z.Foreach)
}

0 comments on commit 388de61

Please sign in to comment.