Giter Club home page Giter Club logo

Comments (2)

trevorld avatar trevorld commented on August 19, 2024

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.

arp242 avatar arp242 commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.