Import upstream version 1.5.0+git20220423.1.bf980b3
Debian Janitor
1 year, 3 months ago
0 | |
on: [push, pull_request]
|
1 | |
name: Test
|
2 | |
jobs:
|
3 | |
test:
|
4 | |
strategy:
|
5 | |
matrix:
|
6 | |
go-version: [1.15.x]
|
7 | |
os: [ubuntu-latest]
|
8 | |
runs-on: ${{ matrix.os }}
|
9 | |
steps:
|
10 | |
- name: Install Go
|
11 | |
uses: actions/setup-go@v2
|
12 | |
with:
|
13 | |
go-version: ${{ matrix.go-version }}
|
14 | |
- name: Checkout code
|
15 | |
uses: actions/checkout@v2
|
16 | |
- name: Test
|
17 | |
run: go test ./...
|
|
0 |
## 1.5.1
|
|
1 |
|
|
2 |
* Wrap errors so they're compatible with `errors.Is` and `errors.As` [GH-282]
|
|
3 |
* Fix map of slices not decoding properly in certain cases. [GH-266]
|
|
4 |
|
0 | 5 |
## 1.5.0
|
1 | 6 |
|
2 | 7 |
* New option `IgnoreUntaggedFields` to ignore decoding to any fields
|
457 | 457 |
var err error
|
458 | 458 |
input, err = DecodeHookExec(d.config.DecodeHook, inputVal, outVal)
|
459 | 459 |
if err != nil {
|
460 | |
return fmt.Errorf("error decoding '%s': %s", name, err)
|
|
460 |
return fmt.Errorf("error decoding '%s': %w", name, err)
|
461 | 461 |
}
|
462 | 462 |
}
|
463 | 463 |
|
|
1122 | 1122 |
if valSlice.IsNil() || d.config.ZeroFields {
|
1123 | 1123 |
// Make a new slice to hold our result, same size as the original data.
|
1124 | 1124 |
valSlice = reflect.MakeSlice(sliceType, dataVal.Len(), dataVal.Len())
|
|
1125 |
} else if valSlice.Len() > dataVal.Len() {
|
|
1126 |
valSlice = valSlice.Slice(0, dataVal.Len())
|
1125 | 1127 |
}
|
1126 | 1128 |
|
1127 | 1129 |
// Accumulate any errors
|
135 | 135 |
type Slice struct {
|
136 | 136 |
Vfoo string
|
137 | 137 |
Vbar []string
|
|
138 |
}
|
|
139 |
|
|
140 |
type SliceOfByte struct {
|
|
141 |
Vfoo string
|
|
142 |
Vbar []byte
|
138 | 143 |
}
|
139 | 144 |
|
140 | 145 |
type SliceOfAlias struct {
|
|
1653 | 1658 |
testSliceInput(t, inputStringSlicePointer, outputStringSlice)
|
1654 | 1659 |
}
|
1655 | 1660 |
|
|
1661 |
func TestNotEmptyByteSlice(t *testing.T) {
|
|
1662 |
t.Parallel()
|
|
1663 |
|
|
1664 |
inputByteSlice := map[string]interface{}{
|
|
1665 |
"vfoo": "foo",
|
|
1666 |
"vbar": []byte(`{"bar": "bar"}`),
|
|
1667 |
}
|
|
1668 |
|
|
1669 |
result := SliceOfByte{
|
|
1670 |
Vfoo: "another foo",
|
|
1671 |
Vbar: []byte(`{"bar": "bar bar bar bar bar bar bar bar"}`),
|
|
1672 |
}
|
|
1673 |
|
|
1674 |
err := Decode(inputByteSlice, &result)
|
|
1675 |
if err != nil {
|
|
1676 |
t.Fatalf("got unexpected error: %s", err)
|
|
1677 |
}
|
|
1678 |
|
|
1679 |
expected := SliceOfByte{
|
|
1680 |
Vfoo: "foo",
|
|
1681 |
Vbar: []byte(`{"bar": "bar"}`),
|
|
1682 |
}
|
|
1683 |
|
|
1684 |
if !reflect.DeepEqual(result, expected) {
|
|
1685 |
t.Errorf("bad: %#v", result)
|
|
1686 |
}
|
|
1687 |
}
|
|
1688 |
|
1656 | 1689 |
func TestInvalidSlice(t *testing.T) {
|
1657 | 1690 |
t.Parallel()
|
1658 | 1691 |
|