diff options
author | 2021-12-23 13:15:26 +0100 | |
---|---|---|
committer | 2021-12-23 13:55:38 +0100 | |
commit | 57311daf54ab12f7a1af5a844ad60fa6af0e7283 (patch) | |
tree | dcdd424a68485b67df5f117d2a243748eed8e7f4 /compare_test.go | |
download | translate-highlight-from-c-to-go-master.tar.xz translate-highlight-from-c-to-go-master.zip |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'compare_test.go')
-rw-r--r-- | compare_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/compare_test.go b/compare_test.go new file mode 100644 index 0000000..3922e2d --- /dev/null +++ b/compare_test.go @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved. + */ + +package syntax + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func FuzzComparison(f *testing.F) { + corpus, err := filepath.Glob("./corpus/*.conf") + if err != nil { + f.Fatal(err) + } + for _, c := range corpus { + b, err := os.ReadFile(c) + if err != nil { + f.Fatal(err) + } + f.Logf("Adding %+q to corpus", c) + f.Add(string(b)) + } + corpus, err = filepath.Glob("/etc/wireguard/*.conf") + if err == nil { + for _, c := range corpus { + b, err := os.ReadFile(c) + if err == nil { + f.Logf("Adding %+q to corpus", c) + f.Add(string(b)) + } + } + } + + f.Fuzz(func(t *testing.T, in string) { + in, _, _ = strings.Cut(in, "\x00") + goOutput := highlightConfig(in) + cOutput := highlightConfigC(in) + if len(goOutput) != len(cOutput) { + t.Fatalf("output length is not the same: %+v vs %+v: %+q", goOutput, cOutput, in) + } + for i := range goOutput { + if goOutput[i] != cOutput[i] { + t.Fatalf("struct return mismatch: %+v vs %+v: %+q", goOutput[i], cOutput[i], in) + } + } + }) +} |