generate: Add decoder test function to testGenerateRun
This commit is contained in:
parent
0acf44886a
commit
9278bdcb43
@ -34,6 +34,7 @@ func testGenerateRun(test *testing.T, protocol *Protocol, imports string, testCa
|
||||
imports = `
|
||||
import "log"
|
||||
import "bytes"
|
||||
import "reflect"
|
||||
import "git.tebibyte.media/sashakoshka/hopp/tape"
|
||||
import tu "git.tebibyte.media/sashakoshka/hopp/internal/testutil"
|
||||
` + imports
|
||||
@ -56,6 +57,20 @@ func testGenerateRun(test *testing.T, protocol *Protocol, imports string, testCa
|
||||
log.Fatalln("not equal at", n)
|
||||
}
|
||||
}
|
||||
|
||||
func testDecode(data []byte, message Message, correct Message) {
|
||||
decoder := tape.NewDecoder(bytes.NewBuffer(data))
|
||||
n, err := message.Decode(decoder)
|
||||
if err != nil { log.Fatalf("at %d: %v\n", n, err) }
|
||||
log.Println("got: ", message)
|
||||
log.Println("correct:", correct)
|
||||
if n != len(data) {
|
||||
log.Fatalf("n incorrect: %d != %d\n", n, len(data))
|
||||
}
|
||||
if !reflect.DeepEqual(message, correct) {
|
||||
log.Fatalln("not equal")
|
||||
}
|
||||
}
|
||||
`
|
||||
fmt.Fprintf(
|
||||
mainFile, "package main\n%s\nfunc main() {\n%s\n%s\n%s\n}\n%s",
|
||||
|
Loading…
x
Reference in New Issue
Block a user