-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mockInputJson helper, rearrange for multiple tests
- Loading branch information
Showing
8 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const std = @import("std"); | ||
const Test = @import("xtp-test").Test; | ||
|
||
const CountVowel = struct { | ||
total: u32, | ||
count: u32, | ||
vowels: []const u8, | ||
}; | ||
|
||
export fn @"test"() i32 { | ||
const xtp_test = Test.init(std.heap.wasm_allocator); | ||
const input = xtp_test.mockInputJson(CountVowel, null) catch unreachable; | ||
const example = CountVowel{ .total = 2, .count = 1, .vowels = "aeiouAEIOU" }; | ||
xtp_test.assertEq("json works (consistent .count)", input.count, example.count); | ||
xtp_test.assertEq("json works (consistent .total)", input.total, example.total); | ||
xtp_test.assert("json works (consistent .vowels)", std.mem.eql(u8, input.vowels, example.vowels), "expected count and vowels fields to match after conversion"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bin = "https://raw.githubusercontent.com/extism/extism/main/wasm/code.wasm" | ||
|
||
[[test]] | ||
name = "json" | ||
build = "zig build json_test" | ||
with = "zig-out/bin/json-test.wasm" | ||
mock_input = { data = '{ "count": 1, "total": 2, "vowels": "aeiouAEIOU" }' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters