Skip to content

Commit ae92c9f

Browse files
feat: add statement to write string in path
1 parent a4621a1 commit ae92c9f

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/lua/zencode_when.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ When("write string '' in ''", function(content, dest)
116116
zentype = 'e' })
117117
end)
118118

119+
When("write string '' in path ''", function(content, dest_path)
120+
local maybe = mayhave(dest_path)
121+
local path = maybe and maybe:octet():string() or dest_path
122+
have(string.match(path, "^[^%.]+"))
123+
set_in_path(path, O.from_string(content))
124+
end)
125+
119126
-- ... and from a number
120127
When("write number '' in ''", function(content, dest)
121128
empty(dest)

test/zencode/cookbook_when.bats

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ Then print 'random dictionary'
18471847
EOF
18481848
save_output when_random_from_table.out.json
18491849
assert_output '{"random_array":[1,3],"random_dictionary":{"str3":"world","str4":"!"},"random_pick":"world"}'
1850-
}
1850+
}
18511851

18521852
@test "hash to point on a curve" {
18531853
cat <<EOF | save_asset when_hash_to_point.data.json
@@ -1869,4 +1869,30 @@ Then print 'hash to point ecp'
18691869
EOF
18701870
save_output when_hash_to_point.out.json
18711871
assert_output '{"hash_to_point_ecp":"AxAXy/Tldf0HPLWpeby/p9r5N5KWsRtyOOhupzDyD+zgpiyIM9ET0sBhcfXQyxD2Iw==","hash_to_point_ecp2":"EKDkY8NZoPBUrXbCKuGTfACzGhYjDN1ukN4WFeC1KruGArzmM2GjcNl540ccj1NwBmJripsCB8dKAZdHsPExCa2bd1HXbCvOIlaT0+yvl8Zb+MjzPAuvOs2y9rpKK/+GBGkYvsUr8aoHyijjv34XjG+6APolthn9+RA3p+Eluos5RjoIiPsYcgixpF+8rj4OEWDf3to6w2qomLHGf0lwhEzMZbPZ67zGYXUkJHSR2cGT/jdPufs7M9Havmq0iCiY"}'
1872-
}
1872+
}
1873+
1874+
@test "write string in path" {
1875+
cat <<EOF | save_asset write_string_in_path.data.json
1876+
{
1877+
"path": "a.b.c.1.1.d",
1878+
"a": {
1879+
"b": {
1880+
}
1881+
}
1882+
}
1883+
EOF
1884+
cat <<EOF | zexe write_string_in_path.zen write_string_in_path.data.json
1885+
Given I have a 'string' named 'path'
1886+
Given I have a 'string dictionary' named 'a'
1887+
1888+
When I write string 'hello' in path 'path'
1889+
When I write string 'hello' in path 'a.b.e'
1890+
When I write string 'hello' in path 'a.b.c.2'
1891+
When I write string 'hello' in path 'a.b.c.1.2'
1892+
1893+
Then print 'a'
1894+
1895+
EOF
1896+
save_output write_string_in_path.out.json
1897+
assert_output '{"a":{"b":{"c":[[{"d":"hello"},"hello"],"hello"],"e":"hello"}}}'
1898+
}

0 commit comments

Comments
 (0)