Comments (2)
I think a similar issue may affect the following tests ("valid/table/array-one" is the most minimal test affected by this):
- valid/inline-table/key-dotted
- valid/inline-table/nest
- valid/key/dotted
- valid/table/array-implicit
- valid/table/array-many
- valid/table/array-nest
- valid/table/array-one
- valid/table/array-table-array
from toml-test.
Reproducible with:
% cat x
#!/bin/sh
cat <<EOF
[[people]]
first_name = "Bruce"
last_name = "Springsteen"
EOF
% toml-test -encoder -run valid/table/array-one -v ./x
PASS valid/table/array-one
toml-test [./x]: using embedded tests: 1 passed, 0 failed, 155 skipped
% cat y
#!/bin/sh
cat <<EOF
people = [{first_name = 'Bruce', last_name = 'Springsteen'}]
EOF
% toml-test -encoder -run valid/table/array-one -v ./y
FAIL valid/table/array-one
Type for key 'people' differs:
Expected: [map[first_name:Bruce last_name:Springsteen]] ([]map[string]interface {})
Your encoder: [map[first_name:Bruce last_name:Springsteen]] ([]interface {})
input sent to parser-cmd:
{
"people": [
{
"first_name": {
"type": "string",
"value": "Bruce"
},
"last_name": {
"type": "string",
"value": "Springsteen"
}
}
]
}
output from parser-cmd (stdout):
people = [{first_name = 'Bruce', last_name = 'Springsteen'}]
want:
[[people]]
first_name = "Bruce"
last_name = "Springsteen"
toml-test [./y]: using embedded tests: 0 passed, 1 failed, 155 skipped
It's kind of an artefact how the TOML library that toml-test uses processes things; with a [[..]] type array we get:
[]map[string]any{
map[string]any{"first_name":"Bruce", "last_name":"Springsteen"},
}
But with an inline array we get:
[]any{
map[string]any{"first_name":"Bruce", "last_name":"Springsteen"},
}
This is the same value: a slice of map[string]any
, but the values are typed differently.
The below patch should fix it, but I want to have another think because I'm not sure if that will break anything (it's been a few years since I wrote all of this), and it might be better to fix this in the TOML library than here too, because I could imagine this causing issues for other users of the library too.
diff --git toml.go toml.go
index 346f0a9..d900940 100644
--- toml.go
+++ toml.go
@@ -31,9 +31,17 @@ func (r Test) CompareTOML(want, have interface{}) Test {
return r
}
+start:
switch w := want.(type) {
case map[string]interface{}:
return r.cmpTOMLMap(w, have)
+ case []map[string]interface{}:
+ ww := make([]interface{}, 0, len(w))
+ for _, v := range w {
+ ww = append(ww, v)
+ }
+ want = ww
+ goto start
case []interface{}:
return r.cmpTOMLArrays(w, have)
default:
@@ -126,7 +134,7 @@ func deepEqual(want, have interface{}) bool {
func isTomlValue(v interface{}) bool {
switch v.(type) {
- case map[string]interface{}, []interface{}:
+ case map[string]interface{}, []interface{}, []map[string]interface{}:
return false
}
return true
from toml-test.
Related Issues (20)
- Installation from conda-forge
- Bug in Test Case: valid/string/multiline-quotes HOT 2
- Add tests for unicode in bare keys
- Add test for tab character HOT 2
- Add tests for invalid encodings in all string types HOT 2
- Generate tests from the spec? HOT 8
- Add tests for "Permit more control characters in comments"
- Contradicting tests `invalid/no-seconds.toml` and `valid/no-seconds.toml` HOT 6
- Millisecond truncation is incorrect HOT 1
- Millisecond decoder tests pass with second precision output HOT 1
- Transfer to the toml-lang organisation? HOT 7
- Split `invalid/float/trailing-us-exp.toml` into two tests HOT 5
- Consider adding some performance tests HOT 1
- Invalid Unicode Escapes HOT 4
- [Valid Tests] Add Extra Spaces in Inline Tables HOT 1
- Clarify if - is permitted as a starting character in bare keys (toml 1.0.0) HOT 1
- Add tests for newlines within an array nested in an inline table
- Inconsistent test result of '+inf' HOT 4
- Add a test for oversized floating-point literals HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toml-test.