1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-21 19:20:05 -05:00

Add tests for auto-generated constants

This commit is contained in:
Aaron Lindsay 2017-04-07 22:34:54 -04:00
parent 932af2439b
commit ac5a0dce1d
2 changed files with 1520 additions and 0 deletions

1456
constants_test.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -154,3 +154,67 @@ with open("constants.go", 'w') as f:
lastValue=lastValue,
constNames=constNames,
upperValueString=upperValueString))
test_header = """package ofxgo_test
/*
* Do not edit this file by hand. It is auto-generated by calling `go generate`.
* To make changes, edit generate_constants.py, re-run `go generate`, and check
* in the result.
*/
import (
"github.com/aclindsa/go/src/encoding/xml"
"github.com/aclindsa/ofxgo"
"testing"
)
"""
test_template = """
func Test{enum}(t *testing.T) {{
e, err := ofxgo.New{enum}("{firstValueUpper}")
if err != nil {{
t.Fatalf("Unexpected error creating new {enum} from string \\\"{firstValueUpper}\\\"\\n")
}}
if !e.Valid() {{
t.Fatalf("{enum} unexpectedly invalid\\n")
}}
err = e.FromString("{lastValueUpper}")
if err != nil {{
t.Fatalf("Unexpected error on {enum}.FromString(\\\"{lastValueUpper}\\\")\\n")
}}
if e.String() != "{lastValueUpper}" {{
t.Fatalf("{enum}.String() expected to be \\\"{lastValueUpper}\\\"\\n")
}}
marshalHelper(t, "{lastValueUpper}", &e)
overwritten, err := ofxgo.New{enum}("THISWILLNEVERBEAVALIDENUMSTRING")
if err == nil {{
t.Fatalf("Expected error creating new {enum} from string \\\"THISWILLNEVERBEAVALIDENUMSTRING\\\"\\n")
}}
if overwritten.Valid() {{
t.Fatalf("{enum} created with string \\\"THISWILLNEVERBEAVALIDENUMSTRING\\\" should not be valid\\n")
}}
b, err := xml.Marshal(&overwritten)
if err != nil {{
t.Fatalf("Unexpected error on xml.Marshal({enum}): %s\\n", err)
}}
if string(b) != "" {{
t.Fatalf("Expected empty string, got '%s'\\n", string(b))
}}
unmarshalHelper(t, "{lastValueUpper}", &e, &overwritten)
}}
"""
with open("constants_test.go", 'w') as f:
f.write(test_header)
for enum in enums:
firstValueUpper = enums[enum][0].upper()
lastValueUpper = enums[enum][-1].upper()
f.write(test_template.format(enum=enum,
firstValueUpper=firstValueUpper,
lastValueUpper=lastValueUpper))