Skip to content

Commit 847ee8a

Browse files
committed
Update toml-test
1 parent 4619257 commit 847ee8a

38 files changed

+130
-62
lines changed

error_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ At line 9, column 3-8:
4747
{"datetime/trailing-t.toml", `
4848
toml: error: Invalid TOML Datetime: "2006-01-30T".
4949
50-
At line 1, column 4-15:
50+
At line 2, column 4-15:
5151
52-
1 | d = 2006-01-30T
52+
1 | # Date cannot end with trailing T
53+
2 | d = 2006-01-30T
5354
^^^^^^^^^^^`},
5455
}
5556

internal/toml-test/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal/toml-test/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ An example implementation can be found in the BurnSushi/toml:
195195
- [Add tags](https://github.com/BurntSushi/toml/blob/master/internal/tag/add.go)
196196
- [Remove tags](https://github.com/BurntSushi/toml/blob/master/internal/tag/rm.go)
197197

198+
Implementation-defined behaviour
199+
--------------------------------
200+
This only tests behaviour that's should be true for every encoder implementing
201+
TOML; a few things are left up to implementations, and are not tested here.
202+
203+
- Millisecond precision (4 digits) is required for datetimes and times, and
204+
further precision is implementation-specific, and any greater precision than
205+
is supported must be truncated (not rounded).
206+
207+
This tests only millisecond precision, and not any further precision or the
208+
truncation of it.
209+
210+
198211
Assumptions of Truth
199212
--------------------
200213
The following are taken as ground truths by `toml-test`:

internal/toml-test/gen-multi.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/toml-test/json.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build go1.16
2-
// +build go1.16
3-
41
package tomltest
52

63
import (
@@ -9,13 +6,15 @@ import (
96
"time"
107
)
118

12-
// cmpJSON consumes the recursive structure of both want and have
13-
// simultaneously. If anything is unequal, the result has failed and comparison
14-
// stops.
9+
// CompareJSON compares the given arguments.
10+
//
11+
// The returned value is a copy of Test with Failure set to a (human-readable)
12+
// description of the first element that is unequal. If both arguments are
13+
// equal, Test is returned unchanged.
1514
//
1615
// reflect.DeepEqual could work here, but it won't tell us how the two
1716
// structures are different.
18-
func (r Test) cmpJSON(want, have interface{}) Test {
17+
func (r Test) CompareJSON(want, have interface{}) Test {
1918
switch w := want.(type) {
2019
case map[string]interface{}:
2120
return r.cmpJSONMaps(w, have)
@@ -67,7 +66,7 @@ func (r Test) cmpJSONMaps(want map[string]interface{}, have interface{}) Test {
6766

6867
// Okay, now make sure that each value is equivalent.
6968
for k := range want {
70-
if sub := r.kjoin(k).cmpJSON(want[k], haveMap[k]); sub.Failed() {
69+
if sub := r.kjoin(k).CompareJSON(want[k], haveMap[k]); sub.Failed() {
7170
return sub
7271
}
7372
}
@@ -93,7 +92,7 @@ func (r Test) cmpJSONArrays(want, have interface{}) Test {
9392
r.Key, len(wantSlice), len(haveSlice))
9493
}
9594
for i := 0; i < len(wantSlice); i++ {
96-
if sub := r.cmpJSON(wantSlice[i], haveSlice[i]); sub.Failed() {
95+
if sub := r.CompareJSON(wantSlice[i], haveSlice[i]); sub.Failed() {
9796
return sub
9897
}
9998
}

internal/toml-test/runner.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build go1.16
2-
// +build go1.16
3-
41
//go:generate ./gen-multi.py
52

63
package tomltest
@@ -310,7 +307,7 @@ func (t Test) runValid(p Parser, fsys fs.FS) Test {
310307
//return t.fail("decode TOML from encoder %q:\n %s", cmd, err)
311308
return t.fail("decode TOML from encoder:\n %s", err)
312309
}
313-
return t.cmpTOML(want, have)
310+
return t.CompareTOML(want, have)
314311
}
315312

316313
// Compare for decoder test
@@ -324,7 +321,7 @@ func (t Test) runValid(p Parser, fsys fs.FS) Test {
324321
return t.fail("decode JSON output from parser:\n %s", err)
325322
}
326323

327-
return t.cmpJSON(want, have)
324+
return t.CompareJSON(want, have)
328325
}
329326

330327
// ReadInput reads the file sent to the encoder.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment-cr = "Carriage return in comment" #
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# No months with 50 days.
12
d = 2006-01-50T00:00:00Z
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# Day "5" instead of "05"; the leading zero is required.
12
with-milli = 1987-07-5T17:45:00.12Z
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# Month "7" instead of "07"; the leading zero is required.
12
no-leads = 1987-7-05T17:45:00Z
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# No seconds in time.
12
no-secs = 1987-07-05T17:45Z
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# No "t" or "T" between the date and time.
12
no-t = 1987-07-0517:45:00Z
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Leading 0 is always required.
2+
d = 01:32:0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Leading 0 is always required.
2+
d = 1:32:00
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# Date cannot end with trailing T
12
d = 2006-01-30T
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# trailing underscore in integer part is not allowed
2+
trailing-us-exp = 1_e2
3+
# trailing underscore in float part is not allowed
4+
trailing-us-exp2 = 1.2_e2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Duplicate keys within an inline table are invalid
2+
a={b=1, b=2}

internal/toml-test/tests/invalid/integer/integer.multi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
leading-zero-1 = 01
22
leading-zero-2 = 00
3+
leading-zero-3 = 0_0
34
leading-zero-sign-1 = -01
45
leading-zero-sign-2 = +01
6+
leading-zero-sign-3 = +0_1
57

68
double-sign-plus = ++99
79
double-sign-nex = --99
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
leading-zero-3 = 0_0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
leading-zero-sign-3 = +0_1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invalid-escape = "This string has a bad \ escape character."
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
k = """t\a"""
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# \<Space> is not a valid escape.
2+
k = """t\ t"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# \<Space> is not a valid escape.
2+
k = """t\ """
3+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# First a.b.c defines a table: a.b.c = {z=9}
2+
#
3+
# Then we define a.b.c.t = "str" to add a str to the above table, making it:
4+
#
5+
# a.b.c = {z=9, t="..."}
6+
#
7+
# While this makes sense, logically, it was decided this is not valid TOML as
8+
# it's too confusing/convoluted.
9+
#
10+
# See: https://github.com/toml-lang/toml/issues/846
11+
# https://github.com/toml-lang/toml/pull/859
12+
13+
[a.b.c]
14+
z = 9
15+
16+
[a]
17+
b.c.t = "Using dotted keys to add to [a.b.c] after explicitly defining it above is not allowed"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is the same issue as in injection-1.toml, except that nests one level
2+
# deeper. See that file for a more complete description.
3+
4+
[a.b.c.d]
5+
z = 9
6+
7+
[a]
8+
b.c.d.k.t = "Using dotted keys to add to [a.b.c.d] after explicitly defining it above is not allowed"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"utc1": {
33
"type": "datetime",
4-
"value": "1987-07-05T17:45:56.123456Z"
4+
"value": "1987-07-05T17:45:56.1234Z"
55
},
66
"utc2": {
77
"type": "datetime",
8-
"value": "1987-07-05T17:45:56.600000Z"
8+
"value": "1987-07-05T17:45:56.6000Z"
99
},
1010
"wita1": {
1111
"type": "datetime",
12-
"value": "1987-07-05T17:45:56.123456+08:00"
12+
"value": "1987-07-05T17:45:56.1234+08:00"
1313
},
1414
"wita2": {
1515
"type": "datetime",
16-
"value": "1987-07-05T17:45:56.600000+08:00"
16+
"value": "1987-07-05T17:45:56.6000+08:00"
1717
}
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
utc1 = 1987-07-05T17:45:56.123456Z
1+
utc1 = 1987-07-05T17:45:56.1234Z
22
utc2 = 1987-07-05T17:45:56.6Z
3-
wita1 = 1987-07-05T17:45:56.123456+08:00
3+
wita1 = 1987-07-05T17:45:56.1234+08:00
44
wita2 = 1987-07-05T17:45:56.6+08:00

internal/toml-test/tests/valid/float/zero.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"f1": {
2+
"zero": {
33
"type": "float",
44
"value": "0"
55
},
6-
"f2": {
6+
"signed-pos": {
77
"type": "float",
88
"value": "0"
99
},
10-
"f3": {
10+
"signed-neg": {
1111
"type": "float",
1212
"value": "0"
1313
},
14-
"f4": {
14+
"exponent": {
1515
"type": "float",
1616
"value": "0"
1717
},
18-
"f5": {
18+
"exponent-two-0": {
1919
"type": "float",
2020
"value": "0"
2121
},
22-
"f6": {
22+
"exponent-signed-pos": {
2323
"type": "float",
2424
"value": "0"
2525
},
26-
"f7": {
26+
"exponent-signed-neg": {
2727
"type": "float",
2828
"value": "0"
2929
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
f1 = 0.0
2-
f2 = +0.0
3-
f3 = -0.0
4-
f4 = 0e0
5-
f5 = 0e00
6-
f6 = +0e0
7-
f7 = -0e0
1+
zero = 0.0
2+
signed-pos = +0.0
3+
signed-neg = -0.0
4+
exponent = 0e0
5+
exponent-two-0 = 0e00
6+
exponent-signed-pos = +0e0
7+
exponent-signed-neg = -0e0

internal/toml-test/tests/valid/string/multiline-toml renamed to internal/toml-test/tests/valid/string/multiline.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# NOTE: this file includes some literal tab characters.
22

33
multiline_empty_one = """"""
4+
5+
# A newline immediately following the opening delimiter will be trimmed.
46
multiline_empty_two = """
57
"""
8+
9+
# \ at the end of line trims newlines as well; note that last \ is followed by
10+
# two spaces, which are ignored.
611
multiline_empty_three = """\
712
"""
813
multiline_empty_four = """\
@@ -33,6 +38,7 @@ whitespace-after-bs = """\
3338
no-space = """a\
3439
b"""
3540

41+
# Has tab character.
3642
keep-ws-before = """a \
3743
b"""
3844

internal/toml-test/tests/valid/string/raw-multiline.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# Single ' should be allowed.
12
oneline = '''This string has a ' quote character.'''
3+
4+
# A newline immediately following the opening delimiter will be trimmed.
25
firstnl = '''
36
This string has a ' quote character.'''
7+
8+
# All other whitespace and newline characters remain intact.
49
multiline = '''
510
This string
611
has ' a quote character

internal/toml-test/toml.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
//go:build go1.16
2-
// +build go1.16
3-
41
package tomltest
52

63
import (
74
"math"
85
"reflect"
96
)
107

11-
// cmpTOML consumes the recursive structure of both want and have
12-
// simultaneously. If anything is unequal the result has failed and comparison
13-
// stops.
8+
// CompareTOML compares the given arguments.
9+
//
10+
// The returned value is a copy of Test with Failure set to a (human-readable)
11+
// description of the first element that is unequal. If both arguments are equal
12+
// Test is returned unchanged.
1413
//
15-
// reflect.DeepEqual could work here, but it won't tell us how the two
14+
// Reflect.DeepEqual could work here, but it won't tell us how the two
1615
// structures are different.
17-
func (r Test) cmpTOML(want, have interface{}) Test {
16+
func (r Test) CompareTOML(want, have interface{}) Test {
1817
if isTomlValue(want) {
1918
if !isTomlValue(have) {
2019
return r.fail("Type for key '%s' differs:\n"+
@@ -64,7 +63,7 @@ func (r Test) cmpTOMLMap(want map[string]interface{}, have interface{}) Test {
6463

6564
// Okay, now make sure that each value is equivalent.
6665
for k := range want {
67-
if sub := r.kjoin(k).cmpTOML(want[k], haveMap[k]); sub.Failed() {
66+
if sub := r.kjoin(k).CompareTOML(want[k], haveMap[k]); sub.Failed() {
6867
return sub
6968
}
7069
}
@@ -96,7 +95,7 @@ func (r Test) cmpTOMLArrays(want []interface{}, have interface{}) Test {
9695
r.Key, want, haveSlice, len(want), len(haveSlice))
9796
}
9897
for i := 0; i < len(want); i++ {
99-
if sub := r.cmpTOML(want[i], haveSlice[i]); sub.Failed() {
98+
if sub := r.CompareTOML(want[i], haveSlice[i]); sub.Failed() {
10099
return sub
101100
}
102101
}

toml_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,16 @@ func TestToml(t *testing.T) {
281281
SkipTests: []string{
282282
// This one is annoying to fix, and such an obscure edge case
283283
// it's okay to leave it like this for now.
284+
// https://github.com/BurntSushi/toml/issues/329
284285
"invalid/encoding/bad-utf8-at-end",
286+
287+
// TODO: fix this.
288+
"invalid/table/append-with-dotted*",
289+
"invalid/datetime/time-no-leads", // https://github.com/BurntSushi/toml/issues/320
290+
"invalid/control/bare-null", // https://github.com/BurntSushi/toml/issues/317
291+
"invalid/control/comment-cr", // https://github.com/BurntSushi/toml/issues/321
292+
"invalid/integer/leading-zero-3", // https://github.com/BurntSushi/toml/issues/326
293+
"invalid/string/multiline-bad-escape-3", // https://github.com/BurntSushi/toml/issues/322
285294
},
286295
}
287296

0 commit comments

Comments
 (0)