summaryrefslogtreecommitdiff
path: root/src/lib/strconv/itoa_test.go
blob: 89a97339e337b874e9e531dfaa2c07739a117be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package strconv

import (
	"fmt";
	"os";
	"strconv";
	"testing";
)

type Int64Test struct {
	in int64;
	out string;
}

// TODO: should be called int64tests

var xint64tests = []Int64Test {
	Int64Test{ 0, "0" },
	Int64Test{ 1, "1" },
	Int64Test{ -1, "-1" },
	Int64Test{ 12345678, "12345678" },
	Int64Test{ -987654321, "-987654321" },
	Int64Test{ 1<<31-1, "2147483647" },
	Int64Test{ -1<<31+1, "-2147483647" },
	Int64Test{ 1<<31, "2147483648" },
	Int64Test{ -1<<31, "-2147483648" },
	Int64Test{ 1<<31+1, "2147483649" },
	Int64Test{ -1<<31-1, "-2147483649" },
	Int64Test{ 1<<32-1, "4294967295" },
	Int64Test{ -1<<32+1, "-4294967295" },
	Int64Test{ 1<<32, "4294967296" },
	Int64Test{ -1<<32, "-4294967296" },
	Int64Test{ 1<<32+1, "4294967297" },
	Int64Test{ -1<<32-1, "-4294967297" },
	Int64Test{ 1<<50, "1125899906842624" },
	Int64Test{ 1<<63-1, "9223372036854775807" },
	Int64Test{ -1<<63+1, "-9223372036854775807" },
	Int64Test{ -1<<63, "-9223372036854775808" },
}

export func TestItoa(t *testing.T) {
	for i := 0; i < len(xint64tests); i++ {
		test := xint64tests[i];
		s := strconv.itoa64(test.in);
		if s != test.out {
			t.Error("strconv.itoa64(%v) = %v want %v\n",
				test.in, s, test.out);
		}
		if int64(int(test.in)) == test.in {
			s := strconv.itoa(int(test.in));
			if s != test.out {
				t.Error("strconv.itoa(%v) = %v want %v\n",
					test.in, s, test.out);
			}
		}
	}
}

// TODO: Use once there is a strconv.uitoa
type Uint64Test struct {
	in uint64;
	out string;
}

// TODO: should be able to call this uint64tests.
var xuint64tests = []Uint64Test {
	Uint64Test{ 1<<63-1, "9223372036854775807" },
	Uint64Test{ 1<<63, "9223372036854775808" },
	Uint64Test{ 1<<63+1, "9223372036854775809" },
	Uint64Test{ 1<<64-2, "18446744073709551614" },
	Uint64Test{ 1<<64-1, "18446744073709551615" },
}