Skip to content

Commit

Permalink
Fixes #35.
Browse files Browse the repository at this point in the history
reflect.Value.SetUint needs to be called when setting unsigned integers.

Add a test that will catch the error reported in #35.
  • Loading branch information
BurntSushi committed May 14, 2014
1 parent d3bb0cb commit fd595ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func unifyInt(data interface{}, rv reflect.Value) error {
return e("Value '%d' is out of range for uint32.", num)
}
}
rv.SetInt(num)
rv.SetUint(unum)
} else {
panic("unreachable")
}
Expand Down
35 changes: 35 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,41 @@ func TestDecodeSmallInt(t *testing.T) {
}
}

func TestDecodeInts(t *testing.T) {
type table struct {
U8 uint8
U16 uint16
U32 uint32
U64 uint64
U uint
I8 int8
I16 int16
I32 int32
I64 int64
I int
}
answer := table{1, 1, 1, 1, 1, -1, -1, -1, -1, -1}
toml := `
u8 = 1
u16 = 1
u32 = 1
u64 = 1
u = 1
i8 = -1
i16 = -1
i32 = -1
i64 = -1
i = -1
`
var tab table
if _, err := Decode(toml, &tab); err != nil {
t.Fatal(err.Error())
}
if answer != tab {
t.Fatalf("Expected %p but got %p", answer, tab)
}
}

func ExamplePrimitiveDecode() {
var md MetaData
var err error
Expand Down

0 comments on commit fd595ec

Please sign in to comment.