Commit 566f390c authored by Martin Möhrmann's avatar Martin Möhrmann

strconv: adjust test output and names for parseUint and parseInt

Instead of printing Atoi as function name for test failures
print the actual function name and arguments tested.

Add a base field to the parseUint64BaseTests for consistency with
the parseInt64BaseTests tests.

Change-Id: Ib9891bdb87b62672b4216625212acfe6474c70fc
Reviewed-on: https://go-review.googlesource.com/55136
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
parent 2c990f45
...@@ -11,13 +11,13 @@ import ( ...@@ -11,13 +11,13 @@ import (
"testing" "testing"
) )
type atoui64Test struct { type parseUint64Test struct {
in string in string
out uint64 out uint64
err error err error
} }
var atoui64tests = []atoui64Test{ var parseUint64Tests = []parseUint64Test{
{"", 0, ErrSyntax}, {"", 0, ErrSyntax},
{"0", 0, nil}, {"0", 0, nil},
{"1", 1, nil}, {"1", 1, nil},
...@@ -30,38 +30,45 @@ var atoui64tests = []atoui64Test{ ...@@ -30,38 +30,45 @@ var atoui64tests = []atoui64Test{
{"18446744073709551620", 1<<64 - 1, ErrRange}, {"18446744073709551620", 1<<64 - 1, ErrRange},
} }
var btoui64tests = []atoui64Test{ type parseUint64BaseTest struct {
{"", 0, ErrSyntax}, in string
{"0", 0, nil}, base int
{"0x", 0, ErrSyntax}, out uint64
{"0X", 0, ErrSyntax}, err error
{"1", 1, nil},
{"12345", 12345, nil},
{"012345", 012345, nil},
{"0x12345", 0x12345, nil},
{"0X12345", 0x12345, nil},
{"12345x", 0, ErrSyntax},
{"0xabcdefg123", 0, ErrSyntax},
{"123456789abc", 0, ErrSyntax},
{"98765432100", 98765432100, nil},
{"18446744073709551615", 1<<64 - 1, nil},
{"18446744073709551616", 1<<64 - 1, ErrRange},
{"18446744073709551620", 1<<64 - 1, ErrRange},
{"0xFFFFFFFFFFFFFFFF", 1<<64 - 1, nil},
{"0x10000000000000000", 1<<64 - 1, ErrRange},
{"01777777777777777777777", 1<<64 - 1, nil},
{"01777777777777777777778", 0, ErrSyntax},
{"02000000000000000000000", 1<<64 - 1, ErrRange},
{"0200000000000000000000", 1 << 61, nil},
} }
type atoi64Test struct { var parseUint64BaseTests = []parseUint64BaseTest{
{"", 0, 0, ErrSyntax},
{"0", 0, 0, nil},
{"0x", 0, 0, ErrSyntax},
{"0X", 0, 0, ErrSyntax},
{"1", 0, 1, nil},
{"12345", 0, 12345, nil},
{"012345", 0, 012345, nil},
{"0x12345", 0, 0x12345, nil},
{"0X12345", 0, 0x12345, nil},
{"12345x", 0, 0, ErrSyntax},
{"0xabcdefg123", 0, 0, ErrSyntax},
{"123456789abc", 0, 0, ErrSyntax},
{"98765432100", 0, 98765432100, nil},
{"18446744073709551615", 0, 1<<64 - 1, nil},
{"18446744073709551616", 0, 1<<64 - 1, ErrRange},
{"18446744073709551620", 0, 1<<64 - 1, ErrRange},
{"0xFFFFFFFFFFFFFFFF", 0, 1<<64 - 1, nil},
{"0x10000000000000000", 0, 1<<64 - 1, ErrRange},
{"01777777777777777777777", 0, 1<<64 - 1, nil},
{"01777777777777777777778", 0, 0, ErrSyntax},
{"02000000000000000000000", 0, 1<<64 - 1, ErrRange},
{"0200000000000000000000", 0, 1 << 61, nil},
}
type parseInt64Test struct {
in string in string
out int64 out int64
err error err error
} }
var atoi64tests = []atoi64Test{ var parseInt64Tests = []parseInt64Test{
{"", 0, ErrSyntax}, {"", 0, ErrSyntax},
{"0", 0, nil}, {"0", 0, nil},
{"-0", 0, nil}, {"-0", 0, nil},
...@@ -81,14 +88,14 @@ var atoi64tests = []atoi64Test{ ...@@ -81,14 +88,14 @@ var atoi64tests = []atoi64Test{
{"-9223372036854775809", -1 << 63, ErrRange}, {"-9223372036854775809", -1 << 63, ErrRange},
} }
type btoi64Test struct { type parseInt64BaseTest struct {
in string in string
base int base int
out int64 out int64
err error err error
} }
var btoi64tests = []btoi64Test{ var parseInt64BaseTests = []parseInt64BaseTest{
{"", 0, 0, ErrSyntax}, {"", 0, 0, ErrSyntax},
{"0", 0, 0, nil}, {"0", 0, 0, nil},
{"-0", 0, 0, nil}, {"-0", 0, 0, nil},
...@@ -138,13 +145,13 @@ var btoi64tests = []btoi64Test{ ...@@ -138,13 +145,13 @@ var btoi64tests = []btoi64Test{
{"7fffffffffffffff", 16, 1<<63 - 1, nil}, {"7fffffffffffffff", 16, 1<<63 - 1, nil},
} }
type atoui32Test struct { type parseUint32Test struct {
in string in string
out uint32 out uint32
err error err error
} }
var atoui32tests = []atoui32Test{ var parseUint32Tests = []parseUint32Test{
{"", 0, ErrSyntax}, {"", 0, ErrSyntax},
{"0", 0, nil}, {"0", 0, nil},
{"1", 1, nil}, {"1", 1, nil},
...@@ -156,13 +163,13 @@ var atoui32tests = []atoui32Test{ ...@@ -156,13 +163,13 @@ var atoui32tests = []atoui32Test{
{"4294967296", 1<<32 - 1, ErrRange}, {"4294967296", 1<<32 - 1, ErrRange},
} }
type atoi32Test struct { type parseInt32Test struct {
in string in string
out int32 out int32
err error err error
} }
var atoi32tests = []atoi32Test{ var parseInt32Tests = []parseInt32Test{
{"", 0, ErrSyntax}, {"", 0, ErrSyntax},
{"0", 0, nil}, {"0", 0, nil},
{"-0", 0, nil}, {"-0", 0, nil},
...@@ -195,40 +202,40 @@ var numErrorTests = []numErrorTest{ ...@@ -195,40 +202,40 @@ var numErrorTests = []numErrorTest{
} }
func init() { func init() {
// The atoi routines return NumErrors wrapping // The parse routines return NumErrors wrapping
// the error and the string. Convert the tables above. // the error and the string. Convert the tables above.
for i := range atoui64tests { for i := range parseUint64Tests {
test := &atoui64tests[i] test := &parseUint64Tests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseUint", test.in, test.err} test.err = &NumError{"ParseUint", test.in, test.err}
} }
} }
for i := range btoui64tests { for i := range parseUint64BaseTests {
test := &btoui64tests[i] test := &parseUint64BaseTests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseUint", test.in, test.err} test.err = &NumError{"ParseUint", test.in, test.err}
} }
} }
for i := range atoi64tests { for i := range parseInt64Tests {
test := &atoi64tests[i] test := &parseInt64Tests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseInt", test.in, test.err} test.err = &NumError{"ParseInt", test.in, test.err}
} }
} }
for i := range btoi64tests { for i := range parseInt64BaseTests {
test := &btoi64tests[i] test := &parseInt64BaseTests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseInt", test.in, test.err} test.err = &NumError{"ParseInt", test.in, test.err}
} }
} }
for i := range atoui32tests { for i := range parseUint32Tests {
test := &atoui32tests[i] test := &parseUint32Tests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseUint", test.in, test.err} test.err = &NumError{"ParseUint", test.in, test.err}
} }
} }
for i := range atoi32tests { for i := range parseInt32Tests {
test := &atoi32tests[i] test := &parseInt32Tests[i]
if test.err != nil { if test.err != nil {
test.err = &NumError{"ParseInt", test.in, test.err} test.err = &NumError{"ParseInt", test.in, test.err}
} }
...@@ -236,67 +243,67 @@ func init() { ...@@ -236,67 +243,67 @@ func init() {
} }
func TestParseUint32(t *testing.T) { func TestParseUint32(t *testing.T) {
for i := range atoui32tests { for i := range parseUint32Tests {
test := &atoui32tests[i] test := &parseUint32Tests[i]
out, err := ParseUint(test.in, 10, 32) out, err := ParseUint(test.in, 10, 32)
if uint64(test.out) != out || !reflect.DeepEqual(test.err, err) { if uint64(test.out) != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui32(%q) = %v, %v want %v, %v", t.Errorf("ParseUint(%q, 10, 32) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
} }
func TestParseUint64(t *testing.T) { func TestParseUint64(t *testing.T) {
for i := range atoui64tests { for i := range parseUint64Tests {
test := &atoui64tests[i] test := &parseUint64Tests[i]
out, err := ParseUint(test.in, 10, 64) out, err := ParseUint(test.in, 10, 64)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui64(%q) = %v, %v want %v, %v", t.Errorf("ParseUint(%q, 10, 64) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
} }
func TestParseUint64Base(t *testing.T) { func TestParseUint64Base(t *testing.T) {
for i := range btoui64tests { for i := range parseUint64BaseTests {
test := &btoui64tests[i] test := &parseUint64BaseTests[i]
out, err := ParseUint(test.in, 0, 64) out, err := ParseUint(test.in, test.base, 64)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("ParseUint(%q) = %v, %v want %v, %v", t.Errorf("ParseUint(%q, %v, 64) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, test.base, out, err, test.out, test.err)
} }
} }
} }
func TestParseInt32(t *testing.T) { func TestParseInt32(t *testing.T) {
for i := range atoi32tests { for i := range parseInt32Tests {
test := &atoi32tests[i] test := &parseInt32Tests[i]
out, err := ParseInt(test.in, 10, 32) out, err := ParseInt(test.in, 10, 32)
if int64(test.out) != out || !reflect.DeepEqual(test.err, err) { if int64(test.out) != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi32(%q) = %v, %v want %v, %v", t.Errorf("ParseInt(%q, 10 ,32) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
} }
func TestParseInt64(t *testing.T) { func TestParseInt64(t *testing.T) {
for i := range atoi64tests { for i := range parseInt64Tests {
test := &atoi64tests[i] test := &parseInt64Tests[i]
out, err := ParseInt(test.in, 10, 64) out, err := ParseInt(test.in, 10, 64)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi64(%q) = %v, %v want %v, %v", t.Errorf("ParseInt(%q, 10, 64) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
} }
func TestParseInt64Base(t *testing.T) { func TestParseInt64Base(t *testing.T) {
for i := range btoi64tests { for i := range parseInt64BaseTests {
test := &btoi64tests[i] test := &parseInt64BaseTests[i]
out, err := ParseInt(test.in, test.base, 64) out, err := ParseInt(test.in, test.base, 64)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("ParseInt(%q) = %v, %v want %v, %v", t.Errorf("ParseInt(%q, %v, 64) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, test.base, out, err, test.out, test.err)
} }
} }
} }
...@@ -304,20 +311,20 @@ func TestParseInt64Base(t *testing.T) { ...@@ -304,20 +311,20 @@ func TestParseInt64Base(t *testing.T) {
func TestParseUint(t *testing.T) { func TestParseUint(t *testing.T) {
switch IntSize { switch IntSize {
case 32: case 32:
for i := range atoui32tests { for i := range parseUint32Tests {
test := &atoui32tests[i] test := &parseUint32Tests[i]
out, err := ParseUint(test.in, 10, 0) out, err := ParseUint(test.in, 10, 0)
if uint64(test.out) != out || !reflect.DeepEqual(test.err, err) { if uint64(test.out) != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui(%q) = %v, %v want %v, %v", t.Errorf("ParseUint(%q, 10, 0) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
case 64: case 64:
for i := range atoui64tests { for i := range parseUint64Tests {
test := &atoui64tests[i] test := &parseUint64Tests[i]
out, err := ParseUint(test.in, 10, 0) out, err := ParseUint(test.in, 10, 0)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui(%q) = %v, %v want %v, %v", t.Errorf("ParseUint(%q, 10, 0) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
...@@ -327,20 +334,20 @@ func TestParseUint(t *testing.T) { ...@@ -327,20 +334,20 @@ func TestParseUint(t *testing.T) {
func TestParseInt(t *testing.T) { func TestParseInt(t *testing.T) {
switch IntSize { switch IntSize {
case 32: case 32:
for i := range atoi32tests { for i := range parseInt32Tests {
test := &atoi32tests[i] test := &parseInt32Tests[i]
out, err := ParseInt(test.in, 10, 0) out, err := ParseInt(test.in, 10, 0)
if int64(test.out) != out || !reflect.DeepEqual(test.err, err) { if int64(test.out) != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi(%q) = %v, %v want %v, %v", t.Errorf("ParseInt(%q, 10, 0) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
case 64: case 64:
for i := range atoi64tests { for i := range parseInt64Tests {
test := &atoi64tests[i] test := &parseInt64Tests[i]
out, err := ParseInt(test.in, 10, 0) out, err := ParseInt(test.in, 10, 0)
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi(%q) = %v, %v want %v, %v", t.Errorf("ParseInt(%q, 10, 0) = %v, %v want %v, %v",
test.in, out, err, test.out, test.err) test.in, out, err, test.out, test.err)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment