Files
templateless.odin/testing.odin
2025-06-19 22:01:03 -06:00

63 lines
1.1 KiB
Odin

#+feature dynamic-literals
#+private
package mustache
import "core:os"
import "core:log"
import "core:testing"
import "core:encoding/json"
data_struct :: union {
map[string]data_struct,
[]data_struct,
string,
bool,
}
test_struct :: struct {
overview: string,
tests: []struct{
name, desc, template, expected: string,
data: data_struct
}
}
@(test)
spec_test :: proc(t: ^testing.T){
test_files := []string {
"./spec/specs/sections.json",
"./spec/specs/interpolation.json",
"./spec/specs/inverted.json",
"./spec/specs/comments.json",
/*
"./spec/specs/partials.json",
"./spec/specs/delimiters.json",
*/
}
for i in test_files {
data, err:=os.read_entire_file_from_filename_or_err(i)
defer delete(data)
if err != nil {
testing.expectf(t, false, "%v", err)
}
test: test_struct
json.unmarshal(data, &test, allocator=context.temp_allocator)
failed := 0
for j in test.tests {
ret := mustache(j.template, j.data)
defer delete(ret)
if ret!=j.expected {
log.warnf( "[%s:%s]: %s", i, j.name, j.desc )
failed += 1
}
}
log.infof( "[%s] Passed: (%d/%d)", i, len(test.tests)-failed, len(test.tests) )
}
}