aboutsummaryrefslogtreecommitdiffstats
path: root/compare_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compare_test.go')
-rw-r--r--compare_test.go52
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)
+ }
+ }
+ })
+}