Repository: BurntSushi/toml
Pull request #432 (2024-11-14 11:26:12)

Fix typos in comments, tests, error message
The PR corrects grammar mistakes.


Patch:
diff --git a/error.go b/error.go
index 1dd5232..b7077d3 100644
--- a/error.go
+++ b/error.go
@@ -69,7 +69,7 @@ type Position struct {
 	Line  int // Line number, starting at 1.
 	Col   int // Error column, starting at 1.
 	Start int // Start of error, as byte offset starting at 0.
-	Len   int // Lenght of the error in bytes.
+	Len   int // Length of the error in bytes.
 }
 
 func (p Position) withCol(tomlFile string) Position {
diff --git a/lex.go b/lex.go
index cd9de46..7935022 100644
--- a/lex.go
+++ b/lex.go
@@ -1117,7 +1117,7 @@ func lexBaseNumberOrDate(lx *lexer) stateFn {
 	case 'x':
 		r = lx.peek()
 		if !isHex(r) {
-			lx.errorf("not a hexidecimal number: '%s%c'", lx.current(), r)
+			lx.errorf("not a hexadecimal number: '%s%c'", lx.current(), r)
 		}
 		return lexHexInteger
 	}
diff --git a/meta.go b/meta.go
index e614537..0d33702 100644
--- a/meta.go
+++ b/meta.go
@@ -135,9 +135,6 @@ func (k Key) maybeQuoted(i int) string {
 
 // Like append(), but only increase the cap by 1.
 func (k Key) add(piece string) Key {
-	if cap(k) > len(k) {
-		return append(k, piece)
-	}
 	newKey := make(Key, len(k)+1)
 	copy(newKey, k)
 	newKey[len(k)] = piece
diff --git a/parse.go b/parse.go
index 3f2c090..349a9fa 100644
--- a/parse.go
+++ b/parse.go
@@ -529,7 +529,7 @@ func numUnderscoresOK(s string) bool {
 			}
 		}
 
-		// isHexis a superset of all the permissable characters surrounding an
+		// isHex is a superset of all the permissible characters surrounding an
 		// underscore.
 		accept = isHex(r)
 	}


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 4bff0cc..10c363f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -5,7 +5,7 @@
     "test": {
       "strategy": {
         "matrix": {
-          "go-version": ["1.18.x", "1.22.x"],
+          "go-version": ["1.18.x", "1.24.x"],
           "os":         ["ubuntu-latest", "macos-latest", "windows-latest"]
         }
       },
diff --git a/encode_test.go b/encode_test.go
index a5c3a7e..d871aee 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -149,7 +149,7 @@ func TestEncodeOmitEmptyStruct(t *testing.T) {
 }
 
 func TestEncodeOmitEmpty(t *testing.T) {
-	type compareable struct {
+	type comparable struct {
 		Bool bool `toml:"bool,omitempty"`
 	}
 	type uncomparable struct {
@@ -166,8 +166,8 @@ func TestEncodeOmitEmpty(t *testing.T) {
 		Slice               []int              `toml:"slice,omitempty"`
 		Map                 map[string]string  `toml:"map,omitempty"`
 		Time                time.Time          `toml:"time,omitempty"`
-		Compareable1        compareable        `toml:"compareable1,omitempty"`
-		Compareable2        compareable        `toml:"compareable2,omitempty"`
+		Comparable1         comparable         `toml:"comparable1,omitempty"`
+		Comparable2         comparable         `toml:"comparable2,omitempty"`
 		Uncomparable1       uncomparable       `toml:"uncomparable1,omitempty"`
 		Uncomparable2       uncomparable       `toml:"uncomparable2,omitempty"`
 		NestedUncomparable1 nestedUncomparable `toml:"nesteduncomparable1,omitempty"`
@@ -182,7 +182,7 @@ func TestEncodeOmitEmpty(t *testing.T) {
 		Slice:               []int{2, 3, 4},
 		Map:                 map[string]string{"foo": "bar"},
 		Time:                time.Date(1985, 6, 18, 15, 16, 17, 0, time.UTC),
-		Compareable2:        compareable{true},
+		Comparable2:         comparable{true},
 		Uncomparable2:       uncomparable{[]string{"XXX"}},
 		NestedUncomparable1: nestedUncomparable{uncomparable{[]string{"XXX"}}, false},
 		NestedUncomparable2: nestedUncomparable{uncomparable{}, true},
@@ -195,7 +195,7 @@ time = 1985-06-18T15:16:17Z
 [map]
   foo = "bar"
 
-[compareable2]
+[comparable2]
   bool = true
 
 [uncomparable2]
diff --git a/error_test.go b/error_test.go
index d14283e..bb8075f 100644
--- a/error_test.go
+++ b/error_test.go
@@ -337,7 +337,7 @@ func (n *Enum2) UnmarshalTOML(text any) error {
 	return nil
 }
 
-func TestMarhsalError(t *testing.T) {
+func TestMarshalError(t *testing.T) {
 	var c struct {
 		K1 string `toml:"k1"`
 		K2 Enum2  `toml:"k2"`
diff --git a/example_test.go b/example_test.go
index da992c1..470959a 100644
--- a/example_test.go
+++ b/example_test.go
@@ -225,7 +225,7 @@ func Example_strictDecoding() {
 type order struct {
 	// NOTE `order.parts` is a private slice of type `part` which is an
 	// interface and may only be loaded from toml using the UnmarshalTOML()
-	// method of the Umarshaler interface.
+	// method of the Unmarshaler interface.
 	parts parts
 }
 
diff --git a/internal/toml-test/runner.go b/internal/toml-test/runner.go
index 666e8ed..69b0e92 100644
--- a/internal/toml-test/runner.go
+++ b/internal/toml-test/runner.go
@@ -101,7 +101,7 @@ type Test struct {
 
 	Skipped          bool          // Skipped this test?
 	Failure          string        // Failure message.
-	Key              string        // TOML key the failure occured on; may be blank.
+	Key              string        // TOML key the failure occurred on; may be blank.
 	Encoder          bool          // Encoder test?
 	Input            string        // The test case that we sent to the external program.
 	Output           string        // Output from the external program.
diff --git a/internal/toml-test/tests/valid/string/escapes.toml b/internal/toml-test/tests/valid/string/escapes.toml
index 5146065..1d949e1 100644
--- a/internal/toml-test/tests/valid/string/escapes.toml
+++ b/internal/toml-test/tests/valid/string/escapes.toml
@@ -8,7 +8,7 @@ backslash     = "|\\."
 delete        = "|\u007F."
 unitseparator = "|\u001F."
 
-# \u is escaped, so should NOT be interperted as a \u escape.
+# \u is escaped, so should NOT be interpreted as a \u escape.
 notunicode1   = "|\\u."
 notunicode2   = "|\u005Cu."
 notunicode3   = "|\\u0075."
diff --git a/internal/toml-test/tests/valid/table/keyword-with-values.json b/internal/toml-test/tests/valid/table/keyword-with-values.json
new file mode 100644
index 0000000..4642aac
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/keyword-with-values.json
@@ -0,0 +1,14 @@
+{
+    "false": {
+        "k": {"type": "integer", "value": "2"}
+    },
+    "inf": {
+        "k": {"type": "integer", "value": "3"}
+    },
+    "nan": {
+        "k": {"type": "integer", "value": "4"}
+    },
+    "true": {
+        "k": {"type": "integer", "value": "1"}
+    }
+}
diff --git a/internal/toml-test/tests/valid/table/keyword-with-values.toml b/internal/toml-test/tests/valid/table/keyword-with-values.toml
new file mode 100644
index 0000000..d154d60
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/keyword-with-values.toml
@@ -0,0 +1,11 @@
+[true]
+k = 1
+
+[false]
+k = 2
+
+[inf]
+k = 3
+
+[nan]
+k = 4
diff --git a/internal/toml-test/tests/valid/table/names-with-values.json b/internal/toml-test/tests/valid/table/names-with-values.json
new file mode 100644
index 0000000..7892371
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/names-with-values.json
@@ -0,0 +1,46 @@
+{
+    "a": {
+        " x ": {
+            "key": {"type": "integer", "value": "4"}
+        },
+        "b": {
+            "c": {
+                "key": {"type": "integer", "value": "1"}
+            }
+        },
+        "b.c": {
+            "key": {"type": "integer", "value": "2"}
+        },
+        "d.e": {
+            "key": {"type": "integer", "value": "3"}
+        }
+    },
+    "d": {
+        "e": {
+            "f": {
+                "key": {"type": "integer", "value": "5"}
+            }
+        }
+    },
+    "g": {
+        "h": {
+            "i": {
+                "key": {"type": "integer", "value": "6"}
+            }
+        }
+    },
+    "j": {
+        "ʞ": {
+            "l": {
+                "key": {"type": "integer", "value": "7"}
+            }
+        }
+    },
+    "x": {
+        "1": {
+            "2": {
+                "key": {"type": "integer", "value": "8"}
+            }
+        }
+    }
+}
diff --git a/internal/toml-test/tests/valid/table/names-with-values.toml b/internal/toml-test/tests/valid/table/names-with-values.toml
new file mode 100644
index 0000000..c297d16
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/names-with-values.toml
@@ -0,0 +1,23 @@
+[a.b.c]
+key = 1
+
+[a."b.c"]
+key = 2
+
+[a.'d.e']
+key = 3
+
+[a.' x ']
+key = 4
+
+[ d.e.f ]
+key = 5
+
+[ g . h . i ]
+key = 6
+
+[ j . "ʞ" . 'l' ]
+key = 7
+
+[x.1.2]
+key = 8
diff --git a/internal/toml-test/tests/valid/table/without-super-with-values.json b/internal/toml-test/tests/valid/table/without-super-with-values.json
new file mode 100644
index 0000000..e295139
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/without-super-with-values.json
@@ -0,0 +1,14 @@
+{
+    "x": {
+        "c": {"type": "integer", "value": "3"},
+        "d": {"type": "integer", "value": "4"},
+        "y": {
+            "z": {
+                "w": {
+                    "a": {"type": "integer", "value": "1"},
+                    "b": {"type": "integer", "value": "2"}
+                }
+            }
+        }
+    }
+}
diff --git a/internal/toml-test/tests/valid/table/without-super-with-values.toml b/internal/toml-test/tests/valid/table/without-super-with-values.toml
new file mode 100644
index 0000000..0bb5196
--- /dev/null
+++ b/internal/toml-test/tests/valid/table/without-super-with-values.toml
@@ -0,0 +1,9 @@
+# [x] you
+# [x.y] don't
+# [x.y.z] need these
+[x.y.z.w] # for this to work
+a = 1
+b = 2
+[x] # defining a super-table afterwards is ok
+c = 3
+d = 4
diff --git a/toml_test.go b/toml_test.go
index 915a51f..029fcdc 100644
--- a/toml_test.go
+++ b/toml_test.go
@@ -243,6 +243,14 @@ var metaTests = map[string]string{
 		x.y.z.w:  Hash
 		x:        Hash
 	`,
+	"table/without-super-with-values": `
+		x.y.z.w: Hash
+		x.y.z.w.a: Integer
+		x.y.z.w.b: Integer
+		x: Hash
+		x.c: Integer
+		x.d: Integer
+	`,
 }
 
 // TOML 1.0
@@ -275,7 +283,7 @@ func runTomlTest(t *testing.T, includeNext bool, wantFail ...string) {
 	}
 
 	// TODO: bit of a hack to make sure not all test run; without this "-run=.."
-	// will still run alll tests, but just report the errors for the -run value.
+	// will still run all tests, but just report the errors for the -run value.
 	// This is annoying in cases where you have some debug printf.
 	//
 	// Need to update toml-test a bit to make this easier, but this good enough