1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  | 
diff --git a/cfg_test.go b/cfg_test.go
index c6b055fc1a137ccc1ffec6e0bfff5861bb0354a7..afdd3752c7801710e7dcafe8c021de8bcce7de56 100644
--- a/cfg_test.go
+++ b/cfg_test.go
@@ -21,10 +21,26 @@ 	Gonk  bool
 }
 
 func TestEncoding(t *testing.T) {
-	assert := is.New(t)
+	final := TestData{
+		Foo: "bar",
+		Baz: true,
+		Bux: 10,
+		Qux: TestSubData{
+			Honk:  "bonk",
+			Chonk: 50,
+			Gonk:  false,
+		},
+	}
 
-	// Starting with dhall since it can't be encoded
-	dhall := `
+	// Each decode-only [Encoding]
+	tt := []struct {
+		Name     string
+		Input    string
+		Encoding Encoding
+	}{
+		{
+			Name: "dhall",
+			Input: `
 		{
 			Foo = "bar"
 			, Baz = True
@@ -35,15 +51,23 @@ 				, Chonk = 50
 				, Gonk = False
 			}
 		}
-	`
-	final := TestData{
-		Foo: "bar",
-		Baz: true,
-		Bux: 10,
-		Qux: TestSubData{
-			Honk:  "bonk",
-			Chonk: 50,
-			Gonk:  false,
+	`,
+			Encoding: DHALL,
+		}, {
+			Name: "jsonnet",
+			Input: `
+		{
+			Foo: "bar",
+			Baz: true,
+			Bux: 10,
+			Qux: {
+				Honk: "bonk",
+				Chonk: 50,
+				Gonk: false,
+			}
+		}
+	`,
+			Encoding: JSONNET,
 		},
 	}
 
@@ -53,15 +77,20 @@ 	if nixfig.Nix != "" {
 		encoders = append(encoders, NIX)
 	}
 
-	var data TestData
-	err := DHALL.Unmarshal([]byte(dhall), &data)
-	assert.NoErr(err) // Should be able to unmarshal dhall
+	for _, tc := range tt {
+		t.Run(tc.Name, func(t *testing.T) {
+			assert := is.New(t)
+			var data TestData
+			err := tc.Encoding.Unmarshal([]byte(tc.Input), &data)
+			assert.NoErr(err) // Should be able to unmarshal
 
-	for _, e := range encoders {
-		out, err := e.Marshal(data)
-		assert.NoErr(err) // Should be able to marshal
-		err = e.Unmarshal(out, &data)
-		assert.NoErr(err) // Should be able to unmarshal
+			for _, e := range encoders {
+				out, err := e.Marshal(data)
+				assert.NoErr(err) // Should be able to marshal
+				err = e.Unmarshal(out, &data)
+				assert.NoErr(err) // Should be able to unmarshal
+			}
+			assert.Equal(data, final) // Final structs should be equal
+		})
 	}
-	assert.Equal(data, final) // Final structs should be equal
 }
  |