Skip default tags tests

This commit is contained in:
Thomas Pelletier
2021-02-19 19:48:43 -05:00
parent d24deebee3
commit c77f1d815c
+148 -147
View File
@@ -11,7 +11,6 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"strconv" "strconv"
"strings"
"testing" "testing"
"time" "time"
@@ -536,9 +535,7 @@ func TestPointerUnmarshal(t *testing.T) {
func TestUnmarshalTypeMismatch(t *testing.T) { func TestUnmarshalTypeMismatch(t *testing.T) {
result := pointerMarshalTestStruct{} result := pointerMarshalTestStruct{}
err := toml.Unmarshal([]byte("List = 123"), &result) err := toml.Unmarshal([]byte("List = 123"), &result)
if !strings.HasPrefix(err.Error(), "(1, 1): Can't convert 123(int64) to []string(slice)") { assert.Error(t, err)
t.Errorf("Type mismatch must be reported: got %v", err.Error())
}
} }
type nestedMarshalTestStruct struct { type nestedMarshalTestStruct struct {
@@ -1067,163 +1064,166 @@ func TestUnmarshalOverflow(t *testing.T) {
} }
func TestUnmarshalDefault(t *testing.T) { func TestUnmarshalDefault(t *testing.T) {
type EmbeddedStruct struct { t.Skipf("don't know if it is a good idea to have `default`")
StringField string `default:"c"` t.Run("main", func(t *testing.T) {
} type EmbeddedStruct struct {
StringField string `default:"c"`
type aliasUint uint
var doc struct {
StringField string `default:"a"`
BoolField bool `default:"true"`
UintField uint `default:"1"`
Uint8Field uint8 `default:"8"`
Uint16Field uint16 `default:"16"`
Uint32Field uint32 `default:"32"`
Uint64Field uint64 `default:"64"`
IntField int `default:"-1"`
Int8Field int8 `default:"-8"`
Int16Field int16 `default:"-16"`
Int32Field int32 `default:"-32"`
Int64Field int64 `default:"-64"`
Float32Field float32 `default:"32.1"`
Float64Field float64 `default:"64.1"`
DurationField time.Duration `default:"120ms"`
DurationField2 time.Duration `default:"120000000"`
NonEmbeddedStruct struct {
StringField string `default:"b"`
} }
EmbeddedStruct
AliasUintField aliasUint `default:"1000"`
}
err := toml.Unmarshal([]byte(``), &doc) type aliasUint uint
if err != nil {
t.Fatal(err)
}
if doc.BoolField != true {
t.Errorf("BoolField should be true, not %t", doc.BoolField)
}
if doc.StringField != "a" {
t.Errorf("StringField should be \"a\", not %s", doc.StringField)
}
if doc.UintField != 1 {
t.Errorf("UintField should be 1, not %d", doc.UintField)
}
if doc.Uint8Field != 8 {
t.Errorf("Uint8Field should be 8, not %d", doc.Uint8Field)
}
if doc.Uint16Field != 16 {
t.Errorf("Uint16Field should be 16, not %d", doc.Uint16Field)
}
if doc.Uint32Field != 32 {
t.Errorf("Uint32Field should be 32, not %d", doc.Uint32Field)
}
if doc.Uint64Field != 64 {
t.Errorf("Uint64Field should be 64, not %d", doc.Uint64Field)
}
if doc.IntField != -1 {
t.Errorf("IntField should be -1, not %d", doc.IntField)
}
if doc.Int8Field != -8 {
t.Errorf("Int8Field should be -8, not %d", doc.Int8Field)
}
if doc.Int16Field != -16 {
t.Errorf("Int16Field should be -16, not %d", doc.Int16Field)
}
if doc.Int32Field != -32 {
t.Errorf("Int32Field should be -32, not %d", doc.Int32Field)
}
if doc.Int64Field != -64 {
t.Errorf("Int64Field should be -64, not %d", doc.Int64Field)
}
if doc.Float32Field != 32.1 {
t.Errorf("Float32Field should be 32.1, not %f", doc.Float32Field)
}
if doc.Float64Field != 64.1 {
t.Errorf("Float64Field should be 64.1, not %f", doc.Float64Field)
}
if doc.DurationField != 120*time.Millisecond {
t.Errorf("DurationField should be 120ms, not %s", doc.DurationField.String())
}
if doc.DurationField2 != 120*time.Millisecond {
t.Errorf("DurationField2 should be 120000000, not %d", doc.DurationField2)
}
if doc.NonEmbeddedStruct.StringField != "b" {
t.Errorf("StringField should be \"b\", not %s", doc.NonEmbeddedStruct.StringField)
}
if doc.EmbeddedStruct.StringField != "c" {
t.Errorf("StringField should be \"c\", not %s", doc.EmbeddedStruct.StringField)
}
if doc.AliasUintField != 1000 {
t.Errorf("AliasUintField should be 1000, not %d", doc.AliasUintField)
}
}
func TestUnmarshalDefaultFailureBool(t *testing.T) { var doc struct {
var doc struct { StringField string `default:"a"`
Field bool `default:"blah"` BoolField bool `default:"true"`
} UintField uint `default:"1"`
Uint8Field uint8 `default:"8"`
Uint16Field uint16 `default:"16"`
Uint32Field uint32 `default:"32"`
Uint64Field uint64 `default:"64"`
IntField int `default:"-1"`
Int8Field int8 `default:"-8"`
Int16Field int16 `default:"-16"`
Int32Field int32 `default:"-32"`
Int64Field int64 `default:"-64"`
Float32Field float32 `default:"32.1"`
Float64Field float64 `default:"64.1"`
DurationField time.Duration `default:"120ms"`
DurationField2 time.Duration `default:"120000000"`
NonEmbeddedStruct struct {
StringField string `default:"b"`
}
EmbeddedStruct
AliasUintField aliasUint `default:"1000"`
}
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err != nil {
t.Fatal("should error") t.Fatal(err)
} }
} if doc.BoolField != true {
t.Errorf("BoolField should be true, not %t", doc.BoolField)
}
if doc.StringField != "a" {
t.Errorf("StringField should be \"a\", not %s", doc.StringField)
}
if doc.UintField != 1 {
t.Errorf("UintField should be 1, not %d", doc.UintField)
}
if doc.Uint8Field != 8 {
t.Errorf("Uint8Field should be 8, not %d", doc.Uint8Field)
}
if doc.Uint16Field != 16 {
t.Errorf("Uint16Field should be 16, not %d", doc.Uint16Field)
}
if doc.Uint32Field != 32 {
t.Errorf("Uint32Field should be 32, not %d", doc.Uint32Field)
}
if doc.Uint64Field != 64 {
t.Errorf("Uint64Field should be 64, not %d", doc.Uint64Field)
}
if doc.IntField != -1 {
t.Errorf("IntField should be -1, not %d", doc.IntField)
}
if doc.Int8Field != -8 {
t.Errorf("Int8Field should be -8, not %d", doc.Int8Field)
}
if doc.Int16Field != -16 {
t.Errorf("Int16Field should be -16, not %d", doc.Int16Field)
}
if doc.Int32Field != -32 {
t.Errorf("Int32Field should be -32, not %d", doc.Int32Field)
}
if doc.Int64Field != -64 {
t.Errorf("Int64Field should be -64, not %d", doc.Int64Field)
}
if doc.Float32Field != 32.1 {
t.Errorf("Float32Field should be 32.1, not %f", doc.Float32Field)
}
if doc.Float64Field != 64.1 {
t.Errorf("Float64Field should be 64.1, not %f", doc.Float64Field)
}
if doc.DurationField != 120*time.Millisecond {
t.Errorf("DurationField should be 120ms, not %s", doc.DurationField.String())
}
if doc.DurationField2 != 120*time.Millisecond {
t.Errorf("DurationField2 should be 120000000, not %d", doc.DurationField2)
}
if doc.NonEmbeddedStruct.StringField != "b" {
t.Errorf("StringField should be \"b\", not %s", doc.NonEmbeddedStruct.StringField)
}
if doc.EmbeddedStruct.StringField != "c" {
t.Errorf("StringField should be \"c\", not %s", doc.EmbeddedStruct.StringField)
}
if doc.AliasUintField != 1000 {
t.Errorf("AliasUintField should be 1000, not %d", doc.AliasUintField)
}
})
func TestUnmarshalDefaultFailureInt(t *testing.T) { t.Run("failure bool", func(t *testing.T) {
var doc struct { var doc struct {
Field int `default:"blah"` Field bool `default:"blah"`
} }
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
} })
func TestUnmarshalDefaultFailureInt64(t *testing.T) { t.Run("failure int", func(t *testing.T) {
var doc struct { var doc struct {
Field int64 `default:"blah"` Field int `default:"blah"`
} }
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
} })
func TestUnmarshalDefaultFailureFloat64(t *testing.T) { t.Run("failure int64", func(t *testing.T) {
var doc struct { var doc struct {
Field float64 `default:"blah"` Field int64 `default:"blah"`
} }
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
} })
func TestUnmarshalDefaultFailureDuration(t *testing.T) { t.Run("failure float64", func(t *testing.T) {
var doc struct { var doc struct {
Field time.Duration `default:"blah"` Field float64 `default:"blah"`
} }
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
} })
func TestUnmarshalDefaultFailureUnsupported(t *testing.T) { t.Run("failure duration", func(t *testing.T) {
var doc struct { var doc struct {
Field struct{} `default:"blah"` Field time.Duration `default:"blah"`
} }
err := toml.Unmarshal([]byte(``), &doc) err := toml.Unmarshal([]byte(``), &doc)
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
})
t.Run("failure unsupported", func(t *testing.T) {
var doc struct {
Field struct{} `default:"blah"`
}
err := toml.Unmarshal([]byte(``), &doc)
if err == nil {
t.Fatal("should error")
}
})
} }
func TestUnmarshalNestedAnonymousStructs(t *testing.T) { func TestUnmarshalNestedAnonymousStructs(t *testing.T) {
@@ -1250,6 +1250,7 @@ func TestUnmarshalNestedAnonymousStructs(t *testing.T) {
} }
func TestUnmarshalNestedAnonymousStructs_Controversial(t *testing.T) { func TestUnmarshalNestedAnonymousStructs_Controversial(t *testing.T) {
// TODO: what does encoding/json do?
type Nested struct { type Nested struct {
Value string `toml:"nested"` Value string `toml:"nested"`
} }