Add testing for spec
This commit is contained in:
144
testing.odin
144
testing.odin
@@ -2,106 +2,56 @@
|
|||||||
#+private
|
#+private
|
||||||
package mustache
|
package mustache
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
import "core:log"
|
||||||
import "core:testing"
|
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)
|
@(test)
|
||||||
test1 :: proc(t: ^testing.T){
|
spec_test :: proc(t: ^testing.T){
|
||||||
fmt := "{"
|
test_files := []string {
|
||||||
tmp := mustache(fmt,{})
|
"./spec/specs/delimiters.json",
|
||||||
defer delete(tmp)
|
"./spec/specs/sections.json",
|
||||||
testing.expect(t, tmp==fmt, tmp)
|
"./spec/specs/interpolation.json",
|
||||||
}
|
//"./spec/specs/inverted.json",
|
||||||
@(test)
|
//"./spec/specs/partials.json",
|
||||||
test2 :: proc(t: ^testing.T){
|
//"./spec/specs/comments.json",
|
||||||
fmt := "}"
|
}
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp==fmt, tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test3 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp==fmt, tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test4 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp==fmt, tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test5 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{}}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp=="", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test6 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{foo}}"
|
|
||||||
|
|
||||||
dict : struct { foo: string } = {"var"}
|
for i in test_files {
|
||||||
|
data, err:=os.read_entire_file_from_filename_or_err(i)
|
||||||
|
defer delete(data)
|
||||||
|
|
||||||
tmp := mustache(fmt, dict)
|
if err != nil {
|
||||||
defer delete(tmp)
|
testing.expectf(t, false, "%v", err)
|
||||||
testing.expect(t, tmp=="var", tmp)
|
}
|
||||||
}
|
|
||||||
@(test)
|
test: test_struct
|
||||||
test7 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{{}}"
|
json.unmarshal(data, &test, allocator=context.temp_allocator)
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
for j in test.tests {
|
||||||
testing.expect(t, tmp=="", tmp)
|
ret := mustache(j.template, j.data)
|
||||||
}
|
defer delete(ret)
|
||||||
@(test)
|
|
||||||
test8 :: proc(t: ^testing.T){
|
if ret!=j.expected {
|
||||||
fmt := "{{}}}"
|
log.warnf( "[%s:%s]: %s", i, j.name, j.desc )
|
||||||
tmp := mustache(fmt,{})
|
}
|
||||||
defer delete(tmp)
|
}
|
||||||
testing.expect(t, tmp=="}", tmp)
|
}
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test9 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{{}}}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp=="}", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test10 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{} }}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp=="", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test11 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{{} }}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp=="", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test12 :: proc(t: ^testing.T){
|
|
||||||
fmt := " {{{} }}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp==" ", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test13 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{{} }} "
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp==" ", tmp)
|
|
||||||
}
|
|
||||||
@(test)
|
|
||||||
test14 :: proc(t: ^testing.T){
|
|
||||||
fmt := "{{{}}}"
|
|
||||||
tmp := mustache(fmt,{})
|
|
||||||
defer delete(tmp)
|
|
||||||
testing.expect(t, tmp=="}", tmp)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user