Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8df3b65280 | |||
| 6c995ec13e | |||
| 9f1bb6c97d | |||
| d3b9283095 | |||
| 013ffc24b8 | |||
| 2762e24a9c | |||
| 5b6828661c |
@@ -19,7 +19,7 @@ jobs:
|
|||||||
dry-run: false
|
dry-run: false
|
||||||
language: go
|
language: go
|
||||||
- name: Upload Crash
|
- name: Upload Crash
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v6
|
||||||
if: failure() && steps.build.outcome == 'success'
|
if: failure() && steps.build.outcome == 'success'
|
||||||
with:
|
with:
|
||||||
name: artifacts
|
name: artifacts
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
./test-go-versions.sh --output ./test-results $VERSIONS
|
./test-go-versions.sh --output ./test-results $VERSIONS
|
||||||
|
|
||||||
- name: Upload test results
|
- name: Upload test results
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v6
|
||||||
with:
|
with:
|
||||||
name: go-versions-test-results
|
name: go-versions-test-results
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ jobs:
|
|||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: '~> v2'
|
version: '~> v2'
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest', 'macos-14' ]
|
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest', 'macos-14' ]
|
||||||
go: [ '1.24', '1.25' ]
|
go: [ '1.24', '1.25' ]
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ builds:
|
|||||||
- linux_riscv64
|
- linux_riscv64
|
||||||
- windows_amd64
|
- windows_amd64
|
||||||
- windows_arm64
|
- windows_arm64
|
||||||
|
- windows_arm
|
||||||
- darwin_amd64
|
- darwin_amd64
|
||||||
- darwin_arm64
|
- darwin_arm64
|
||||||
- id: tomljson
|
- id: tomljson
|
||||||
@@ -41,6 +42,7 @@ builds:
|
|||||||
- linux_riscv64
|
- linux_riscv64
|
||||||
- windows_amd64
|
- windows_amd64
|
||||||
- windows_arm64
|
- windows_arm64
|
||||||
|
- windows_arm
|
||||||
- darwin_amd64
|
- darwin_amd64
|
||||||
- darwin_arm64
|
- darwin_arm64
|
||||||
- id: jsontoml
|
- id: jsontoml
|
||||||
@@ -60,6 +62,7 @@ builds:
|
|||||||
- linux_arm
|
- linux_arm
|
||||||
- windows_amd64
|
- windows_amd64
|
||||||
- windows_arm64
|
- windows_arm64
|
||||||
|
- windows_arm
|
||||||
- darwin_amd64
|
- darwin_amd64
|
||||||
- darwin_arm64
|
- darwin_arm64
|
||||||
universal_binaries:
|
universal_binaries:
|
||||||
|
|||||||
+257
-1
@@ -4554,10 +4554,266 @@ func (c *customTable873) UnmarshalTOML(data []byte) error {
|
|||||||
c.Keys = append(c.Keys, key)
|
c.Keys = append(c.Keys, key)
|
||||||
c.Values[key] = string(valueBytes)
|
c.Values[key] = string(valueBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue873_TableUnmarshaler(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Section customTable873 `toml:"section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[section]
|
||||||
|
key1 = "value1"
|
||||||
|
key2 = "value2"
|
||||||
|
key3 = "value3"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"key1", "key2", "key3"}, cfg.Section.Keys)
|
||||||
|
assert.Equal(t, "value1", cfg.Section.Values["key1"])
|
||||||
|
assert.Equal(t, "value2", cfg.Section.Values["key2"])
|
||||||
|
assert.Equal(t, "value3", cfg.Section.Values["key3"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssue873_TableUnmarshaler_EmptyTable(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Section customTable873 `toml:"section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[section]
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{}, cfg.Section.Keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssue873_ArrayTableUnmarshaler(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Items []customTable873 `toml:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[[items]]
|
||||||
|
name = "first"
|
||||||
|
id = "1"
|
||||||
|
|
||||||
|
[[items]]
|
||||||
|
name = "second"
|
||||||
|
id = "2"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 2, len(cfg.Items))
|
||||||
|
assert.Equal(t, []string{"name", "id"}, cfg.Items[0].Keys)
|
||||||
|
assert.Equal(t, "first", cfg.Items[0].Values["name"])
|
||||||
|
assert.Equal(t, "1", cfg.Items[0].Values["id"])
|
||||||
|
assert.Equal(t, []string{"name", "id"}, cfg.Items[1].Keys)
|
||||||
|
assert.Equal(t, "second", cfg.Items[1].Values["name"])
|
||||||
|
assert.Equal(t, "2", cfg.Items[1].Values["id"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssue873_NestedTableUnmarshaler(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Outer struct {
|
||||||
|
Inner customTable873 `toml:"inner"`
|
||||||
|
} `toml:"outer"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[outer.inner]
|
||||||
|
a = "A"
|
||||||
|
b = "B"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"a", "b"}, cfg.Outer.Inner.Keys)
|
||||||
|
assert.Equal(t, "A", cfg.Outer.Inner.Values["a"])
|
||||||
|
assert.Equal(t, "B", cfg.Outer.Inner.Values["b"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssue873_TableUnmarshaler_MultipleTables(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
First customTable873 `toml:"first"`
|
||||||
|
Second customTable873 `toml:"second"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[first]
|
||||||
|
key1 = "value1"
|
||||||
|
|
||||||
|
[second]
|
||||||
|
key2 = "value2"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"key1"}, cfg.First.Keys)
|
||||||
|
assert.Equal(t, "value1", cfg.First.Values["key1"])
|
||||||
|
assert.Equal(t, []string{"key2"}, cfg.Second.Keys)
|
||||||
|
assert.Equal(t, "value2", cfg.Second.Values["key2"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that regular struct fields still work alongside Unmarshaler tables
|
||||||
|
func TestIssue873_MixedWithRegularFields(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Name string `toml:"name"`
|
||||||
|
Section customTable873 `toml:"section"`
|
||||||
|
Count int `toml:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
name = "test"
|
||||||
|
count = 42
|
||||||
|
|
||||||
|
[section]
|
||||||
|
foo = "bar"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "test", cfg.Name)
|
||||||
|
assert.Equal(t, 42, cfg.Count)
|
||||||
|
assert.Equal(t, []string{"foo"}, cfg.Section.Keys)
|
||||||
|
assert.Equal(t, "bar", cfg.Section.Values["foo"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that pointer to Unmarshaler type works
|
||||||
|
func TestIssue873_PointerToUnmarshaler(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Section *customTable873 `toml:"section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[section]
|
||||||
|
hello = "world"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, cfg.Section != nil)
|
||||||
|
assert.Equal(t, []string{"hello"}, cfg.Section.Keys)
|
||||||
|
assert.Equal(t, "world", cfg.Section.Values["hello"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test table with sub-tables defined separately
|
||||||
|
func TestIssue873_TableWithSubTables(t *testing.T) {
|
||||||
|
type Config struct {
|
||||||
|
Parent customTable873 `toml:"parent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[parent]
|
||||||
|
name = "root"
|
||||||
|
|
||||||
|
[parent.child]
|
||||||
|
name = "nested"
|
||||||
|
`
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
// The parent should only get the keys directly under [parent],
|
||||||
|
// not the [parent.child] sub-table
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"name"}, cfg.Parent.Keys)
|
||||||
|
assert.Equal(t, "root", cfg.Parent.Values["name"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test for issue #994 follow-up - tables defined piece-wise
|
||||||
|
// This addresses the maintainer's comment: "It doesn't deal with tables defined piece-wise yet"
|
||||||
|
func TestIssue994_TablesPieceWise(t *testing.T) {
|
||||||
|
// Test with piece-wise table definition (using [table] syntax)
|
||||||
|
// The customTable873 type captures key-value pairs in order,
|
||||||
|
// which is useful for use cases like maintaining map ordering
|
||||||
|
doc := `
|
||||||
|
[section]
|
||||||
|
first = "1"
|
||||||
|
second = "2"
|
||||||
|
third = "3"
|
||||||
|
`
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Section customTable873 `toml:"section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&cfg)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
// Verify ordering is preserved (keys are collected in document order)
|
||||||
|
assert.Equal(t, []string{"first", "second", "third"}, cfg.Section.Keys)
|
||||||
|
assert.Equal(t, "1", cfg.Section.Values["first"])
|
||||||
|
assert.Equal(t, "2", cfg.Section.Values["second"])
|
||||||
|
assert.Equal(t, "3", cfg.Section.Values["third"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test root-level struct with tables - combines #994 fix with #873 enhancement
|
||||||
|
func TestIssue994_RootWithTables(t *testing.T) {
|
||||||
|
type rootDoc struct {
|
||||||
|
Tables []customTable873 `toml:"tables"`
|
||||||
|
}
|
||||||
|
|
||||||
|
doc := `
|
||||||
|
[[tables]]
|
||||||
|
name = "first"
|
||||||
|
value = "one"
|
||||||
|
|
||||||
|
[[tables]]
|
||||||
|
name = "second"
|
||||||
|
value = "two"
|
||||||
|
`
|
||||||
|
|
||||||
|
var d rootDoc
|
||||||
|
err := toml.NewDecoder(bytes.NewReader([]byte(doc))).
|
||||||
|
EnableUnmarshalerInterface().
|
||||||
|
Decode(&d)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 2, len(d.Tables))
|
||||||
|
assert.Equal(t, "first", d.Tables[0].Values["name"])
|
||||||
|
assert.Equal(t, "one", d.Tables[0].Values["value"])
|
||||||
|
assert.Equal(t, "second", d.Tables[1].Values["name"])
|
||||||
|
assert.Equal(t, "two", d.Tables[1].Values["value"])
|
||||||
|
}
|
||||||
|
|
||||||
// Test for split tables - when the same parent table is defined in multiple places
|
// Test for split tables - when the same parent table is defined in multiple places
|
||||||
// This is a key requirement for issue #873: if type A implements Unmarshaler,
|
// This is a key requirement for issue #873: if type A implements Unmarshaler,
|
||||||
// and [a.b] and [a.d] are defined with another table [x] in between,
|
// and [a.b] and [a.d] are defined with another table [x] in between,
|
||||||
|
|||||||
Reference in New Issue
Block a user