convert composite literals from { } to ( ).

only non-trivial changes are in
	convlit1.go
	golden.out

R=gri
OCL=25019
CL=25024
This commit is contained in:
Russ Cox 2009-02-13 14:48:32 -08:00
parent 07244f7c80
commit 9f8f2e6130
92 changed files with 1598 additions and 1600 deletions

View file

@ -32,7 +32,7 @@ type rotate13 struct {
} }
func newRotate13(source reader) *rotate13 { func newRotate13(source reader) *rotate13 {
return &rotate13{source} return &rotate13(source)
} }
func (r13 *rotate13) Read(b []byte) (ret int, err *os.Error) { func (r13 *rotate13) Read(b []byte) (ret int, err *os.Error) {

View file

@ -18,7 +18,7 @@ func newFD(fd int64, name string) *FD {
if fd < 0 { if fd < 0 {
return nil return nil
} }
return &FD{fd, name} return &FD(fd, name)
} }
var ( var (

View file

@ -7,7 +7,7 @@ package main
import fd "fd" import fd "fd"
func main() { func main() {
hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'}; hello := []byte('h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n');
fd.Stdout.Write(hello); fd.Stdout.Write(hello);
file, err := fd.Open("/does/not/exist", 0, 0); file, err := fd.Open("/does/not/exist", 0, 0);
if file == nil { if file == nil {

View file

@ -12,8 +12,8 @@ func main() {
// harder stuff // harder stuff
type T struct { a int; b string }; type T struct { a int; b string };
t := T{77, "Sunset Strip"}; t := T(77, "Sunset Strip");
a := []int{1, 2, 3, 4}; a := []int(1, 2, 3, 4);
fmt.Printf("%v %v %v\n", u64, t, a); fmt.Printf("%v %v %v\n", u64, t, a);
fmt.Print(u64, " ", t, " ", a, "\n"); fmt.Print(u64, " ", t, " ", a, "\n");
fmt.Println(u64, t, a); fmt.Println(u64, t, a);

View file

@ -13,6 +13,6 @@ func (t *testType) String() string {
} }
func main() { func main() {
t := &testType{77, "Sunset Strip"}; t := &testType(77, "Sunset Strip");
fmt.Println(t) fmt.Println(t)
} }

View file

@ -7,7 +7,7 @@ package main
import "sort" import "sort"
func ints() { func ints() {
data := []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586}; data := []int(74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586);
a := sort.IntArray(data); a := sort.IntArray(data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
@ -16,7 +16,7 @@ func ints() {
} }
func strings() { func strings() {
data := []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}; data := []string("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
a := sort.StringArray(data); a := sort.StringArray(data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
@ -39,15 +39,15 @@ func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num;
func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i]; } func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i]; }
func days() { func days() {
Sunday := day{ 0, "SUN", "Sunday" }; Sunday := day( 0, "SUN", "Sunday" );
Monday := day{ 1, "MON", "Monday" }; Monday := day( 1, "MON", "Monday" );
Tuesday := day{ 2, "TUE", "Tuesday" }; Tuesday := day( 2, "TUE", "Tuesday" );
Wednesday := day{ 3, "WED", "Wednesday" }; Wednesday := day( 3, "WED", "Wednesday" );
Thursday := day{ 4, "THU", "Thursday" }; Thursday := day( 4, "THU", "Thursday" );
Friday := day{ 5, "FRI", "Friday" }; Friday := day( 5, "FRI", "Friday" );
Saturday := day{ 6, "SAT", "Saturday" }; Saturday := day( 6, "SAT", "Saturday" );
data := []*day{&Tuesday, &Thursday, &Sunday, &Monday, &Friday}; data := []*day(&Tuesday, &Thursday, &Sunday, &Monday, &Friday);
a := dayArray{data}; a := dayArray(data);
sort.Sort(&a); sort.Sort(&a);
if !sort.IsSorted(&a) { if !sort.IsSorted(&a) {
panic() panic()

View file

@ -14,6 +14,6 @@ func sum(a []int) int { // returns an int
func main() { func main() {
s := sum([3]int{1,2,3}); // a slice of the array is passed to sum s := sum([3]int(1,2,3)); // a slice of the array is passed to sum
print(s, "\n"); print(s, "\n");
} }

View file

@ -71,7 +71,7 @@ trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
echo 'import "testing"' echo 'import "testing"'
# test array # test array
echo echo
echo 'var tests = []testing.Test {' echo 'var tests = []testing.Test('
for ofile in $ofiles for ofile in $ofiles
do do
# test functions are named TestFoo # test functions are named TestFoo
@ -84,11 +84,11 @@ trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
else else
for i in $tests for i in $tests
do do
echo ' testing.Test{ "'$i'", '$i' },' echo ' testing.Test( "'$i'", '$i' ),'
done done
fi fi
done done
echo '}' echo ')'
# body # body
echo echo
echo 'func main() {' echo 'func main() {'

View file

@ -114,10 +114,10 @@ func Dump(x []Digit) {
type Natural []Digit; type Natural []Digit;
var ( var (
natZero Natural = Natural{}; natZero Natural = Natural();
natOne Natural = Natural{1}; natOne Natural = Natural(1);
natTwo Natural = Natural{2}; natTwo Natural = Natural(2);
natTen Natural = Natural{10}; natTen Natural = Natural(10);
) )
@ -131,7 +131,7 @@ func Nat(x uint) Natural {
case 10: return natTen; case 10: return natTen;
} }
assert(Digit(x) < _B); assert(Digit(x) < _B);
return Natural{Digit(x)}; return Natural(Digit(x));
} }
@ -818,7 +818,7 @@ func MakeInt(sign bool, mant Natural) *Integer {
if mant.IsZero() { if mant.IsZero() {
sign = false; // normalize sign = false; // normalize
} }
return &Integer{sign, mant}; return &Integer(sign, mant);
} }
@ -1140,7 +1140,7 @@ func MakeRat(a *Integer, b Natural) *Rational {
a = MakeInt(a.sign, a.mant.Div(f)); a = MakeInt(a.sign, a.mant.Div(f));
b = b.Div(f); b = b.Div(f);
} }
return &Rational{a, b}; return &Rational(a, b);
} }

View file

@ -264,16 +264,16 @@ func TestIntQuoRem(t *testing.T) {
tester = t; tester = t;
test_msg = "IntQuoRem"; test_msg = "IntQuoRem";
type T struct { x, y, q, r int }; type T struct { x, y, q, r int };
a := []T{ a := []T(
T{+8, +3, +2, +2}, T(+8, +3, +2, +2),
T{+8, -3, -2, +2}, T(+8, -3, -2, +2),
T{-8, +3, -2, -2}, T(-8, +3, -2, -2),
T{-8, -3, +2, -2}, T(-8, -3, +2, -2),
T{+1, +2, 0, +1}, T(+1, +2, 0, +1),
T{+1, -2, 0, +1}, T(+1, -2, 0, +1),
T{-1, +2, 0, -1}, T(-1, +2, 0, -1),
T{-1, -2, 0, -1}, T(-1, -2, 0, -1),
}; );
for i := uint(0); i < uint(len(a)); i++ { for i := uint(0); i < uint(len(a)); i++ {
e := &a[i]; e := &a[i];
x, y := bignum.Int(e.x).Mul(ip), bignum.Int(e.y).Mul(ip); x, y := bignum.Int(e.x).Mul(ip), bignum.Int(e.y).Mul(ip);
@ -291,16 +291,16 @@ func TestIntDivMod(t *testing.T) {
tester = t; tester = t;
test_msg = "IntDivMod"; test_msg = "IntDivMod";
type T struct { x, y, q, r int }; type T struct { x, y, q, r int };
a := []T{ a := []T(
T{+8, +3, +2, +2}, T(+8, +3, +2, +2),
T{+8, -3, -2, +2}, T(+8, -3, -2, +2),
T{-8, +3, -3, +1}, T(-8, +3, -3, +1),
T{-8, -3, +3, +1}, T(-8, -3, +3, +1),
T{+1, +2, 0, +1}, T(+1, +2, 0, +1),
T{+1, -2, 0, +1}, T(+1, -2, 0, +1),
T{-1, +2, -1, +1}, T(-1, +2, -1, +1),
T{-1, -2, +1, +1}, T(-1, -2, +1, +1),
}; );
for i := uint(0); i < uint(len(a)); i++ { for i := uint(0); i < uint(len(a)); i++ {
e := &a[i]; e := &a[i];
x, y := bignum.Int(e.x).Mul(ip), bignum.Int(e.y).Mul(ip); x, y := bignum.Int(e.x).Mul(ip), bignum.Int(e.y).Mul(ip);

View file

@ -477,6 +477,6 @@ type BufReadWrite struct {
} }
func NewBufReadWrite(r *BufRead, w *BufWrite) *BufReadWrite { func NewBufReadWrite(r *BufRead, w *BufWrite) *BufReadWrite {
return &BufReadWrite{r, w} return &BufReadWrite(r, w)
} }

View file

@ -98,10 +98,10 @@ type readMaker struct {
name string; name string;
fn func([]byte) io.Read; fn func([]byte) io.Read;
} }
var readMakers = []readMaker { var readMakers = []readMaker (
readMaker{ "full", func(p []byte) io.Read { return newByteReader(p) } }, readMaker( "full", func(p []byte) io.Read { return newByteReader(p) } ),
readMaker{ "half", func(p []byte) io.Read { return newHalfByteReader(p) } }, readMaker( "half", func(p []byte) io.Read { return newHalfByteReader(p) } ),
} )
// Call ReadLineString (which ends up calling everything else) // Call ReadLineString (which ends up calling everything else)
// to accumulate the text of a file. // to accumulate the text of a file.
@ -157,21 +157,21 @@ type bufReader struct {
name string; name string;
fn func(*BufRead) string; fn func(*BufRead) string;
} }
var bufreaders = []bufReader { var bufreaders = []bufReader (
bufReader{ "1", func(b *BufRead) string { return reads(b, 1) } }, bufReader( "1", func(b *BufRead) string { return reads(b, 1) } ),
bufReader{ "2", func(b *BufRead) string { return reads(b, 2) } }, bufReader( "2", func(b *BufRead) string { return reads(b, 2) } ),
bufReader{ "3", func(b *BufRead) string { return reads(b, 3) } }, bufReader( "3", func(b *BufRead) string { return reads(b, 3) } ),
bufReader{ "4", func(b *BufRead) string { return reads(b, 4) } }, bufReader( "4", func(b *BufRead) string { return reads(b, 4) } ),
bufReader{ "5", func(b *BufRead) string { return reads(b, 5) } }, bufReader( "5", func(b *BufRead) string { return reads(b, 5) } ),
bufReader{ "7", func(b *BufRead) string { return reads(b, 7) } }, bufReader( "7", func(b *BufRead) string { return reads(b, 7) } ),
bufReader{ "bytes", readBytes }, bufReader( "bytes", readBytes ),
bufReader{ "lines", readLines }, bufReader( "lines", readLines ),
} )
var bufsizes = []int { var bufsizes = []int (
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
23, 32, 46, 64, 93, 128, 1024, 4096 23, 32, 46, 64, 93, 128, 1024, 4096
} )
func TestBufReadSimple(t *testing.T) { func TestBufReadSimple(t *testing.T) {
b := NewBufRead(newByteReader(io.StringBytes("hello world"))); b := NewBufRead(newByteReader(io.StringBytes("hello world")));
@ -281,10 +281,10 @@ type writeMaker struct {
func TestBufWrite(t *testing.T) { func TestBufWrite(t *testing.T) {
var data [8192]byte; var data [8192]byte;
var writers = []writeMaker { var writers = []writeMaker (
writeMaker{ "full", newByteWriter }, writeMaker( "full", newByteWriter ),
writeMaker{ "half", newHalfByteWriter }, writeMaker( "half", newHalfByteWriter ),
}; );
for i := 0; i < len(data); i++ { for i := 0; i < len(data); i++ {
data[i] = byte(' '+ i%('~'-' ')); data[i] = byte(' '+ i%('~'-' '));

View file

@ -112,7 +112,7 @@ type boolValue struct {
func newBoolValue(val bool, p *bool) *boolValue { func newBoolValue(val bool, p *bool) *boolValue {
*p = val; *p = val;
return &boolValue{p} return &boolValue(p)
} }
func (b *boolValue) set(val bool) { func (b *boolValue) set(val bool) {
@ -130,7 +130,7 @@ type intValue struct {
func newIntValue(val int, p *int) *intValue { func newIntValue(val int, p *int) *intValue {
*p = val; *p = val;
return &intValue{p} return &intValue(p)
} }
func (i *intValue) set(val int) { func (i *intValue) set(val int) {
@ -148,7 +148,7 @@ type int64Value struct {
func newInt64Value(val int64, p *int64) *int64Value { func newInt64Value(val int64, p *int64) *int64Value {
*p = val; *p = val;
return &int64Value{p} return &int64Value(p)
} }
func (i *int64Value) set(val int64) { func (i *int64Value) set(val int64) {
@ -166,7 +166,7 @@ type uintValue struct {
func newUintValue(val uint, p *uint) *uintValue { func newUintValue(val uint, p *uint) *uintValue {
*p = val; *p = val;
return &uintValue{p} return &uintValue(p)
} }
func (i *uintValue) set(val uint) { func (i *uintValue) set(val uint) {
@ -184,7 +184,7 @@ type uint64Value struct {
func newUint64Value(val uint64, p *uint64) *uint64Value { func newUint64Value(val uint64, p *uint64) *uint64Value {
*p = val; *p = val;
return &uint64Value{p} return &uint64Value(p)
} }
func (i *uint64Value) set(val uint64) { func (i *uint64Value) set(val uint64) {
@ -202,7 +202,7 @@ type stringValue struct {
func newStringValue(val string, p *string) *stringValue { func newStringValue(val string, p *string) *stringValue {
*p = val; *p = val;
return &stringValue{p} return &stringValue(p)
} }
func (s *stringValue) set(val string) { func (s *stringValue) set(val string) {
@ -232,7 +232,7 @@ type allFlags struct {
first_arg int; // 0 is the program name, 1 is first arg first_arg int; // 0 is the program name, 1 is first arg
} }
var flags *allFlags = &allFlags{make(map[string] *Flag), make(map[string] *Flag), 1} var flags *allFlags = &allFlags(make(map[string] *Flag), make(map[string] *Flag), 1)
func PrintDefaults() { func PrintDefaults() {
for k, f := range flags.formal { for k, f := range flags.formal {

View file

@ -29,127 +29,127 @@ type fmtTest struct {
const b32 uint32 = 1<<32 - 1 const b32 uint32 = 1<<32 - 1
const b64 uint64 = 1<<64 - 1 const b64 uint64 = 1<<64 - 1
var array = []int{1, 2, 3, 4, 5} var array = []int(1, 2, 3, 4, 5)
var fmttests = []fmtTest{ var fmttests = []fmtTest(
// basic string // basic string
fmtTest{ "%s", "abc", "abc" }, fmtTest( "%s", "abc", "abc" ),
fmtTest{ "%x", "abc", "616263" }, fmtTest( "%x", "abc", "616263" ),
fmtTest{ "%x", "xyz", "78797a" }, fmtTest( "%x", "xyz", "78797a" ),
fmtTest{ "%X", "xyz", "78797A" }, fmtTest( "%X", "xyz", "78797A" ),
fmtTest{ "%q", "abc", `"abc"` }, fmtTest( "%q", "abc", `"abc"` ),
// basic bytes // basic bytes
fmtTest{ "%s", io.StringBytes("abc"), "abc" }, fmtTest( "%s", io.StringBytes("abc"), "abc" ),
fmtTest{ "%x", io.StringBytes("abc"), "616263" }, fmtTest( "%x", io.StringBytes("abc"), "616263" ),
fmtTest{ "% x", io.StringBytes("abc"), "61 62 63" }, fmtTest( "% x", io.StringBytes("abc"), "61 62 63" ),
fmtTest{ "%x", io.StringBytes("xyz"), "78797a" }, fmtTest( "%x", io.StringBytes("xyz"), "78797a" ),
fmtTest{ "%X", io.StringBytes("xyz"), "78797A" }, fmtTest( "%X", io.StringBytes("xyz"), "78797A" ),
fmtTest{ "%q", io.StringBytes("abc"), `"abc"` }, fmtTest( "%q", io.StringBytes("abc"), `"abc"` ),
// escaped strings // escaped strings
fmtTest{ "%#q", `abc`, "`abc`" }, fmtTest( "%#q", `abc`, "`abc`" ),
fmtTest{ "%#q", `"`, "`\"`" }, fmtTest( "%#q", `"`, "`\"`" ),
fmtTest{ "1 %#q", `\n`, "1 `\\n`" }, fmtTest( "1 %#q", `\n`, "1 `\\n`" ),
fmtTest{ "2 %#q", "\n", `2 "\n"` }, fmtTest( "2 %#q", "\n", `2 "\n"` ),
fmtTest{ "%q", `"`, `"\""` }, fmtTest( "%q", `"`, `"\""` ),
fmtTest{ "%q", "\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"` }, fmtTest( "%q", "\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"` ),
fmtTest{ "%q", "abc\xffdef", `"abc\xffdef"` }, fmtTest( "%q", "abc\xffdef", `"abc\xffdef"` ),
fmtTest{ "%q", "\u263a", `"\u263a"` }, fmtTest( "%q", "\u263a", `"\u263a"` ),
fmtTest{ "%q", "\U0010ffff", `"\U0010ffff"` }, fmtTest( "%q", "\U0010ffff", `"\U0010ffff"` ),
// width // width
fmtTest{ "%5s", "abc", " abc" }, fmtTest( "%5s", "abc", " abc" ),
fmtTest{ "%-5s", "abc", "abc " }, fmtTest( "%-5s", "abc", "abc " ),
fmtTest{ "%05s", "abc", "00abc" }, fmtTest( "%05s", "abc", "00abc" ),
// integers // integers
fmtTest{ "%d", 12345, "12345" }, fmtTest( "%d", 12345, "12345" ),
fmtTest{ "%d", -12345, "-12345" }, fmtTest( "%d", -12345, "-12345" ),
fmtTest{ "%10d", 12345, " 12345" }, fmtTest( "%10d", 12345, " 12345" ),
fmtTest{ "%10d", -12345, " -12345" }, fmtTest( "%10d", -12345, " -12345" ),
fmtTest{ "%+10d", 12345, " +12345" }, fmtTest( "%+10d", 12345, " +12345" ),
fmtTest{ "%010d", 12345, "0000012345" }, fmtTest( "%010d", 12345, "0000012345" ),
fmtTest{ "%010d", -12345, "-000012345" }, fmtTest( "%010d", -12345, "-000012345" ),
fmtTest{ "%-10d", 12345, "12345 " }, fmtTest( "%-10d", 12345, "12345 " ),
fmtTest{ "%010.3d", 1, " 001" }, fmtTest( "%010.3d", 1, " 001" ),
fmtTest{ "%010.3d", -1, " -001" }, fmtTest( "%010.3d", -1, " -001" ),
fmtTest{ "%+d", 12345, "+12345" }, fmtTest( "%+d", 12345, "+12345" ),
fmtTest{ "%+d", -12345, "-12345" }, fmtTest( "%+d", -12345, "-12345" ),
fmtTest{ "% d", 12345, " 12345" }, fmtTest( "% d", 12345, " 12345" ),
fmtTest{ "% d", -12345, "-12345" }, fmtTest( "% d", -12345, "-12345" ),
// arrays // arrays
// TODO: when arrays work in interfaces, enable this line // TODO: when arrays work in interfaces, enable this line
// and delete the TestArrayPrinter routine below // and delete the TestArrayPrinter routine below
// fmtTest{ "%v", array, "[1 2 3 4 5]" }, // fmtTest{ "%v", array, "[1 2 3 4 5]" },
fmtTest{ "%v", &array, "&[1 2 3 4 5]" }, fmtTest( "%v", &array, "&[1 2 3 4 5]" ),
// old test/fmt_test.go // old test/fmt_test.go
fmtTest{ "%d", 1234, "1234" }, fmtTest( "%d", 1234, "1234" ),
fmtTest{ "%d", -1234, "-1234" }, fmtTest( "%d", -1234, "-1234" ),
fmtTest{ "%d", uint(1234), "1234" }, fmtTest( "%d", uint(1234), "1234" ),
fmtTest{ "%d", uint32(b32), "4294967295" }, fmtTest( "%d", uint32(b32), "4294967295" ),
fmtTest{ "%d", uint64(b64), "18446744073709551615" }, fmtTest( "%d", uint64(b64), "18446744073709551615" ),
fmtTest{ "%o", 01234, "1234" }, fmtTest( "%o", 01234, "1234" ),
fmtTest{ "%o", uint32(b32), "37777777777" }, fmtTest( "%o", uint32(b32), "37777777777" ),
fmtTest{ "%o", uint64(b64), "1777777777777777777777" }, fmtTest( "%o", uint64(b64), "1777777777777777777777" ),
fmtTest{ "%x", 0x1234abcd, "1234abcd" }, fmtTest( "%x", 0x1234abcd, "1234abcd" ),
fmtTest{ "%x", b32-0x1234567, "fedcba98" }, fmtTest( "%x", b32-0x1234567, "fedcba98" ),
fmtTest{ "%X", 0x1234abcd, "1234ABCD" }, fmtTest( "%X", 0x1234abcd, "1234ABCD" ),
fmtTest{ "%X", b32-0x1234567, "FEDCBA98" }, fmtTest( "%X", b32-0x1234567, "FEDCBA98" ),
fmtTest{ "%x", b64, "ffffffffffffffff" }, fmtTest( "%x", b64, "ffffffffffffffff" ),
fmtTest{ "%b", 7, "111" }, fmtTest( "%b", 7, "111" ),
fmtTest{ "%b", b64, "1111111111111111111111111111111111111111111111111111111111111111" }, fmtTest( "%b", b64, "1111111111111111111111111111111111111111111111111111111111111111" ),
fmtTest{ "%e", float64(1), "1.000000e+00" }, fmtTest( "%e", float64(1), "1.000000e+00" ),
fmtTest{ "%e", float64(1234.5678e3), "1.234568e+06" }, fmtTest( "%e", float64(1234.5678e3), "1.234568e+06" ),
fmtTest{ "%e", float64(1234.5678e-8), "1.234568e-05" }, fmtTest( "%e", float64(1234.5678e-8), "1.234568e-05" ),
fmtTest{ "%e", float64(-7), "-7.000000e+00" }, fmtTest( "%e", float64(-7), "-7.000000e+00" ),
fmtTest{ "%e", float64(-1e-9), "-1.000000e-09" }, fmtTest( "%e", float64(-1e-9), "-1.000000e-09" ),
fmtTest{ "%f", float64(1234.5678e3), "1234567.800000" }, fmtTest( "%f", float64(1234.5678e3), "1234567.800000" ),
fmtTest{ "%f", float64(1234.5678e-8), "0.000012" }, fmtTest( "%f", float64(1234.5678e-8), "0.000012" ),
fmtTest{ "%f", float64(-7), "-7.000000" }, fmtTest( "%f", float64(-7), "-7.000000" ),
fmtTest{ "%f", float64(-1e-9), "-0.000000" }, fmtTest( "%f", float64(-1e-9), "-0.000000" ),
fmtTest{ "%g", float64(1234.5678e3), "1.2345678e+06" }, fmtTest( "%g", float64(1234.5678e3), "1.2345678e+06" ),
fmtTest{ "%g", float32(1234.5678e3), "1.2345678e+06" }, fmtTest( "%g", float32(1234.5678e3), "1.2345678e+06" ),
fmtTest{ "%g", float64(1234.5678e-8), "1.2345678e-05" }, fmtTest( "%g", float64(1234.5678e-8), "1.2345678e-05" ),
fmtTest{ "%g", float64(-7), "-7" }, fmtTest( "%g", float64(-7), "-7" ),
fmtTest{ "%g", float64(-1e-9), "-1e-09", }, fmtTest( "%g", float64(-1e-9), "-1e-09", ),
fmtTest{ "%g", float32(-1e-9), "-1e-09" }, fmtTest( "%g", float32(-1e-9), "-1e-09" ),
fmtTest{ "%c", 'x', "x" }, fmtTest( "%c", 'x', "x" ),
fmtTest{ "%c", 0xe4, "ä" }, fmtTest( "%c", 0xe4, "ä" ),
fmtTest{ "%c", 0x672c, "本" }, fmtTest( "%c", 0x672c, "本" ),
fmtTest{ "%c", '日', "日" }, fmtTest( "%c", '日', "日" ),
fmtTest{ "%20.8d", 1234, " 00001234" }, fmtTest( "%20.8d", 1234, " 00001234" ),
fmtTest{ "%20.8d", -1234, " -00001234" }, fmtTest( "%20.8d", -1234, " -00001234" ),
fmtTest{ "%20d", 1234, " 1234" }, fmtTest( "%20d", 1234, " 1234" ),
fmtTest{ "%-20.8d", 1234, "00001234 " }, fmtTest( "%-20.8d", 1234, "00001234 " ),
fmtTest{ "%-20.8d", -1234, "-00001234 " }, fmtTest( "%-20.8d", -1234, "-00001234 " ),
fmtTest{ "%.20b", 7, "00000000000000000111" }, fmtTest( "%.20b", 7, "00000000000000000111" ),
fmtTest{ "%20.5s", "qwertyuiop", " qwert" }, fmtTest( "%20.5s", "qwertyuiop", " qwert" ),
fmtTest{ "%.5s", "qwertyuiop", "qwert" }, fmtTest( "%.5s", "qwertyuiop", "qwert" ),
fmtTest{ "%-20.5s", "qwertyuiop", "qwert " }, fmtTest( "%-20.5s", "qwertyuiop", "qwert " ),
fmtTest{ "%20c", 'x', " x" }, fmtTest( "%20c", 'x', " x" ),
fmtTest{ "%-20c", 'x', "x " }, fmtTest( "%-20c", 'x', "x " ),
fmtTest{ "%20.6e", 1.2345e3, " 1.234500e+03" }, fmtTest( "%20.6e", 1.2345e3, " 1.234500e+03" ),
fmtTest{ "%20.6e", 1.2345e-3, " 1.234500e-03" }, fmtTest( "%20.6e", 1.2345e-3, " 1.234500e-03" ),
fmtTest{ "%20e", 1.2345e3, " 1.234500e+03" }, fmtTest( "%20e", 1.2345e3, " 1.234500e+03" ),
fmtTest{ "%20e", 1.2345e-3, " 1.234500e-03" }, fmtTest( "%20e", 1.2345e-3, " 1.234500e-03" ),
fmtTest{ "%20.8e", 1.2345e3, " 1.23450000e+03" }, fmtTest( "%20.8e", 1.2345e3, " 1.23450000e+03" ),
fmtTest{ "%20f", float64(1.23456789e3), " 1234.567890" }, fmtTest( "%20f", float64(1.23456789e3), " 1234.567890" ),
fmtTest{ "%20f", float64(1.23456789e-3), " 0.001235" }, fmtTest( "%20f", float64(1.23456789e-3), " 0.001235" ),
fmtTest{ "%20f", float64(12345678901.23456789), " 12345678901.234568" }, fmtTest( "%20f", float64(12345678901.23456789), " 12345678901.234568" ),
fmtTest{ "%-20f", float64(1.23456789e3), "1234.567890 " }, fmtTest( "%-20f", float64(1.23456789e3), "1234.567890 " ),
fmtTest{ "%20.8f", float64(1.23456789e3), " 1234.56789000" }, fmtTest( "%20.8f", float64(1.23456789e3), " 1234.56789000" ),
fmtTest{ "%20.8f", float64(1.23456789e-3), " 0.00123457" }, fmtTest( "%20.8f", float64(1.23456789e-3), " 0.00123457" ),
fmtTest{ "%g", float64(1.23456789e3), "1234.56789" }, fmtTest( "%g", float64(1.23456789e3), "1234.56789" ),
fmtTest{ "%g", float64(1.23456789e-3), "0.00123456789" }, fmtTest( "%g", float64(1.23456789e-3), "0.00123456789" ),
fmtTest{ "%g", float64(1.23456789e20), "1.23456789e+20" }, fmtTest( "%g", float64(1.23456789e20), "1.23456789e+20" ),
fmtTest{ "%20e", math.Inf(1), " +Inf" }, fmtTest( "%20e", math.Inf(1), " +Inf" ),
fmtTest{ "%-20f", math.Inf(-1), "-Inf " }, fmtTest( "%-20f", math.Inf(-1), "-Inf " ),
fmtTest{ "%20g", math.NaN(), " NaN" }, fmtTest( "%20g", math.NaN(), " NaN" ),
} )
func TestSprintf(t *testing.T) { func TestSprintf(t *testing.T) {
for i := 0; i < len(fmttests); i++ { for i := 0; i < len(fmttests); i++ {
@ -190,20 +190,20 @@ type flagTest struct {
out string; out string;
} }
var flagtests = []flagTest { var flagtests = []flagTest (
flagTest{ "%a", "[%a]" }, flagTest( "%a", "[%a]" ),
flagTest{ "%-a", "[%-a]" }, flagTest( "%-a", "[%-a]" ),
flagTest{ "%+a", "[%+a]" }, flagTest( "%+a", "[%+a]" ),
flagTest{ "%#a", "[%#a]" }, flagTest( "%#a", "[%#a]" ),
flagTest{ "% a", "[% a]" }, flagTest( "% a", "[% a]" ),
flagTest{ "%0a", "[%0a]" }, flagTest( "%0a", "[%0a]" ),
flagTest{ "%1.2a", "[%1.2a]" }, flagTest( "%1.2a", "[%1.2a]" ),
flagTest{ "%-1.2a", "[%-1.2a]" }, flagTest( "%-1.2a", "[%-1.2a]" ),
flagTest{ "%+1.2a", "[%+1.2a]" }, flagTest( "%+1.2a", "[%+1.2a]" ),
flagTest{ "%-+1.2a", "[%+-1.2a]" }, flagTest( "%-+1.2a", "[%+-1.2a]" ),
flagTest{ "%-+1.2abc", "[%+-1.2a]bc" }, flagTest( "%-+1.2abc", "[%+-1.2a]bc" ),
flagTest{ "%-1.2abc", "[%-1.2a]bc" }, flagTest( "%-1.2abc", "[%-1.2a]bc" ),
} )
func TestFlagParser(t *testing.T) { func TestFlagParser(t *testing.T) {
var flagprinter flagPrinter; var flagprinter flagPrinter;
@ -229,10 +229,10 @@ func TestStructPrinter(t *testing.T) {
fmt string; fmt string;
out string; out string;
} }
var tests = []Test { var tests = []Test (
Test{ "%v", "{abc def 123}" }, Test( "%v", "{abc def 123}" ),
Test{ "%+v", "{a=abc b=def c=123}" }, Test( "%+v", "{a=abc b=def c=123}" ),
}; );
for i := 0; i < len(tests); i++ { for i := 0; i < len(tests); i++ {
tt := tests[i]; tt := tests[i];
out := fmt.Sprintf(tt.fmt, s); out := fmt.Sprintf(tt.fmt, s);
@ -243,7 +243,7 @@ func TestStructPrinter(t *testing.T) {
} }
func TestArrayPrinter(t *testing.T) { func TestArrayPrinter(t *testing.T) {
a := []int{1, 2, 3, 4, 5}; a := []int(1, 2, 3, 4, 5);
want := "[1 2 3 4 5]"; want := "[1 2 3 4 5]";
out := fmt.Sprintf("%v", a); out := fmt.Sprintf("%v", a);
if out != want { if out != want {

View file

@ -25,7 +25,7 @@ const (
) )
func NewDigest() *Digest { func NewDigest() *Digest {
return &Digest{1, 0, 0}; return &Digest(1, 0, 0);
} }
func (d *Digest) Write(p []byte) (nn int, err *os.Error) { func (d *Digest) Write(p []byte) (nn int, err *os.Error) {

View file

@ -15,39 +15,39 @@ type _Adler32Test struct {
in string; in string;
} }
var golden = []_Adler32Test { var golden = []_Adler32Test (
_Adler32Test{ 0x1, "" }, _Adler32Test( 0x1, "" ),
_Adler32Test{ 0x620062, "a" }, _Adler32Test( 0x620062, "a" ),
_Adler32Test{ 0x12600c4, "ab" }, _Adler32Test( 0x12600c4, "ab" ),
_Adler32Test{ 0x24d0127, "abc" }, _Adler32Test( 0x24d0127, "abc" ),
_Adler32Test{ 0x3d8018b, "abcd" }, _Adler32Test( 0x3d8018b, "abcd" ),
_Adler32Test{ 0x5c801f0, "abcde" }, _Adler32Test( 0x5c801f0, "abcde" ),
_Adler32Test{ 0x81e0256, "abcdef" }, _Adler32Test( 0x81e0256, "abcdef" ),
_Adler32Test{ 0xadb02bd, "abcdefg" }, _Adler32Test( 0xadb02bd, "abcdefg" ),
_Adler32Test{ 0xe000325, "abcdefgh" }, _Adler32Test( 0xe000325, "abcdefgh" ),
_Adler32Test{ 0x118e038e, "abcdefghi" }, _Adler32Test( 0x118e038e, "abcdefghi" ),
_Adler32Test{ 0x158603f8, "abcdefghij" }, _Adler32Test( 0x158603f8, "abcdefghij" ),
_Adler32Test{ 0x3f090f02, "Discard medicine more than two years old." }, _Adler32Test( 0x3f090f02, "Discard medicine more than two years old." ),
_Adler32Test{ 0x46d81477, "He who has a shady past knows that nice guys finish last." }, _Adler32Test( 0x46d81477, "He who has a shady past knows that nice guys finish last." ),
_Adler32Test{ 0x40ee0ee1, "I wouldn't marry him with a ten foot pole." }, _Adler32Test( 0x40ee0ee1, "I wouldn't marry him with a ten foot pole." ),
_Adler32Test{ 0x16661315, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" }, _Adler32Test( 0x16661315, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" ),
_Adler32Test{ 0x5b2e1480, "The days of the digital watch are numbered. -Tom Stoppard" }, _Adler32Test( 0x5b2e1480, "The days of the digital watch are numbered. -Tom Stoppard" ),
_Adler32Test{ 0x8c3c09ea, "Nepal premier won't resign." }, _Adler32Test( 0x8c3c09ea, "Nepal premier won't resign." ),
_Adler32Test{ 0x45ac18fd, "For every action there is an equal and opposite government program." }, _Adler32Test( 0x45ac18fd, "For every action there is an equal and opposite government program." ),
_Adler32Test{ 0x53c61462, "His money is twice tainted: 'taint yours and 'taint mine." }, _Adler32Test( 0x53c61462, "His money is twice tainted: 'taint yours and 'taint mine." ),
_Adler32Test{ 0x7e511e63, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" }, _Adler32Test( 0x7e511e63, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" ),
_Adler32Test{ 0xe4801a6a, "It's a tiny change to the code and not completely disgusting. - Bob Manchek" }, _Adler32Test( 0xe4801a6a, "It's a tiny change to the code and not completely disgusting. - Bob Manchek" ),
_Adler32Test{ 0x61b507df, "size: a.out: bad magic" }, _Adler32Test( 0x61b507df, "size: a.out: bad magic" ),
_Adler32Test{ 0xb8631171, "The major problem is with sendmail. -Mark Horton" }, _Adler32Test( 0xb8631171, "The major problem is with sendmail. -Mark Horton" ),
_Adler32Test{ 0x8b5e1904, "Give me a rock, paper and scissors and I will move the world. CCFestoon" }, _Adler32Test( 0x8b5e1904, "Give me a rock, paper and scissors and I will move the world. CCFestoon" ),
_Adler32Test{ 0x7cc6102b, "If the enemy is within range, then so are you." }, _Adler32Test( 0x7cc6102b, "If the enemy is within range, then so are you." ),
_Adler32Test{ 0x700318e7, "It's well we cannot hear the screams/That we create in others' dreams." }, _Adler32Test( 0x700318e7, "It's well we cannot hear the screams/That we create in others' dreams." ),
_Adler32Test{ 0x1e601747, "You remind me of a TV show, but that's all right: I watch it anyway." }, _Adler32Test( 0x1e601747, "You remind me of a TV show, but that's all right: I watch it anyway." ),
_Adler32Test{ 0xb55b0b09, "C is as portable as Stonehedge!!" }, _Adler32Test( 0xb55b0b09, "C is as portable as Stonehedge!!" ),
_Adler32Test{ 0x39111dd0, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" }, _Adler32Test( 0x39111dd0, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" ),
_Adler32Test{ 0x91dd304f, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" }, _Adler32Test( 0x91dd304f, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" ),
_Adler32Test{ 0x2e5d1316, "How can you write a big system without C++? -Paul Glick" }, _Adler32Test( 0x2e5d1316, "How can you write a big system without C++? -Paul Glick" ),
} )
func TestGolden(t *testing.T) { func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ { for i := 0; i < len(golden); i++ {

View file

@ -52,7 +52,7 @@ type Digest struct {
} }
func NewDigest(tab Table) *Digest { func NewDigest(tab Table) *Digest {
return &Digest{0, tab}; return &Digest(0, tab);
} }
func NewIEEEDigest() *Digest { func NewIEEEDigest() *Digest {

View file

@ -15,39 +15,39 @@ type _Crc32Test struct {
in string; in string;
} }
var golden = []_Crc32Test { var golden = []_Crc32Test (
_Crc32Test{ 0x0, "" }, _Crc32Test( 0x0, "" ),
_Crc32Test{ 0xe8b7be43, "a" }, _Crc32Test( 0xe8b7be43, "a" ),
_Crc32Test{ 0x9e83486d, "ab" }, _Crc32Test( 0x9e83486d, "ab" ),
_Crc32Test{ 0x352441c2, "abc" }, _Crc32Test( 0x352441c2, "abc" ),
_Crc32Test{ 0xed82cd11, "abcd" }, _Crc32Test( 0xed82cd11, "abcd" ),
_Crc32Test{ 0x8587d865, "abcde" }, _Crc32Test( 0x8587d865, "abcde" ),
_Crc32Test{ 0x4b8e39ef, "abcdef" }, _Crc32Test( 0x4b8e39ef, "abcdef" ),
_Crc32Test{ 0x312a6aa6, "abcdefg" }, _Crc32Test( 0x312a6aa6, "abcdefg" ),
_Crc32Test{ 0xaeef2a50, "abcdefgh" }, _Crc32Test( 0xaeef2a50, "abcdefgh" ),
_Crc32Test{ 0x8da988af, "abcdefghi" }, _Crc32Test( 0x8da988af, "abcdefghi" ),
_Crc32Test{ 0x3981703a, "abcdefghij" }, _Crc32Test( 0x3981703a, "abcdefghij" ),
_Crc32Test{ 0x6b9cdfe7, "Discard medicine more than two years old." }, _Crc32Test( 0x6b9cdfe7, "Discard medicine more than two years old." ),
_Crc32Test{ 0xc90ef73f, "He who has a shady past knows that nice guys finish last." }, _Crc32Test( 0xc90ef73f, "He who has a shady past knows that nice guys finish last." ),
_Crc32Test{ 0xb902341f, "I wouldn't marry him with a ten foot pole." }, _Crc32Test( 0xb902341f, "I wouldn't marry him with a ten foot pole." ),
_Crc32Test{ 0x42080e8, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" }, _Crc32Test( 0x42080e8, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" ),
_Crc32Test{ 0x154c6d11, "The days of the digital watch are numbered. -Tom Stoppard" }, _Crc32Test( 0x154c6d11, "The days of the digital watch are numbered. -Tom Stoppard" ),
_Crc32Test{ 0x4c418325, "Nepal premier won't resign." }, _Crc32Test( 0x4c418325, "Nepal premier won't resign." ),
_Crc32Test{ 0x33955150, "For every action there is an equal and opposite government program." }, _Crc32Test( 0x33955150, "For every action there is an equal and opposite government program." ),
_Crc32Test{ 0x26216a4b, "His money is twice tainted: 'taint yours and 'taint mine." }, _Crc32Test( 0x26216a4b, "His money is twice tainted: 'taint yours and 'taint mine." ),
_Crc32Test{ 0x1abbe45e, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" }, _Crc32Test( 0x1abbe45e, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" ),
_Crc32Test{ 0xc89a94f7, "It's a tiny change to the code and not completely disgusting. - Bob Manchek" }, _Crc32Test( 0xc89a94f7, "It's a tiny change to the code and not completely disgusting. - Bob Manchek" ),
_Crc32Test{ 0xab3abe14, "size: a.out: bad magic" }, _Crc32Test( 0xab3abe14, "size: a.out: bad magic" ),
_Crc32Test{ 0xbab102b6, "The major problem is with sendmail. -Mark Horton" }, _Crc32Test( 0xbab102b6, "The major problem is with sendmail. -Mark Horton" ),
_Crc32Test{ 0x999149d7, "Give me a rock, paper and scissors and I will move the world. CCFestoon" }, _Crc32Test( 0x999149d7, "Give me a rock, paper and scissors and I will move the world. CCFestoon" ),
_Crc32Test{ 0x6d52a33c, "If the enemy is within range, then so are you." }, _Crc32Test( 0x6d52a33c, "If the enemy is within range, then so are you." ),
_Crc32Test{ 0x90631e8d, "It's well we cannot hear the screams/That we create in others' dreams." }, _Crc32Test( 0x90631e8d, "It's well we cannot hear the screams/That we create in others' dreams." ),
_Crc32Test{ 0x78309130, "You remind me of a TV show, but that's all right: I watch it anyway." }, _Crc32Test( 0x78309130, "You remind me of a TV show, but that's all right: I watch it anyway." ),
_Crc32Test{ 0x7d0a377f, "C is as portable as Stonehedge!!" }, _Crc32Test( 0x7d0a377f, "C is as portable as Stonehedge!!" ),
_Crc32Test{ 0x8c79fd79, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" }, _Crc32Test( 0x8c79fd79, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" ),
_Crc32Test{ 0xa20b7167, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" }, _Crc32Test( 0xa20b7167, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" ),
_Crc32Test{ 0x8e0bb443, "How can you write a big system without C++? -Paul Glick" }, _Crc32Test( 0x8e0bb443, "How can you write a big system without C++? -Paul Glick" ),
} )
func TestGolden(t *testing.T) { func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ { for i := 0; i < len(golden); i++ {

View file

@ -16,39 +16,39 @@ type md5Test struct {
in string; in string;
} }
var golden = []md5Test { var golden = []md5Test (
md5Test{ "d41d8cd98f00b204e9800998ecf8427e", "" }, md5Test( "d41d8cd98f00b204e9800998ecf8427e", "" ),
md5Test{ "0cc175b9c0f1b6a831c399e269772661", "a" }, md5Test( "0cc175b9c0f1b6a831c399e269772661", "a" ),
md5Test{ "187ef4436122d1cc2f40dc2b92f0eba0", "ab" }, md5Test( "187ef4436122d1cc2f40dc2b92f0eba0", "ab" ),
md5Test{ "900150983cd24fb0d6963f7d28e17f72", "abc" }, md5Test( "900150983cd24fb0d6963f7d28e17f72", "abc" ),
md5Test{ "e2fc714c4727ee9395f324cd2e7f331f", "abcd" }, md5Test( "e2fc714c4727ee9395f324cd2e7f331f", "abcd" ),
md5Test{ "ab56b4d92b40713acc5af89985d4b786", "abcde" }, md5Test( "ab56b4d92b40713acc5af89985d4b786", "abcde" ),
md5Test{ "e80b5017098950fc58aad83c8c14978e", "abcdef" }, md5Test( "e80b5017098950fc58aad83c8c14978e", "abcdef" ),
md5Test{ "7ac66c0f148de9519b8bd264312c4d64", "abcdefg" }, md5Test( "7ac66c0f148de9519b8bd264312c4d64", "abcdefg" ),
md5Test{ "e8dc4081b13434b45189a720b77b6818", "abcdefgh" }, md5Test( "e8dc4081b13434b45189a720b77b6818", "abcdefgh" ),
md5Test{ "8aa99b1f439ff71293e95357bac6fd94", "abcdefghi" }, md5Test( "8aa99b1f439ff71293e95357bac6fd94", "abcdefghi" ),
md5Test{ "a925576942e94b2ef57a066101b48876", "abcdefghij" }, md5Test( "a925576942e94b2ef57a066101b48876", "abcdefghij" ),
md5Test{ "d747fc1719c7eacb84058196cfe56d57", "Discard medicine more than two years old." }, md5Test( "d747fc1719c7eacb84058196cfe56d57", "Discard medicine more than two years old." ),
md5Test{ "bff2dcb37ef3a44ba43ab144768ca837", "He who has a shady past knows that nice guys finish last." }, md5Test( "bff2dcb37ef3a44ba43ab144768ca837", "He who has a shady past knows that nice guys finish last." ),
md5Test{ "0441015ecb54a7342d017ed1bcfdbea5", "I wouldn't marry him with a ten foot pole." }, md5Test( "0441015ecb54a7342d017ed1bcfdbea5", "I wouldn't marry him with a ten foot pole." ),
md5Test{ "9e3cac8e9e9757a60c3ea391130d3689", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" }, md5Test( "9e3cac8e9e9757a60c3ea391130d3689", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" ),
md5Test{ "a0f04459b031f916a59a35cc482dc039", "The days of the digital watch are numbered. -Tom Stoppard" }, md5Test( "a0f04459b031f916a59a35cc482dc039", "The days of the digital watch are numbered. -Tom Stoppard" ),
md5Test{ "e7a48e0fe884faf31475d2a04b1362cc", "Nepal premier won't resign." }, md5Test( "e7a48e0fe884faf31475d2a04b1362cc", "Nepal premier won't resign." ),
md5Test{ "637d2fe925c07c113800509964fb0e06", "For every action there is an equal and opposite government program." }, md5Test( "637d2fe925c07c113800509964fb0e06", "For every action there is an equal and opposite government program." ),
md5Test{ "834a8d18d5c6562119cf4c7f5086cb71", "His money is twice tainted: 'taint yours and 'taint mine." }, md5Test( "834a8d18d5c6562119cf4c7f5086cb71", "His money is twice tainted: 'taint yours and 'taint mine." ),
md5Test{ "de3a4d2fd6c73ec2db2abad23b444281", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" }, md5Test( "de3a4d2fd6c73ec2db2abad23b444281", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" ),
md5Test{ "acf203f997e2cf74ea3aff86985aefaf", "It's a tiny change to the code and not completely disgusting. - Bob Manchek" }, md5Test( "acf203f997e2cf74ea3aff86985aefaf", "It's a tiny change to the code and not completely disgusting. - Bob Manchek" ),
md5Test{ "e1c1384cb4d2221dfdd7c795a4222c9a", "size: a.out: bad magic" }, md5Test( "e1c1384cb4d2221dfdd7c795a4222c9a", "size: a.out: bad magic" ),
md5Test{ "c90f3ddecc54f34228c063d7525bf644", "The major problem is with sendmail. -Mark Horton" }, md5Test( "c90f3ddecc54f34228c063d7525bf644", "The major problem is with sendmail. -Mark Horton" ),
md5Test{ "cdf7ab6c1fd49bd9933c43f3ea5af185", "Give me a rock, paper and scissors and I will move the world. CCFestoon" }, md5Test( "cdf7ab6c1fd49bd9933c43f3ea5af185", "Give me a rock, paper and scissors and I will move the world. CCFestoon" ),
md5Test{ "83bc85234942fc883c063cbd7f0ad5d0", "If the enemy is within range, then so are you." }, md5Test( "83bc85234942fc883c063cbd7f0ad5d0", "If the enemy is within range, then so are you." ),
md5Test{ "277cbe255686b48dd7e8f389394d9299", "It's well we cannot hear the screams/That we create in others' dreams." }, md5Test( "277cbe255686b48dd7e8f389394d9299", "It's well we cannot hear the screams/That we create in others' dreams." ),
md5Test{ "fd3fb0a7ffb8af16603f3d3af98f8e1f", "You remind me of a TV show, but that's all right: I watch it anyway." }, md5Test( "fd3fb0a7ffb8af16603f3d3af98f8e1f", "You remind me of a TV show, but that's all right: I watch it anyway." ),
md5Test{ "469b13a78ebf297ecda64d4723655154", "C is as portable as Stonehedge!!" }, md5Test( "469b13a78ebf297ecda64d4723655154", "C is as portable as Stonehedge!!" ),
md5Test{ "63eb3a2f466410104731c4b037600110", "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" }, md5Test( "63eb3a2f466410104731c4b037600110", "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" ),
md5Test{ "72c2ed7592debca1c90fc0100f931a2f", "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" }, md5Test( "72c2ed7592debca1c90fc0100f931a2f", "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" ),
md5Test{ "132f7619d33b523b1d9e5bd8e0928355", "How can you write a big system without C++? -Paul Glick" }, md5Test( "132f7619d33b523b1d9e5bd8e0928355", "How can you write a big system without C++? -Paul Glick" ),
} )
func TestGolden(t *testing.T) { func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ { for i := 0; i < len(golden); i++ {

View file

@ -11,7 +11,7 @@ package md5
import "md5" import "md5"
// table[i] = int((1<<32) * abs(sin(i+1 radians))). // table[i] = int((1<<32) * abs(sin(i+1 radians))).
var table = []uint32 { var table = []uint32 (
// round 1 // round 1
0xd76aa478, 0xd76aa478,
0xe8c7b756, 0xe8c7b756,
@ -83,12 +83,12 @@ var table = []uint32 {
0xbd3af235, 0xbd3af235,
0x2ad7d2bb, 0x2ad7d2bb,
0xeb86d391, 0xeb86d391,
} )
var shift1 = []uint { 7, 12, 17, 22 }; var shift1 = []uint ( 7, 12, 17, 22 );
var shift2 = []uint { 5, 9, 14, 20 }; var shift2 = []uint ( 5, 9, 14, 20 );
var shift3 = []uint { 4, 11, 16, 23 }; var shift3 = []uint ( 4, 11, 16, 23 );
var shift4 = []uint { 6, 10, 15, 21 }; var shift4 = []uint ( 6, 10, 15, 21 );
func _Block(dig *Digest, p []byte) int { func _Block(dig *Digest, p []byte) int {
a := dig.s[0]; a := dig.s[0];

View file

@ -18,39 +18,39 @@ type sha1Test struct {
in string; in string;
} }
var golden = []sha1Test { var golden = []sha1Test (
sha1Test{ "da39a3ee5e6b4b0d3255bfef95601890afd80709", "" }, sha1Test( "da39a3ee5e6b4b0d3255bfef95601890afd80709", "" ),
sha1Test{ "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a" }, sha1Test( "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a" ),
sha1Test{ "da23614e02469a0d7c7bd1bdab5c9c474b1904dc", "ab" }, sha1Test( "da23614e02469a0d7c7bd1bdab5c9c474b1904dc", "ab" ),
sha1Test{ "a9993e364706816aba3e25717850c26c9cd0d89d", "abc" }, sha1Test( "a9993e364706816aba3e25717850c26c9cd0d89d", "abc" ),
sha1Test{ "81fe8bfe87576c3ecb22426f8e57847382917acf", "abcd" }, sha1Test( "81fe8bfe87576c3ecb22426f8e57847382917acf", "abcd" ),
sha1Test{ "03de6c570bfe24bfc328ccd7ca46b76eadaf4334", "abcde" }, sha1Test( "03de6c570bfe24bfc328ccd7ca46b76eadaf4334", "abcde" ),
sha1Test{ "1f8ac10f23c5b5bc1167bda84b833e5c057a77d2", "abcdef" }, sha1Test( "1f8ac10f23c5b5bc1167bda84b833e5c057a77d2", "abcdef" ),
sha1Test{ "2fb5e13419fc89246865e7a324f476ec624e8740", "abcdefg" }, sha1Test( "2fb5e13419fc89246865e7a324f476ec624e8740", "abcdefg" ),
sha1Test{ "425af12a0743502b322e93a015bcf868e324d56a", "abcdefgh" }, sha1Test( "425af12a0743502b322e93a015bcf868e324d56a", "abcdefgh" ),
sha1Test{ "c63b19f1e4c8b5f76b25c49b8b87f57d8e4872a1", "abcdefghi" }, sha1Test( "c63b19f1e4c8b5f76b25c49b8b87f57d8e4872a1", "abcdefghi" ),
sha1Test{ "d68c19a0a345b7eab78d5e11e991c026ec60db63", "abcdefghij" }, sha1Test( "d68c19a0a345b7eab78d5e11e991c026ec60db63", "abcdefghij" ),
sha1Test{ "ebf81ddcbe5bf13aaabdc4d65354fdf2044f38a7", "Discard medicine more than two years old." }, sha1Test( "ebf81ddcbe5bf13aaabdc4d65354fdf2044f38a7", "Discard medicine more than two years old." ),
sha1Test{ "e5dea09392dd886ca63531aaa00571dc07554bb6", "He who has a shady past knows that nice guys finish last." }, sha1Test( "e5dea09392dd886ca63531aaa00571dc07554bb6", "He who has a shady past knows that nice guys finish last." ),
sha1Test{ "45988f7234467b94e3e9494434c96ee3609d8f8f", "I wouldn't marry him with a ten foot pole." }, sha1Test( "45988f7234467b94e3e9494434c96ee3609d8f8f", "I wouldn't marry him with a ten foot pole." ),
sha1Test{ "55dee037eb7460d5a692d1ce11330b260e40c988", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" }, sha1Test( "55dee037eb7460d5a692d1ce11330b260e40c988", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave" ),
sha1Test{ "b7bc5fb91080c7de6b582ea281f8a396d7c0aee8", "The days of the digital watch are numbered. -Tom Stoppard" }, sha1Test( "b7bc5fb91080c7de6b582ea281f8a396d7c0aee8", "The days of the digital watch are numbered. -Tom Stoppard" ),
sha1Test{ "c3aed9358f7c77f523afe86135f06b95b3999797", "Nepal premier won't resign." }, sha1Test( "c3aed9358f7c77f523afe86135f06b95b3999797", "Nepal premier won't resign." ),
sha1Test{ "6e29d302bf6e3a5e4305ff318d983197d6906bb9", "For every action there is an equal and opposite government program." }, sha1Test( "6e29d302bf6e3a5e4305ff318d983197d6906bb9", "For every action there is an equal and opposite government program." ),
sha1Test{ "597f6a540010f94c15d71806a99a2c8710e747bd", "His money is twice tainted: 'taint yours and 'taint mine." }, sha1Test( "597f6a540010f94c15d71806a99a2c8710e747bd", "His money is twice tainted: 'taint yours and 'taint mine." ),
sha1Test{ "6859733b2590a8a091cecf50086febc5ceef1e80", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" }, sha1Test( "6859733b2590a8a091cecf50086febc5ceef1e80", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977" ),
sha1Test{ "514b2630ec089b8aee18795fc0cf1f4860cdacad", "It's a tiny change to the code and not completely disgusting. - Bob Manchek" }, sha1Test( "514b2630ec089b8aee18795fc0cf1f4860cdacad", "It's a tiny change to the code and not completely disgusting. - Bob Manchek" ),
sha1Test{ "c5ca0d4a7b6676fc7aa72caa41cc3d5df567ed69", "size: a.out: bad magic" }, sha1Test( "c5ca0d4a7b6676fc7aa72caa41cc3d5df567ed69", "size: a.out: bad magic" ),
sha1Test{ "74c51fa9a04eadc8c1bbeaa7fc442f834b90a00a", "The major problem is with sendmail. -Mark Horton" }, sha1Test( "74c51fa9a04eadc8c1bbeaa7fc442f834b90a00a", "The major problem is with sendmail. -Mark Horton" ),
sha1Test{ "0b4c4ce5f52c3ad2821852a8dc00217fa18b8b66", "Give me a rock, paper and scissors and I will move the world. CCFestoon" }, sha1Test( "0b4c4ce5f52c3ad2821852a8dc00217fa18b8b66", "Give me a rock, paper and scissors and I will move the world. CCFestoon" ),
sha1Test{ "3ae7937dd790315beb0f48330e8642237c61550a", "If the enemy is within range, then so are you." }, sha1Test( "3ae7937dd790315beb0f48330e8642237c61550a", "If the enemy is within range, then so are you." ),
sha1Test{ "410a2b296df92b9a47412b13281df8f830a9f44b", "It's well we cannot hear the screams/That we create in others' dreams." }, sha1Test( "410a2b296df92b9a47412b13281df8f830a9f44b", "It's well we cannot hear the screams/That we create in others' dreams." ),
sha1Test{ "841e7c85ca1adcddbdd0187f1289acb5c642f7f5", "You remind me of a TV show, but that's all right: I watch it anyway." }, sha1Test( "841e7c85ca1adcddbdd0187f1289acb5c642f7f5", "You remind me of a TV show, but that's all right: I watch it anyway." ),
sha1Test{ "163173b825d03b952601376b25212df66763e1db", "C is as portable as Stonehedge!!" }, sha1Test( "163173b825d03b952601376b25212df66763e1db", "C is as portable as Stonehedge!!" ),
sha1Test{ "32b0377f2687eb88e22106f133c586ab314d5279", "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" }, sha1Test( "32b0377f2687eb88e22106f133c586ab314d5279", "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley" ),
sha1Test{ "0885aaf99b569542fd165fa44e322718f4a984e0", "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" }, sha1Test( "0885aaf99b569542fd165fa44e322718f4a984e0", "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule" ),
sha1Test{ "6627d6904d71420b0bf3886ab629623538689f45", "How can you write a big system without C++? -Paul Glick" }, sha1Test( "6627d6904d71420b0bf3886ab629623538689f45", "How can you write a big system without C++? -Paul Glick" ),
} )
func TestGolden(t *testing.T) { func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ { for i := 0; i < len(golden); i++ {

View file

@ -247,7 +247,7 @@ func (h *redirectHandler) ServeHTTP(c *Conn, req *Request) {
} }
func RedirectHandler(to string) Handler { func RedirectHandler(to string) Handler {
return &redirectHandler{to}; return &redirectHandler(to);
} }
// Path-based HTTP request multiplexer. // Path-based HTTP request multiplexer.
@ -265,7 +265,7 @@ type ServeMux struct {
} }
func NewServeMux() *ServeMux { func NewServeMux() *ServeMux {
return &ServeMux{make(map[string] Handler)}; return &ServeMux(make(map[string] Handler));
} }
var DefaultServeMux = NewServeMux(); var DefaultServeMux = NewServeMux();

View file

@ -53,7 +53,7 @@ const (
StatusHTTPVersionNotSupported = 505; StatusHTTPVersionNotSupported = 505;
) )
var statusText = map[int]string { var statusText = map[int]string (
StatusContinue: "Continue", StatusContinue: "Continue",
StatusSwitchingProtocols: "Switching Protocols", StatusSwitchingProtocols: "Switching Protocols",
@ -98,5 +98,5 @@ var statusText = map[int]string {
StatusServiceUnavailable: "Service Unavailable", StatusServiceUnavailable: "Service Unavailable",
StatusGatewayTimeout: "Gateway Timeout", StatusGatewayTimeout: "Gateway Timeout",
StatusHTTPVersionNotSupported: "HTTP Version Not Supported", StatusHTTPVersionNotSupported: "HTTP Version Not Supported",
} )

View file

@ -83,7 +83,7 @@ func Make_FullReader(fd Read) Read {
// already a _FullRead // already a _FullRead
return fd return fd
} }
return &_FullRead{fd} return &_FullRead(fd)
} }
// Copies n bytes (or until EOF is reached) from src to dst. // Copies n bytes (or until EOF is reached) from src to dst.

View file

@ -45,7 +45,7 @@ func JsonToString(j Json) string {
} }
type _Null struct { } type _Null struct { }
var Null Json = &_Null{} var Null Json = &_Null()
func (*_Null) Kind() int { return NullKind } func (*_Null) Kind() int { return NullKind }
func (*_Null) String() string { return "null" } func (*_Null) String() string { return "null" }
func (*_Null) Number() float64 { return 0 } func (*_Null) Number() float64 { return 0 }
@ -240,7 +240,7 @@ func (b *_JsonBuilder) Get() Json {
} }
func (b *_JsonBuilder) Float64(f float64) { func (b *_JsonBuilder) Float64(f float64) {
b.Put(&_Number{f, _Null{}}) b.Put(&_Number(f, _Null()))
} }
func (b *_JsonBuilder) Int64(i int64) { func (b *_JsonBuilder) Int64(i int64) {
@ -252,7 +252,7 @@ func (b *_JsonBuilder) Uint64(i uint64) {
} }
func (b *_JsonBuilder) Bool(tf bool) { func (b *_JsonBuilder) Bool(tf bool) {
b.Put(&_Bool{tf, _Null{}}) b.Put(&_Bool(tf, _Null()))
} }
func (b *_JsonBuilder) Null() { func (b *_JsonBuilder) Null() {
@ -260,16 +260,16 @@ func (b *_JsonBuilder) Null() {
} }
func (b *_JsonBuilder) String(s string) { func (b *_JsonBuilder) String(s string) {
b.Put(&_String{s, _Null{}}) b.Put(&_String(s, _Null()))
} }
func (b *_JsonBuilder) Array() { func (b *_JsonBuilder) Array() {
b.Put(&_Array{array.New(0), _Null{}}) b.Put(&_Array(array.New(0), _Null()))
} }
func (b *_JsonBuilder) Map() { func (b *_JsonBuilder) Map() {
b.Put(&_Map{make(map[string]Json), _Null{}}) b.Put(&_Map(make(map[string]Json), _Null()))
} }
func (b *_JsonBuilder) Elem(i int) Builder { func (b *_JsonBuilder) Elem(i int) Builder {

View file

@ -9,7 +9,7 @@ import (
"testing"; "testing";
) )
var jsontests = []string { var jsontests = []string (
`null`, `null`,
`true`, `true`,
`false`, `false`,
@ -22,7 +22,7 @@ var jsontests = []string {
`[1,2,"abc",null,true,false]`, `[1,2,"abc",null,true,false]`,
`{}`, `{}`,
`{"a":1}`, `{"a":1}`,
} )
func TestJson(t *testing.T) { func TestJson(t *testing.T) {
for i := 0; i < len(jsontests); i++ { for i := 0; i < len(jsontests); i++ {

View file

@ -163,7 +163,7 @@ func (b *_StructBuilder) Elem(i int) Builder {
av.SetLen(i+1); av.SetLen(i+1);
} }
if i < av.Len() { if i < av.Len() {
return &_StructBuilder{ av.Elem(i) } return &_StructBuilder( av.Elem(i) )
} }
} }
return nobuilder return nobuilder
@ -195,7 +195,7 @@ func (b *_StructBuilder) Key(k string) Builder {
for i := 0; i < t.Len(); i++ { for i := 0; i < t.Len(); i++ {
name, typ, tag, off := t.Field(i); name, typ, tag, off := t.Field(i);
if k == name { if k == name {
return &_StructBuilder{ sv.Field(i) } return &_StructBuilder( sv.Field(i) )
} }
} }
} }
@ -205,7 +205,7 @@ func (b *_StructBuilder) Key(k string) Builder {
func Unmarshal(s string, val interface{}) (ok bool, errtok string) { func Unmarshal(s string, val interface{}) (ok bool, errtok string) {
var errindx int; var errindx int;
var val1 interface{}; var val1 interface{};
b := &_StructBuilder{ reflect.NewValue(val) }; b := &_StructBuilder( reflect.NewValue(val) );
ok, errindx, errtok = Parse(s, b); ok, errindx, errtok = Parse(s, b);
if !ok { if !ok {
return false, errtok return false, errtok

View file

@ -43,7 +43,7 @@ type Logger struct {
} }
func NewLogger(out0, out1 io.Write, prefix string, flag int) *Logger { func NewLogger(out0, out1 io.Write, prefix string, flag int) *Logger {
return &Logger{out0, out1, prefix, flag} return &Logger(out0, out1, prefix, flag)
} }
var ( var (

View file

@ -29,21 +29,21 @@ type tester struct {
pattern string; // regexp that log output must match; we add ^ and expected_text$ always pattern string; // regexp that log output must match; we add ^ and expected_text$ always
} }
var tests = []tester { var tests = []tester (
// individual pieces: // individual pieces:
tester{ 0, "", "" }, tester( 0, "", "" ),
tester{ 0, "XXX", "XXX" }, tester( 0, "XXX", "XXX" ),
tester{ Lok|Ldate, "", Rdate+" " }, tester( Lok|Ldate, "", Rdate+" " ),
tester{ Lok|Ltime, "", Rtime+" " }, tester( Lok|Ltime, "", Rtime+" " ),
tester{ Lok|Ltime|Lmicroseconds, "", Rtime+Rmicroseconds+" " }, tester( Lok|Ltime|Lmicroseconds, "", Rtime+Rmicroseconds+" " ),
tester{ Lok|Lmicroseconds, "", Rtime+Rmicroseconds+" " }, // microsec implies time tester( Lok|Lmicroseconds, "", Rtime+Rmicroseconds+" " ), // microsec implies time
tester{ Lok|Llongfile, "", Rlongfile+" " }, tester( Lok|Llongfile, "", Rlongfile+" " ),
tester{ Lok|Lshortfile, "", Rshortfile+" " }, tester( Lok|Lshortfile, "", Rshortfile+" " ),
tester{ Lok|Llongfile|Lshortfile, "", Rshortfile+" " }, // shortfile overrides longfile tester( Lok|Llongfile|Lshortfile, "", Rshortfile+" " ), // shortfile overrides longfile
// everything at once: // everything at once:
tester{ Lok|Ldate|Ltime|Lmicroseconds|Llongfile, "XXX", "XXX"+Rdate+" "+Rtime+Rmicroseconds+" "+Rlongfile+" " }, tester( Lok|Ldate|Ltime|Lmicroseconds|Llongfile, "XXX", "XXX"+Rdate+" "+Rtime+Rmicroseconds+" "+Rlongfile+" " ),
tester{ Lok|Ldate|Ltime|Lmicroseconds|Lshortfile, "XXX", "XXX"+Rdate+" "+Rtime+Rmicroseconds+" "+Rshortfile+" " }, tester( Lok|Ldate|Ltime|Lmicroseconds|Lshortfile, "XXX", "XXX"+Rdate+" "+Rtime+Rmicroseconds+" "+Rshortfile+" " ),
} )
// Test using Log("hello", 23, "world") or using Logf("hello %d world", 23) // Test using Log("hello", 23, "world") or using Logf("hello %d world", 23)
func testLog(t *testing.T, flag int, prefix string, pattern string, useLogf bool) { func testLog(t *testing.T, flag int, prefix string, pattern string, useLogf bool) {

View file

@ -9,7 +9,7 @@ import (
"testing"; "testing";
) )
var vf = []float64 { var vf = []float64 (
4.9790119248836735e+00, 4.9790119248836735e+00,
7.7388724745781045e+00, 7.7388724745781045e+00,
-2.7688005719200159e-01, -2.7688005719200159e-01,
@ -20,8 +20,8 @@ var vf = []float64 {
2.7279399104360102e+00, 2.7279399104360102e+00,
1.8253080916808550e+00, 1.8253080916808550e+00,
-8.6859247685756013e+00, -8.6859247685756013e+00,
} )
var asin = []float64 { var asin = []float64 (
5.2117697218417440e-01, 5.2117697218417440e-01,
8.8495619865825236e-01, 8.8495619865825236e-01,
-2.7691544662819413e-02, -2.7691544662819413e-02,
@ -32,8 +32,8 @@ var asin = []float64 {
2.7629597861677200e-01, 2.7629597861677200e-01,
1.8355989225745148e-01, 1.8355989225745148e-01,
-1.0523547536021498e+00, -1.0523547536021498e+00,
} )
var atan = []float64 { var atan = []float64 (
1.3725902621296217e+00, 1.3725902621296217e+00,
1.4422906096452980e+00, 1.4422906096452980e+00,
-2.7011324359471755e-01, -2.7011324359471755e-01,
@ -44,8 +44,8 @@ var atan = []float64 {
1.2194305844639670e+00, 1.2194305844639670e+00,
1.0696031952318783e+00, 1.0696031952318783e+00,
-1.4561721938838085e+00, -1.4561721938838085e+00,
} )
var exp = []float64 { var exp = []float64 (
1.4533071302642137e+02, 1.4533071302642137e+02,
2.2958822575694450e+03, 2.2958822575694450e+03,
7.5814542574851666e-01, 7.5814542574851666e-01,
@ -56,8 +56,8 @@ var exp = []float64 {
1.5301332413189379e+01, 1.5301332413189379e+01,
6.2047063430646876e+00, 6.2047063430646876e+00,
1.6894712385826522e-04, 1.6894712385826522e-04,
} )
var floor = []float64 { var floor = []float64 (
4.0000000000000000e+00, 4.0000000000000000e+00,
7.0000000000000000e+00, 7.0000000000000000e+00,
-1.0000000000000000e+00, -1.0000000000000000e+00,
@ -68,8 +68,8 @@ var floor = []float64 {
2.0000000000000000e+00, 2.0000000000000000e+00,
1.0000000000000000e+00, 1.0000000000000000e+00,
-9.0000000000000000e+00, -9.0000000000000000e+00,
} )
var log = []float64 { var log = []float64 (
1.6052314626930630e+00, 1.6052314626930630e+00,
2.0462560018708768e+00, 2.0462560018708768e+00,
-1.2841708730962657e+00, -1.2841708730962657e+00,
@ -80,8 +80,8 @@ var log = []float64 {
1.0035467127723465e+00, 1.0035467127723465e+00,
6.0174879014578053e-01, 6.0174879014578053e-01,
2.1617038728473527e+00, 2.1617038728473527e+00,
} )
var pow = []float64 { var pow = []float64 (
9.5282232631648415e+04, 9.5282232631648415e+04,
5.4811599352999900e+07, 5.4811599352999900e+07,
5.2859121715894400e-01, 5.2859121715894400e-01,
@ -92,8 +92,8 @@ var pow = []float64 {
5.3449040147551940e+02, 5.3449040147551940e+02,
6.6881821384514159e+01, 6.6881821384514159e+01,
2.0609869004248744e-09, 2.0609869004248744e-09,
} )
var sin = []float64 { var sin = []float64 (
-9.6466616586009283e-01, -9.6466616586009283e-01,
9.9338225271646543e-01, 9.9338225271646543e-01,
-2.7335587039794395e-01, -2.7335587039794395e-01,
@ -104,8 +104,8 @@ var sin = []float64 {
4.0195666811555783e-01, 4.0195666811555783e-01,
9.6778633541688000e-01, 9.6778633541688000e-01,
-6.7344058690503452e-01, -6.7344058690503452e-01,
} )
var sinh = []float64 { var sinh = []float64 (
7.2661916084208533e+01, 7.2661916084208533e+01,
1.1479409110035194e+03, 1.1479409110035194e+03,
-2.8043136512812520e-01, -2.8043136512812520e-01,
@ -116,8 +116,8 @@ var sinh = []float64 {
7.6179893137269143e+00, 7.6179893137269143e+00,
3.0217691805496156e+00, 3.0217691805496156e+00,
-2.9595057572444951e+03, -2.9595057572444951e+03,
} )
var sqrt = []float64 { var sqrt = []float64 (
2.2313699659365484e+00, 2.2313699659365484e+00,
2.7818829009464263e+00, 2.7818829009464263e+00,
5.2619393496314792e-01, 5.2619393496314792e-01,
@ -128,8 +128,8 @@ var sqrt = []float64 {
1.6516476350711160e+00, 1.6516476350711160e+00,
1.3510396336454586e+00, 1.3510396336454586e+00,
2.9471892997524950e+00, 2.9471892997524950e+00,
} )
var tan = []float64 { var tan = []float64 (
-3.6613165650402277e+00, -3.6613165650402277e+00,
8.6490023264859754e+00, 8.6490023264859754e+00,
-2.8417941955033615e-01, -2.8417941955033615e-01,
@ -140,8 +140,8 @@ var tan = []float64 {
-4.3898089147528178e-01, -4.3898089147528178e-01,
-3.8438855602011305e+00, -3.8438855602011305e+00,
9.1098879337768517e-01, 9.1098879337768517e-01,
} )
var tanh = []float64 { var tanh = []float64 (
9.9990531206936328e-01, 9.9990531206936328e-01,
9.9999962057085307e-01, 9.9999962057085307e-01,
-2.7001505097318680e-01, -2.7001505097318680e-01,
@ -152,7 +152,7 @@ var tanh = []float64 {
9.9149409509772863e-01, 9.9149409509772863e-01,
9.4936501296239700e-01, 9.4936501296239700e-01,
-9.9999994291374019e-01, -9.9999994291374019e-01,
} )
func tolerance(a,b,e float64) bool { func tolerance(a,b,e float64) bool {
d := a-b; d := a-b;

View file

@ -50,7 +50,7 @@ func doDialTCP(t *testing.T, network, addr string) {
fd.Close() fd.Close()
} }
var googleaddrs = []string { var googleaddrs = []string (
"74.125.19.99:80", "74.125.19.99:80",
"www.google.com:80", "www.google.com:80",
"74.125.19.99:http", "74.125.19.99:http",
@ -62,7 +62,7 @@ var googleaddrs = []string {
"[0:0:0:0:000000:ffff:74.125.19.99]:80", "[0:0:0:0:000000:ffff:74.125.19.99]:80",
"[0:0:0:0:0:ffff::74.125.19.99]:80", "[0:0:0:0:0:ffff::74.125.19.99]:80",
"[2001:4860:0:2001::68]:80" // ipv6.google.com; removed if ipv6 flag not set "[2001:4860:0:2001::68]:80" // ipv6.google.com; removed if ipv6 flag not set
} )
func TestDialGoogle(t *testing.T) { func TestDialGoogle(t *testing.T) {
// If no ipv6 tunnel, don't try the last address. // If no ipv6 tunnel, don't try the last address.

View file

@ -46,9 +46,9 @@ func _Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
} }
out := new(DNS_Msg); out := new(DNS_Msg);
out.id = 0x1234; out.id = 0x1234;
out.question = []DNS_Question{ out.question = []DNS_Question(
DNS_Question{ name, DNS_TypeA, DNS_ClassINET } DNS_Question( name, DNS_TypeA, DNS_ClassINET )
}; );
out.recursion_desired = true; out.recursion_desired = true;
msg, ok := out.Pack(); msg, ok := out.Pack();
if !ok { if !ok {

View file

@ -197,7 +197,7 @@ type DNS_RR_A struct {
// packing sequence. // packing sequence.
// Map of constructors for each RR wire type. // Map of constructors for each RR wire type.
var rr_mk = map[int] func()DNS_RR { var rr_mk = map[int] func()DNS_RR (
DNS_TypeCNAME: func() DNS_RR { return new(DNS_RR_CNAME) }, DNS_TypeCNAME: func() DNS_RR { return new(DNS_RR_CNAME) },
DNS_TypeHINFO: func() DNS_RR { return new(DNS_RR_HINFO) }, DNS_TypeHINFO: func() DNS_RR { return new(DNS_RR_HINFO) },
DNS_TypeMB: func() DNS_RR { return new(DNS_RR_MB) }, DNS_TypeMB: func() DNS_RR { return new(DNS_RR_MB) },
@ -210,7 +210,7 @@ var rr_mk = map[int] func()DNS_RR {
DNS_TypeSOA: func() DNS_RR { return new(DNS_RR_SOA) }, DNS_TypeSOA: func() DNS_RR { return new(DNS_RR_SOA) },
DNS_TypeTXT: func() DNS_RR { return new(DNS_RR_TXT) }, DNS_TypeTXT: func() DNS_RR { return new(DNS_RR_TXT) },
DNS_TypeA: func() DNS_RR { return new(DNS_RR_A) }, DNS_TypeA: func() DNS_RR { return new(DNS_RR_A) },
} )
// _Pack a domain name s into msg[off:]. // _Pack a domain name s into msg[off:].
// Domain names are a sequence of counted strings // Domain names are a sequence of counted strings

View file

@ -10,7 +10,7 @@ import (
) )
func _IPv4(a, b, c, d byte) []byte { func _IPv4(a, b, c, d byte) []byte {
return []byte{ 0,0,0,0, 0,0,0,0, 0,0,255,255, a,b,c,d } return []byte( 0,0,0,0, 0,0,0,0, 0,0,255,255, a,b,c,d )
} }
func isEqual(a []byte, b []byte) bool { func isEqual(a []byte, b []byte) bool {
@ -32,16 +32,16 @@ type parseIPTest struct {
in string; in string;
out []byte; out []byte;
} }
var parseiptests = []parseIPTest { var parseiptests = []parseIPTest (
parseIPTest{"127.0.1.2", _IPv4(127, 0, 1, 2)}, parseIPTest("127.0.1.2", _IPv4(127, 0, 1, 2)),
parseIPTest{"127.0.0.1", _IPv4(127, 0, 0, 1)}, parseIPTest("127.0.0.1", _IPv4(127, 0, 0, 1)),
parseIPTest{"127.0.0.256", nil}, parseIPTest("127.0.0.256", nil),
parseIPTest{"abc", nil}, parseIPTest("abc", nil),
parseIPTest{"::ffff:127.0.0.1", _IPv4(127, 0, 0, 1)}, parseIPTest("::ffff:127.0.0.1", _IPv4(127, 0, 0, 1)),
parseIPTest{"2001:4860:0:2001::68", parseIPTest("2001:4860:0:2001::68",
[]byte{0x20,0x01, 0x48,0x60, 0,0, 0x20,0x01, 0,0, 0,0, 0,0, 0x00,0x68}}, []byte(0x20,0x01, 0x48,0x60, 0,0, 0x20,0x01, 0,0, 0,0, 0,0, 0x00,0x68)),
parseIPTest{"::ffff:4a7d:1363", _IPv4(74, 125, 19, 99)}, parseIPTest("::ffff:4a7d:1363", _IPv4(74, 125, 19, 99)),
} )
func TestParseIP(t *testing.T) { func TestParseIP(t *testing.T) {
for i := 0; i < len(parseiptests); i++ { for i := 0; i < len(parseiptests); i++ {

View file

@ -60,7 +60,7 @@ func _Open(name string) *_File {
if err != nil { if err != nil {
return nil return nil
} }
return &_File{fd, make([]byte, 1024)[0:0]}; return &_File(fd, make([]byte, 1024)[0:0]);
} }
func _ByteIndex(s string, c byte) int { func _ByteIndex(s string, c byte) int {

View file

@ -16,37 +16,37 @@ type portTest struct {
ok bool; ok bool;
} }
var porttests = []portTest { var porttests = []portTest (
portTest{ "tcp", "echo", 7, true }, portTest( "tcp", "echo", 7, true ),
portTest{ "tcp", "discard", 9, true }, portTest( "tcp", "discard", 9, true ),
portTest{ "tcp", "systat", 11, true }, portTest( "tcp", "systat", 11, true ),
portTest{ "tcp", "daytime", 13, true }, portTest( "tcp", "daytime", 13, true ),
portTest{ "tcp", "chargen", 19, true }, portTest( "tcp", "chargen", 19, true ),
portTest{ "tcp", "ftp-data", 20, true }, portTest( "tcp", "ftp-data", 20, true ),
portTest{ "tcp", "ftp", 21, true }, portTest( "tcp", "ftp", 21, true ),
portTest{ "tcp", "ssh", 22, true }, portTest( "tcp", "ssh", 22, true ),
portTest{ "tcp", "telnet", 23, true }, portTest( "tcp", "telnet", 23, true ),
portTest{ "tcp", "smtp", 25, true }, portTest( "tcp", "smtp", 25, true ),
portTest{ "tcp", "time", 37, true }, portTest( "tcp", "time", 37, true ),
portTest{ "tcp", "domain", 53, true }, portTest( "tcp", "domain", 53, true ),
portTest{ "tcp", "gopher", 70, true }, portTest( "tcp", "gopher", 70, true ),
portTest{ "tcp", "finger", 79, true }, portTest( "tcp", "finger", 79, true ),
portTest{ "tcp", "http", 80, true }, portTest( "tcp", "http", 80, true ),
portTest{ "udp", "echo", 7, true }, portTest( "udp", "echo", 7, true ),
portTest{ "udp", "tacacs", 49, true }, portTest( "udp", "tacacs", 49, true ),
portTest{ "udp", "tftp", 69, true }, portTest( "udp", "tftp", 69, true ),
portTest{ "udp", "bootpc", 68, true }, portTest( "udp", "bootpc", 68, true ),
portTest{ "udp", "bootps", 67, true }, portTest( "udp", "bootps", 67, true ),
portTest{ "udp", "domain", 53, true }, portTest( "udp", "domain", 53, true ),
portTest{ "udp", "ntp", 123, true }, portTest( "udp", "ntp", 123, true ),
portTest{ "udp", "snmp", 161, true }, portTest( "udp", "snmp", 161, true ),
portTest{ "udp", "syslog", 514, true }, portTest( "udp", "syslog", 514, true ),
portTest{ "udp", "nfs", 2049, true }, portTest( "udp", "nfs", 2049, true ),
portTest{ "--badnet--", "zzz", 0, false }, portTest( "--badnet--", "zzz", 0, false ),
portTest{ "tcp", "--badport--", 0, false }, portTest( "tcp", "--badport--", 0, false ),
} )
func TestLookupPort(t *testing.T) { func TestLookupPort(t *testing.T) {
for i := 0; i < len(porttests); i++ { for i := 0; i < len(porttests); i++ {

View file

@ -52,7 +52,7 @@ func Do(f func()) {
// job, present = jobmap[f] // job, present = jobmap[f]
if !present { if !present {
c := make(chan *_Job); c := make(chan *_Job);
service <- _Request{f, c}; service <- _Request(f, c);
job = <-c job = <-c
} }

View file

@ -33,7 +33,7 @@ func NewError(s string) *Error {
if ok { if ok {
return err return err
} }
err = &Error{s}; err = &Error(s);
errorStringTab[s] = err; errorStringTab[s] = err;
return err; return err;
} }

View file

@ -33,7 +33,7 @@ func NewFD(fd int64, name string) *FD {
if fd < 0 { if fd < 0 {
return nil return nil
} }
return &FD{fd, name, nil} return &FD(fd, name, nil)
} }
var ( var (

View file

@ -10,7 +10,7 @@ import (
"testing"; "testing";
) )
var dot = []string{ var dot = []string(
"dir_amd64_darwin.go", "dir_amd64_darwin.go",
"dir_amd64_linux.go", "dir_amd64_linux.go",
"os_env.go", "os_env.go",
@ -21,13 +21,13 @@ var dot = []string{
"os_types.go", "os_types.go",
"stat_amd64_darwin.go", "stat_amd64_darwin.go",
"stat_amd64_linux.go" "stat_amd64_linux.go"
} )
var etc = []string{ var etc = []string(
"group", "group",
"hosts", "hosts",
"passwd", "passwd",
} )
func size(file string, t *testing.T) uint64 { func size(file string, t *testing.T) uint64 {
fd, err := Open(file, O_RDONLY, 0); fd, err := Open(file, O_RDONLY, 0);

View file

@ -168,7 +168,7 @@ func TestAll(tt *testing.T) { // TODO(r): wrap up better
} }
{ {
var i int = 7; var i int = 7;
var tmp = &T{123, 456.75, "hello", &i}; var tmp = &T(123, 456.75, "hello", &i);
value := reflect.NewValue(tmp); value := reflect.NewValue(tmp);
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.T{123, 456.75, hello, *int(@)}"); assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.T{123, 456.75, hello, *int(@)}");
} }
@ -188,7 +188,7 @@ func TestAll(tt *testing.T) { // TODO(r): wrap up better
// } // }
{ {
type AA []int; type AA []int;
var tmp = AA{1,2,3,4,5,6,7,8,9,10}; var tmp = AA(1,2,3,4,5,6,7,8,9,10);
value := reflect.NewValue(&tmp); // TODO: NewValue(tmp) too value := reflect.NewValue(&tmp); // TODO: NewValue(tmp) too
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}");
value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123);
@ -297,9 +297,9 @@ func TestInterfaceGet(t *testing.T) {
} }
func TestCopyArray(t *testing.T) { func TestCopyArray(t *testing.T) {
a := []int{ 1, 2, 3, 4, 10, 9, 8, 7 }; a := []int( 1, 2, 3, 4, 10, 9, 8, 7 );
b := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 }; b := []int( 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 );
c := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 }; c := []int( 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 );
va := NewValue(&a); va := NewValue(&a);
vb := NewValue(&b); vb := NewValue(&b);
for i := 0; i < len(b); i++ { for i := 0; i < len(b); i++ {
@ -332,7 +332,7 @@ func TestCopyArray(t *testing.T) {
} }
func TestBigUnnamedStruct(t *testing.T) { func TestBigUnnamedStruct(t *testing.T) {
b := struct{a,b,c,d int64}{1, 2, 3, 4}; b := struct{a,b,c,d int64}(1, 2, 3, 4);
v := NewValue(b); v := NewValue(b);
b1 := v.Interface().(struct{a,b,c,d int64}); b1 := v.Interface().(struct{a,b,c,d int64});
if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d { if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d {
@ -344,7 +344,7 @@ type big struct {
a, b, c, d, e int64 a, b, c, d, e int64
} }
func TestBigStruct(t *testing.T) { func TestBigStruct(t *testing.T) {
b := big{1, 2, 3, 4, 5}; b := big(1, 2, 3, 4, 5);
v := NewValue(b); v := NewValue(b);
b1 := v.Interface().(big); b1 := v.Interface().(big);
if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d || b1.e != b.e { if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d || b1.e != b.e {

View file

@ -101,7 +101,7 @@ type basicType struct {
} }
func newBasicType(name string, kind int, size int) Type { func newBasicType(name string, kind int, size int) Type {
return &basicType{ commonType{kind, name, name, size} } return &basicType( commonType(kind, name, name, size) )
} }
// Prebuilt basic types // Prebuilt basic types
@ -136,7 +136,7 @@ type stubType struct {
} }
func newStubType(name string, typ Type) *stubType { func newStubType(name string, typ Type) *stubType {
return &stubType{name, typ} return &stubType(name, typ)
} }
func (t *stubType) Get() Type { func (t *stubType) Get() Type {
@ -164,7 +164,7 @@ type ptrTypeStruct struct {
} }
func newPtrTypeStruct(name, typestring string, sub *stubType) *ptrTypeStruct { func newPtrTypeStruct(name, typestring string, sub *stubType) *ptrTypeStruct {
return &ptrTypeStruct{ commonType{PtrKind, typestring, name, ptrsize}, sub} return &ptrTypeStruct( commonType(PtrKind, typestring, name, ptrsize), sub)
} }
func (t *ptrTypeStruct) Sub() Type { func (t *ptrTypeStruct) Sub() Type {
@ -193,7 +193,7 @@ type arrayTypeStruct struct {
} }
func newArrayTypeStruct(name, typestring string, open bool, len int, elem *stubType) *arrayTypeStruct { func newArrayTypeStruct(name, typestring string, open bool, len int, elem *stubType) *arrayTypeStruct {
return &arrayTypeStruct{ commonType{ArrayKind, typestring, name, 0}, elem, open, len} return &arrayTypeStruct( commonType(ArrayKind, typestring, name, 0), elem, open, len)
} }
func (t *arrayTypeStruct) Size() int { func (t *arrayTypeStruct) Size() int {
@ -236,7 +236,7 @@ type mapTypeStruct struct {
} }
func newMapTypeStruct(name, typestring string, key, elem *stubType) *mapTypeStruct { func newMapTypeStruct(name, typestring string, key, elem *stubType) *mapTypeStruct {
return &mapTypeStruct{ commonType{MapKind, typestring, name, ptrsize}, key, elem} return &mapTypeStruct( commonType(MapKind, typestring, name, ptrsize), key, elem)
} }
func (t *mapTypeStruct) Key() Type { func (t *mapTypeStruct) Key() Type {
@ -273,7 +273,7 @@ type chanTypeStruct struct {
} }
func newChanTypeStruct(name, typestring string, dir int, elem *stubType) *chanTypeStruct { func newChanTypeStruct(name, typestring string, dir int, elem *stubType) *chanTypeStruct {
return &chanTypeStruct{ commonType{ChanKind, typestring, name, ptrsize}, elem, dir} return &chanTypeStruct( commonType(ChanKind, typestring, name, ptrsize), elem, dir)
} }
func (t *chanTypeStruct) Dir() int { func (t *chanTypeStruct) Dir() int {
@ -311,7 +311,7 @@ type structTypeStruct struct {
} }
func newStructTypeStruct(name, typestring string, field []structField) *structTypeStruct { func newStructTypeStruct(name, typestring string, field []structField) *structTypeStruct {
return &structTypeStruct{ commonType{StructKind, typestring, name, 0}, field} return &structTypeStruct( commonType(StructKind, typestring, name, 0), field)
} }
// TODO: not portable; depends on 6g // TODO: not portable; depends on 6g
@ -369,7 +369,7 @@ type interfaceTypeStruct struct {
} }
func newInterfaceTypeStruct(name, typestring string, field []structField) *interfaceTypeStruct { func newInterfaceTypeStruct(name, typestring string, field []structField) *interfaceTypeStruct {
return &interfaceTypeStruct{ commonType{InterfaceKind, typestring, name, interfacesize}, field } return &interfaceTypeStruct( commonType(InterfaceKind, typestring, name, interfacesize), field )
} }
func (t *interfaceTypeStruct) Field(i int) (name string, typ Type, tag string, offset int) { func (t *interfaceTypeStruct) Field(i int) (name string, typ Type, tag string, offset int) {
@ -402,7 +402,7 @@ type funcTypeStruct struct {
} }
func newFuncTypeStruct(name, typestring string, in, out *structTypeStruct) *funcTypeStruct { func newFuncTypeStruct(name, typestring string, in, out *structTypeStruct) *funcTypeStruct {
return &funcTypeStruct{ commonType{FuncKind, typestring, name, 0}, in, out } return &funcTypeStruct( commonType(FuncKind, typestring, name, 0), in, out )
} }
func (t *funcTypeStruct) Size() int { func (t *funcTypeStruct) Size() int {

View file

@ -78,7 +78,7 @@ type missingValueStruct struct {
} }
func missingCreator(typ Type, addr Addr) Value { func missingCreator(typ Type, addr Addr) Value {
return &missingValueStruct{ commonValue{MissingKind, typ, addr} } return &missingValueStruct( commonValue(MissingKind, typ, addr) )
} }
// -- Int // -- Int
@ -99,7 +99,7 @@ type intValueStruct struct {
} }
func intCreator(typ Type, addr Addr) Value { func intCreator(typ Type, addr Addr) Value {
return &intValueStruct{ commonValue{IntKind, typ, addr} } return &intValueStruct( commonValue(IntKind, typ, addr) )
} }
func (v *intValueStruct) Get() int { func (v *intValueStruct) Get() int {
@ -128,7 +128,7 @@ type int8ValueStruct struct {
} }
func int8Creator(typ Type, addr Addr) Value { func int8Creator(typ Type, addr Addr) Value {
return &int8ValueStruct{ commonValue{Int8Kind, typ, addr} } return &int8ValueStruct( commonValue(Int8Kind, typ, addr) )
} }
func (v *int8ValueStruct) Get() int8 { func (v *int8ValueStruct) Get() int8 {
@ -157,7 +157,7 @@ type int16ValueStruct struct {
} }
func int16Creator(typ Type, addr Addr) Value { func int16Creator(typ Type, addr Addr) Value {
return &int16ValueStruct{ commonValue{Int16Kind, typ, addr} } return &int16ValueStruct( commonValue(Int16Kind, typ, addr) )
} }
func (v *int16ValueStruct) Get() int16 { func (v *int16ValueStruct) Get() int16 {
@ -186,7 +186,7 @@ type int32ValueStruct struct {
} }
func int32Creator(typ Type, addr Addr) Value { func int32Creator(typ Type, addr Addr) Value {
return &int32ValueStruct{ commonValue{Int32Kind, typ, addr} } return &int32ValueStruct( commonValue(Int32Kind, typ, addr) )
} }
func (v *int32ValueStruct) Get() int32 { func (v *int32ValueStruct) Get() int32 {
@ -215,7 +215,7 @@ type int64ValueStruct struct {
} }
func int64Creator(typ Type, addr Addr) Value { func int64Creator(typ Type, addr Addr) Value {
return &int64ValueStruct{ commonValue{Int64Kind, typ, addr} } return &int64ValueStruct( commonValue(Int64Kind, typ, addr) )
} }
func (v *int64ValueStruct) Get() int64 { func (v *int64ValueStruct) Get() int64 {
@ -244,7 +244,7 @@ type uintValueStruct struct {
} }
func uintCreator(typ Type, addr Addr) Value { func uintCreator(typ Type, addr Addr) Value {
return &uintValueStruct{ commonValue{UintKind, typ, addr} } return &uintValueStruct( commonValue(UintKind, typ, addr) )
} }
func (v *uintValueStruct) Get() uint { func (v *uintValueStruct) Get() uint {
@ -273,7 +273,7 @@ type uint8ValueStruct struct {
} }
func uint8Creator(typ Type, addr Addr) Value { func uint8Creator(typ Type, addr Addr) Value {
return &uint8ValueStruct{ commonValue{Uint8Kind, typ, addr} } return &uint8ValueStruct( commonValue(Uint8Kind, typ, addr) )
} }
func (v *uint8ValueStruct) Get() uint8 { func (v *uint8ValueStruct) Get() uint8 {
@ -302,7 +302,7 @@ type uint16ValueStruct struct {
} }
func uint16Creator(typ Type, addr Addr) Value { func uint16Creator(typ Type, addr Addr) Value {
return &uint16ValueStruct{ commonValue{Uint16Kind, typ, addr} } return &uint16ValueStruct( commonValue(Uint16Kind, typ, addr) )
} }
func (v *uint16ValueStruct) Get() uint16 { func (v *uint16ValueStruct) Get() uint16 {
@ -331,7 +331,7 @@ type uint32ValueStruct struct {
} }
func uint32Creator(typ Type, addr Addr) Value { func uint32Creator(typ Type, addr Addr) Value {
return &uint32ValueStruct{ commonValue{Uint32Kind, typ, addr} } return &uint32ValueStruct( commonValue(Uint32Kind, typ, addr) )
} }
func (v *uint32ValueStruct) Get() uint32 { func (v *uint32ValueStruct) Get() uint32 {
@ -360,7 +360,7 @@ type uint64ValueStruct struct {
} }
func uint64Creator(typ Type, addr Addr) Value { func uint64Creator(typ Type, addr Addr) Value {
return &uint64ValueStruct{ commonValue{Uint64Kind, typ, addr} } return &uint64ValueStruct( commonValue(Uint64Kind, typ, addr) )
} }
func (v *uint64ValueStruct) Get() uint64 { func (v *uint64ValueStruct) Get() uint64 {
@ -389,7 +389,7 @@ type uintptrValueStruct struct {
} }
func uintptrCreator(typ Type, addr Addr) Value { func uintptrCreator(typ Type, addr Addr) Value {
return &uintptrValueStruct{ commonValue{UintptrKind, typ, addr} } return &uintptrValueStruct( commonValue(UintptrKind, typ, addr) )
} }
func (v *uintptrValueStruct) Get() uintptr { func (v *uintptrValueStruct) Get() uintptr {
@ -418,7 +418,7 @@ type floatValueStruct struct {
} }
func floatCreator(typ Type, addr Addr) Value { func floatCreator(typ Type, addr Addr) Value {
return &floatValueStruct{ commonValue{FloatKind, typ, addr} } return &floatValueStruct( commonValue(FloatKind, typ, addr) )
} }
func (v *floatValueStruct) Get() float { func (v *floatValueStruct) Get() float {
@ -447,7 +447,7 @@ type float32ValueStruct struct {
} }
func float32Creator(typ Type, addr Addr) Value { func float32Creator(typ Type, addr Addr) Value {
return &float32ValueStruct{ commonValue{Float32Kind, typ, addr} } return &float32ValueStruct( commonValue(Float32Kind, typ, addr) )
} }
func (v *float32ValueStruct) Get() float32 { func (v *float32ValueStruct) Get() float32 {
@ -476,7 +476,7 @@ type float64ValueStruct struct {
} }
func float64Creator(typ Type, addr Addr) Value { func float64Creator(typ Type, addr Addr) Value {
return &float64ValueStruct{ commonValue{Float64Kind, typ, addr} } return &float64ValueStruct( commonValue(Float64Kind, typ, addr) )
} }
func (v *float64ValueStruct) Get() float64 { func (v *float64ValueStruct) Get() float64 {
@ -505,7 +505,7 @@ type float80ValueStruct struct {
} }
func float80Creator(typ Type, addr Addr) Value { func float80Creator(typ Type, addr Addr) Value {
return &float80ValueStruct{ commonValue{Float80Kind, typ, addr} } return &float80ValueStruct( commonValue(Float80Kind, typ, addr) )
} }
/* /*
@ -537,7 +537,7 @@ type stringValueStruct struct {
} }
func stringCreator(typ Type, addr Addr) Value { func stringCreator(typ Type, addr Addr) Value {
return &stringValueStruct{ commonValue{StringKind, typ, addr} } return &stringValueStruct( commonValue(StringKind, typ, addr) )
} }
func (v *stringValueStruct) Get() string { func (v *stringValueStruct) Get() string {
@ -566,7 +566,7 @@ type boolValueStruct struct {
} }
func boolCreator(typ Type, addr Addr) Value { func boolCreator(typ Type, addr Addr) Value {
return &boolValueStruct{ commonValue{BoolKind, typ, addr} } return &boolValueStruct( commonValue(BoolKind, typ, addr) )
} }
func (v *boolValueStruct) Get() bool { func (v *boolValueStruct) Get() bool {
@ -614,7 +614,7 @@ func (v *ptrValueStruct) SetSub(subv Value) {
} }
func ptrCreator(typ Type, addr Addr) Value { func ptrCreator(typ Type, addr Addr) Value {
return &ptrValueStruct{ commonValue{PtrKind, typ, addr} }; return &ptrValueStruct( commonValue(PtrKind, typ, addr) );
} }
// -- Array // -- Array
@ -774,7 +774,7 @@ type mapValueStruct struct {
} }
func mapCreator(typ Type, addr Addr) Value { func mapCreator(typ Type, addr Addr) Value {
return &mapValueStruct{ commonValue{MapKind, typ, addr} } return &mapValueStruct( commonValue(MapKind, typ, addr) )
} }
func (v *mapValueStruct) Len() int { func (v *mapValueStruct) Len() int {
@ -801,7 +801,7 @@ type chanValueStruct struct {
} }
func chanCreator(typ Type, addr Addr) Value { func chanCreator(typ Type, addr Addr) Value {
return &chanValueStruct{ commonValue{ChanKind, typ, addr} } return &chanValueStruct( commonValue(ChanKind, typ, addr) )
} }
// -- Struct // -- Struct
@ -833,7 +833,7 @@ func (v *structValueStruct) Field(i int) Value {
func structCreator(typ Type, addr Addr) Value { func structCreator(typ Type, addr Addr) Value {
t := typ.(StructType); t := typ.(StructType);
nfield := t.Len(); nfield := t.Len();
v := &structValueStruct{ commonValue{StructKind, typ, addr}, make([]Value, nfield) }; v := &structValueStruct( commonValue(StructKind, typ, addr), make([]Value, nfield) );
for i := 0; i < nfield; i++ { for i := 0; i < nfield; i++ {
name, ftype, str, offset := t.Field(i); name, ftype, str, offset := t.Field(i);
addr_uint := uintptr(addr) + uintptr(offset); addr_uint := uintptr(addr) + uintptr(offset);
@ -864,7 +864,7 @@ func (v *interfaceValueStruct) Get() interface{} {
} }
func interfaceCreator(typ Type, addr Addr) Value { func interfaceCreator(typ Type, addr Addr) Value {
return &interfaceValueStruct{ commonValue{InterfaceKind, typ, addr} } return &interfaceValueStruct( commonValue(InterfaceKind, typ, addr) )
} }
// -- Func // -- Func
@ -882,10 +882,10 @@ type funcValueStruct struct {
} }
func funcCreator(typ Type, addr Addr) Value { func funcCreator(typ Type, addr Addr) Value {
return &funcValueStruct{ commonValue{FuncKind, typ, addr} } return &funcValueStruct( commonValue(FuncKind, typ, addr) )
} }
var creator = map[int] creatorFn { var creator = map[int] creatorFn (
MissingKind : missingCreator, MissingKind : missingCreator,
IntKind : intCreator, IntKind : intCreator,
Int8Kind : int8Creator, Int8Kind : int8Creator,
@ -911,7 +911,7 @@ var creator = map[int] creatorFn {
StructKind : structCreator, StructKind : structCreator,
InterfaceKind : interfaceCreator, InterfaceKind : interfaceCreator,
FuncKind : funcCreator, FuncKind : funcCreator,
} )
var typecache = make(map[string] Type); var typecache = make(map[string] Type);

View file

@ -10,7 +10,7 @@ import (
"testing"; "testing";
) )
var good_re = []string{ var good_re = []string(
``, ``,
`.`, `.`,
`^.$`, `^.$`,
@ -27,27 +27,27 @@ var good_re = []string{
`[]`, `[]`,
`[abc]`, `[abc]`,
`[^1234]`, `[^1234]`,
} )
// TODO: nice to do this with a map // TODO: nice to do this with a map
type stringError struct { type stringError struct {
re string; re string;
err *os.Error; err *os.Error;
} }
var bad_re = []stringError{ var bad_re = []stringError(
stringError{ `*`, regexp.ErrBareClosure }, stringError( `*`, regexp.ErrBareClosure ),
stringError{ `(abc`, regexp.ErrUnmatchedLpar }, stringError( `(abc`, regexp.ErrUnmatchedLpar ),
stringError{ `abc)`, regexp.ErrUnmatchedRpar }, stringError( `abc)`, regexp.ErrUnmatchedRpar ),
stringError{ `x[a-z`, regexp.ErrUnmatchedLbkt }, stringError( `x[a-z`, regexp.ErrUnmatchedLbkt ),
stringError{ `abc]`, regexp.ErrUnmatchedRbkt }, stringError( `abc]`, regexp.ErrUnmatchedRbkt ),
stringError{ `[z-a]`, regexp.ErrBadRange }, stringError( `[z-a]`, regexp.ErrBadRange ),
stringError{ `abc\`, regexp.ErrExtraneousBackslash }, stringError( `abc\`, regexp.ErrExtraneousBackslash ),
stringError{ `a**`, regexp.ErrBadClosure }, stringError( `a**`, regexp.ErrBadClosure ),
stringError{ `a*+`, regexp.ErrBadClosure }, stringError( `a*+`, regexp.ErrBadClosure ),
stringError{ `a??`, regexp.ErrBadClosure }, stringError( `a??`, regexp.ErrBadClosure ),
stringError{ `*`, regexp.ErrBareClosure }, stringError( `*`, regexp.ErrBareClosure ),
stringError{ `\x`, regexp.ErrBadBackslash }, stringError( `\x`, regexp.ErrBadBackslash ),
} )
type vec []int; type vec []int;
@ -57,33 +57,33 @@ type tester struct {
match vec; match vec;
} }
var matches = []tester { var matches = []tester (
tester{ ``, "", vec{0,0} }, tester( ``, "", vec(0,0) ),
tester{ `a`, "a", vec{0,1} }, tester( `a`, "a", vec(0,1) ),
tester{ `x`, "y", vec{} }, tester( `x`, "y", vec() ),
tester{ `b`, "abc", vec{1,2} }, tester( `b`, "abc", vec(1,2) ),
tester{ `.`, "a", vec{0,1} }, tester( `.`, "a", vec(0,1) ),
tester{ `.*`, "abcdef", vec{0,6} }, tester( `.*`, "abcdef", vec(0,6) ),
tester{ `^abcd$`, "abcd", vec{0,4} }, tester( `^abcd$`, "abcd", vec(0,4) ),
tester{ `^bcd'`, "abcdef", vec{} }, tester( `^bcd'`, "abcdef", vec() ),
tester{ `^abcd$`, "abcde", vec{} }, tester( `^abcd$`, "abcde", vec() ),
tester{ `a+`, "baaab", vec{1,4} }, tester( `a+`, "baaab", vec(1,4) ),
tester{ `a*`, "baaab", vec{0,0} }, tester( `a*`, "baaab", vec(0,0) ),
tester{ `[a-z]+`, "abcd", vec{0,4} }, tester( `[a-z]+`, "abcd", vec(0,4) ),
tester{ `[^a-z]+`, "ab1234cd", vec{2,6} }, tester( `[^a-z]+`, "ab1234cd", vec(2,6) ),
tester{ `[a\-\]z]+`, "az]-bcz", vec{0,4} }, tester( `[a\-\]z]+`, "az]-bcz", vec(0,4) ),
tester{ `[日本語]+`, "日本語日本語", vec{0,18} }, tester( `[日本語]+`, "日本語日本語", vec(0,18) ),
tester{ `()`, "", vec{0,0, 0,0} }, tester( `()`, "", vec(0,0, 0,0) ),
tester{ `(a)`, "a", vec{0,1, 0,1} }, tester( `(a)`, "a", vec(0,1, 0,1) ),
tester{ `(.)(.)`, "日a", vec{0,4, 0,3, 3,4} }, tester( `(.)(.)`, "日a", vec(0,4, 0,3, 3,4) ),
tester{ `(.*)`, "", vec{0,0, 0,0} }, tester( `(.*)`, "", vec(0,0, 0,0) ),
tester{ `(.*)`, "abcd", vec{0,4, 0,4} }, tester( `(.*)`, "abcd", vec(0,4, 0,4) ),
tester{ `(..)(..)`, "abcd", vec{0,4, 0,2, 2,4} }, tester( `(..)(..)`, "abcd", vec(0,4, 0,2, 2,4) ),
tester{ `(([^xyz]*)(d))`, "abcd", vec{0,4, 0,4, 0,3, 3,4} }, tester( `(([^xyz]*)(d))`, "abcd", vec(0,4, 0,4, 0,3, 3,4) ),
tester{ `((a|b|c)*(d))`, "abcd", vec{0,4, 0,4, 2,3, 3,4} }, tester( `((a|b|c)*(d))`, "abcd", vec(0,4, 0,4, 2,3, 3,4) ),
tester{ `(((a|b|c)*)(d))`, "abcd", vec{0,4, 0,4, 0,3, 2,3, 3,4} }, tester( `(((a|b|c)*)(d))`, "abcd", vec(0,4, 0,4, 0,3, 2,3, 3,4) ),
tester{ `a*(|(b))c*`, "aacc", vec{0,4, 2,2, -1,-1} }, tester( `a*(|(b))c*`, "aacc", vec(0,4, 2,2, -1,-1) ),
} )
func compileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp { func compileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp {
re, err := regexp.Compile(expr); re, err := regexp.Compile(expr);

View file

@ -12,9 +12,9 @@ import (
) )
var ints = [...]int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586} var ints = [...]int(74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586)
var floats = [...]float{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8} var floats = [...]float(74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8)
var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"} var strings = [...]string("", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***")
func TestSortIntArray(t *testing.T) { func TestSortIntArray(t *testing.T) {
data := ints; data := ints;
@ -134,9 +134,9 @@ func lg(n int) int {
} }
func TestBentleyMcIlroy(t *testing.T) { func TestBentleyMcIlroy(t *testing.T) {
sizes := []int{100, 1023, 1024, 1025}; sizes := []int(100, 1023, 1024, 1025);
dists := []string{"sawtooth", "rand", "stagger", "plateau", "shuffle"}; dists := []string("sawtooth", "rand", "stagger", "plateau", "shuffle");
modes := []string{"copy", "reverse", "reverse1", "reverse2", "sort", "dither"}; modes := []string("copy", "reverse", "reverse1", "reverse2", "sort", "dither");
var tmp1, tmp2 [1025]int; var tmp1, tmp2 [1025]int;
for ni := 0; ni < len(sizes); ni++ { for ni := 0; ni < len(sizes); ni++ {
n := sizes[ni]; n := sizes[ni];
@ -205,7 +205,7 @@ func TestBentleyMcIlroy(t *testing.T) {
} }
desc := fmt.Sprintf("n=%d m=%d dist=%s mode=%s", n, m, dists[dist], modes[mode]); desc := fmt.Sprintf("n=%d m=%d dist=%s mode=%s", n, m, dists[dist], modes[mode]);
d := &testingData{desc, t, mdata[0:n], n*lg(n)*12/10, 0}; d := &testingData(desc, t, mdata[0:n], n*lg(n)*12/10, 0);
sort.Sort(d); sort.Sort(d);
// If we were testing C qsort, we'd have to make a copy // If we were testing C qsort, we'd have to make a copy

View file

@ -106,9 +106,9 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
} }
// decimal power of ten to binary power of two. // decimal power of ten to binary power of two.
var powtab = []int{ var powtab = []int(
1, 3, 6, 9, 13, 16, 19, 23, 26 1, 3, 6, 9, 13, 16, 19, 23, 26
} )
func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uint64, overflow bool) { func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uint64, overflow bool) {
var exp int; var exp int;
@ -232,14 +232,14 @@ func decimalAtof32Int(neg bool, d *decimal) float32 {
} }
// Exact powers of 10. // Exact powers of 10.
var float64pow10 = []float64 { var float64pow10 = []float64 (
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1e20, 1e21, 1e22 1e20, 1e21, 1e22
} )
var float32pow10 = []float32 { var float32pow10 = []float32 (
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10
} )
// If possible to convert decimal d to 64-bit float f exactly, // If possible to convert decimal d to 64-bit float f exactly,
// entirely in floating-point math, do so, avoiding the expense of decimalToFloatBits. // entirely in floating-point math, do so, avoiding the expense of decimalToFloatBits.

View file

@ -16,80 +16,80 @@ type atofTest struct {
err *os.Error; err *os.Error;
} }
var atoftests = []atofTest { var atoftests = []atofTest (
atofTest{ "", "0", os.EINVAL }, atofTest( "", "0", os.EINVAL ),
atofTest{ "1", "1", nil }, atofTest( "1", "1", nil ),
atofTest{ "+1", "1", nil }, atofTest( "+1", "1", nil ),
atofTest{ "1x", "0", os.EINVAL }, atofTest( "1x", "0", os.EINVAL ),
atofTest{ "1.1.", "0", os.EINVAL }, atofTest( "1.1.", "0", os.EINVAL ),
atofTest{ "1e23", "1e+23", nil }, atofTest( "1e23", "1e+23", nil ),
atofTest{ "100000000000000000000000", "1e+23", nil }, atofTest( "100000000000000000000000", "1e+23", nil ),
atofTest{ "1e-100", "1e-100", nil }, atofTest( "1e-100", "1e-100", nil ),
atofTest{ "123456700", "1.234567e+08", nil }, atofTest( "123456700", "1.234567e+08", nil ),
atofTest{ "99999999999999974834176", "9.999999999999997e+22", nil }, atofTest( "99999999999999974834176", "9.999999999999997e+22", nil ),
atofTest{ "100000000000000000000001", "1.0000000000000001e+23", nil }, atofTest( "100000000000000000000001", "1.0000000000000001e+23", nil ),
atofTest{ "100000000000000008388608", "1.0000000000000001e+23", nil }, atofTest( "100000000000000008388608", "1.0000000000000001e+23", nil ),
atofTest{ "100000000000000016777215", "1.0000000000000001e+23", nil }, atofTest( "100000000000000016777215", "1.0000000000000001e+23", nil ),
atofTest{ "100000000000000016777216", "1.0000000000000003e+23", nil }, atofTest( "100000000000000016777216", "1.0000000000000003e+23", nil ),
atofTest{ "-1", "-1", nil }, atofTest( "-1", "-1", nil ),
atofTest{ "-0", "-0", nil }, atofTest( "-0", "-0", nil ),
atofTest{ "1e-20", "1e-20", nil }, atofTest( "1e-20", "1e-20", nil ),
atofTest{ "625e-3", "0.625", nil }, atofTest( "625e-3", "0.625", nil ),
// largest float64 // largest float64
atofTest{ "1.7976931348623157e308", "1.7976931348623157e+308", nil }, atofTest( "1.7976931348623157e308", "1.7976931348623157e+308", nil ),
atofTest{ "-1.7976931348623157e308", "-1.7976931348623157e+308", nil }, atofTest( "-1.7976931348623157e308", "-1.7976931348623157e+308", nil ),
// next float64 - too large // next float64 - too large
atofTest{ "1.7976931348623159e308", "+Inf", os.ERANGE }, atofTest( "1.7976931348623159e308", "+Inf", os.ERANGE ),
atofTest{ "-1.7976931348623159e308", "-Inf", os.ERANGE }, atofTest( "-1.7976931348623159e308", "-Inf", os.ERANGE ),
// the border is ...158079 // the border is ...158079
// borderline - okay // borderline - okay
atofTest{ "1.7976931348623158e308", "1.7976931348623157e+308", nil }, atofTest( "1.7976931348623158e308", "1.7976931348623157e+308", nil ),
atofTest{ "-1.7976931348623158e308", "-1.7976931348623157e+308", nil }, atofTest( "-1.7976931348623158e308", "-1.7976931348623157e+308", nil ),
// borderline - too large // borderline - too large
atofTest{ "1.797693134862315808e308", "+Inf", os.ERANGE }, atofTest( "1.797693134862315808e308", "+Inf", os.ERANGE ),
atofTest{ "-1.797693134862315808e308", "-Inf", os.ERANGE }, atofTest( "-1.797693134862315808e308", "-Inf", os.ERANGE ),
// a little too large // a little too large
atofTest{ "1e308", "1e+308", nil }, atofTest( "1e308", "1e+308", nil ),
atofTest{ "2e308", "+Inf", os.ERANGE }, atofTest( "2e308", "+Inf", os.ERANGE ),
atofTest{ "1e309", "+Inf", os.ERANGE }, atofTest( "1e309", "+Inf", os.ERANGE ),
// way too large // way too large
atofTest{ "1e310", "+Inf", os.ERANGE }, atofTest( "1e310", "+Inf", os.ERANGE ),
atofTest{ "-1e310", "-Inf", os.ERANGE }, atofTest( "-1e310", "-Inf", os.ERANGE ),
atofTest{ "1e400", "+Inf", os.ERANGE }, atofTest( "1e400", "+Inf", os.ERANGE ),
atofTest{ "-1e400", "-Inf", os.ERANGE }, atofTest( "-1e400", "-Inf", os.ERANGE ),
atofTest{ "1e400000", "+Inf", os.ERANGE }, atofTest( "1e400000", "+Inf", os.ERANGE ),
atofTest{ "-1e400000", "-Inf", os.ERANGE }, atofTest( "-1e400000", "-Inf", os.ERANGE ),
// denormalized // denormalized
atofTest{ "1e-305", "1e-305", nil }, atofTest( "1e-305", "1e-305", nil ),
atofTest{ "1e-306", "1e-306", nil }, atofTest( "1e-306", "1e-306", nil ),
atofTest{ "1e-307", "1e-307", nil }, atofTest( "1e-307", "1e-307", nil ),
atofTest{ "1e-308", "1e-308", nil }, atofTest( "1e-308", "1e-308", nil ),
atofTest{ "1e-309", "1e-309", nil }, atofTest( "1e-309", "1e-309", nil ),
atofTest{ "1e-310", "1e-310", nil }, atofTest( "1e-310", "1e-310", nil ),
atofTest{ "1e-322", "1e-322", nil }, atofTest( "1e-322", "1e-322", nil ),
// smallest denormal // smallest denormal
atofTest{ "5e-324", "5e-324", nil }, atofTest( "5e-324", "5e-324", nil ),
// too small // too small
atofTest{ "4e-324", "0", nil }, atofTest( "4e-324", "0", nil ),
// way too small // way too small
atofTest{ "1e-350", "0", nil }, atofTest( "1e-350", "0", nil ),
atofTest{ "1e-400000", "0", nil }, atofTest( "1e-400000", "0", nil ),
// try to overflow exponent // try to overflow exponent
atofTest{ "1e-4294967296", "0", nil }, atofTest( "1e-4294967296", "0", nil ),
atofTest{ "1e+4294967296", "+Inf", os.ERANGE }, atofTest( "1e+4294967296", "+Inf", os.ERANGE ),
atofTest{ "1e-18446744073709551616", "0", nil }, atofTest( "1e-18446744073709551616", "0", nil ),
atofTest{ "1e+18446744073709551616", "+Inf", os.ERANGE }, atofTest( "1e+18446744073709551616", "+Inf", os.ERANGE ),
// Parse errors // Parse errors
atofTest{ "1e", "0", os.EINVAL }, atofTest( "1e", "0", os.EINVAL ),
atofTest{ "1e-", "0", os.EINVAL }, atofTest( "1e-", "0", os.EINVAL ),
atofTest{ ".e-1", "0", os.EINVAL }, atofTest( ".e-1", "0", os.EINVAL ),
} )
func testAtof(t *testing.T, opt bool) { func testAtof(t *testing.T, opt bool) {
oldopt := strconv.optimize; oldopt := strconv.optimize;

View file

@ -16,18 +16,18 @@ type atoui64Test struct {
err *os.Error; err *os.Error;
} }
var atoui64tests = []atoui64Test { var atoui64tests = []atoui64Test (
atoui64Test{ "", 0, os.EINVAL }, atoui64Test( "", 0, os.EINVAL ),
atoui64Test{ "0", 0, nil }, atoui64Test( "0", 0, nil ),
atoui64Test{ "1", 1, nil }, atoui64Test( "1", 1, nil ),
atoui64Test{ "12345", 12345, nil }, atoui64Test( "12345", 12345, nil ),
atoui64Test{ "012345", 0, os.EINVAL }, atoui64Test( "012345", 0, os.EINVAL ),
atoui64Test{ "12345x", 0, os.EINVAL }, atoui64Test( "12345x", 0, os.EINVAL ),
atoui64Test{ "98765432100", 98765432100, nil }, atoui64Test( "98765432100", 98765432100, nil ),
atoui64Test{ "18446744073709551615", 1<<64-1, nil }, atoui64Test( "18446744073709551615", 1<<64-1, nil ),
atoui64Test{ "18446744073709551616", 1<<64-1, os.ERANGE }, atoui64Test( "18446744073709551616", 1<<64-1, os.ERANGE ),
atoui64Test{ "18446744073709551620", 1<<64-1, os.ERANGE }, atoui64Test( "18446744073709551620", 1<<64-1, os.ERANGE ),
} )
type atoi64Test struct { type atoi64Test struct {
in string; in string;
@ -35,27 +35,27 @@ type atoi64Test struct {
err *os.Error; err *os.Error;
} }
var atoi64test = []atoi64Test { var atoi64test = []atoi64Test (
atoi64Test{ "", 0, os.EINVAL }, atoi64Test( "", 0, os.EINVAL ),
atoi64Test{ "0", 0, nil }, atoi64Test( "0", 0, nil ),
atoi64Test{ "-0", 0, nil }, atoi64Test( "-0", 0, nil ),
atoi64Test{ "1", 1, nil }, atoi64Test( "1", 1, nil ),
atoi64Test{ "-1", -1, nil }, atoi64Test( "-1", -1, nil ),
atoi64Test{ "12345", 12345, nil }, atoi64Test( "12345", 12345, nil ),
atoi64Test{ "-12345", -12345, nil }, atoi64Test( "-12345", -12345, nil ),
atoi64Test{ "012345", 0, os.EINVAL }, atoi64Test( "012345", 0, os.EINVAL ),
atoi64Test{ "-012345", 0, os.EINVAL }, atoi64Test( "-012345", 0, os.EINVAL ),
atoi64Test{ "12345x", 0, os.EINVAL }, atoi64Test( "12345x", 0, os.EINVAL ),
atoi64Test{ "-12345x", 0, os.EINVAL }, atoi64Test( "-12345x", 0, os.EINVAL ),
atoi64Test{ "98765432100", 98765432100, nil }, atoi64Test( "98765432100", 98765432100, nil ),
atoi64Test{ "-98765432100", -98765432100, nil }, atoi64Test( "-98765432100", -98765432100, nil ),
atoi64Test{ "9223372036854775807", 1<<63-1, nil }, atoi64Test( "9223372036854775807", 1<<63-1, nil ),
atoi64Test{ "-9223372036854775807", -(1<<63-1), nil }, atoi64Test( "-9223372036854775807", -(1<<63-1), nil ),
atoi64Test{ "9223372036854775808", 1<<63-1, os.ERANGE }, atoi64Test( "9223372036854775808", 1<<63-1, os.ERANGE ),
atoi64Test{ "-9223372036854775808", -1<<63, nil }, atoi64Test( "-9223372036854775808", -1<<63, nil ),
atoi64Test{ "9223372036854775809", 1<<63-1, os.ERANGE }, atoi64Test( "9223372036854775809", 1<<63-1, os.ERANGE ),
atoi64Test{ "-9223372036854775809", -1<<63, os.ERANGE }, atoi64Test( "-9223372036854775809", -1<<63, os.ERANGE ),
} )
type atoui32Test struct { type atoui32Test struct {
in string; in string;
@ -63,17 +63,17 @@ type atoui32Test struct {
err *os.Error; err *os.Error;
} }
var atoui32tests = []atoui32Test { var atoui32tests = []atoui32Test (
atoui32Test{ "", 0, os.EINVAL }, atoui32Test( "", 0, os.EINVAL ),
atoui32Test{ "0", 0, nil }, atoui32Test( "0", 0, nil ),
atoui32Test{ "1", 1, nil }, atoui32Test( "1", 1, nil ),
atoui32Test{ "12345", 12345, nil }, atoui32Test( "12345", 12345, nil ),
atoui32Test{ "012345", 0, os.EINVAL }, atoui32Test( "012345", 0, os.EINVAL ),
atoui32Test{ "12345x", 0, os.EINVAL }, atoui32Test( "12345x", 0, os.EINVAL ),
atoui32Test{ "987654321", 987654321, nil }, atoui32Test( "987654321", 987654321, nil ),
atoui32Test{ "4294967295", 1<<32-1, nil }, atoui32Test( "4294967295", 1<<32-1, nil ),
atoui32Test{ "4294967296", 1<<32-1, os.ERANGE }, atoui32Test( "4294967296", 1<<32-1, os.ERANGE ),
} )
type atoi32Test struct { type atoi32Test struct {
in string; in string;
@ -81,27 +81,27 @@ type atoi32Test struct {
err *os.Error; err *os.Error;
} }
var atoi32tests = []atoi32Test { var atoi32tests = []atoi32Test (
atoi32Test{ "", 0, os.EINVAL }, atoi32Test( "", 0, os.EINVAL ),
atoi32Test{ "0", 0, nil }, atoi32Test( "0", 0, nil ),
atoi32Test{ "-0", 0, nil }, atoi32Test( "-0", 0, nil ),
atoi32Test{ "1", 1, nil }, atoi32Test( "1", 1, nil ),
atoi32Test{ "-1", -1, nil }, atoi32Test( "-1", -1, nil ),
atoi32Test{ "12345", 12345, nil }, atoi32Test( "12345", 12345, nil ),
atoi32Test{ "-12345", -12345, nil }, atoi32Test( "-12345", -12345, nil ),
atoi32Test{ "012345", 0, os.EINVAL }, atoi32Test( "012345", 0, os.EINVAL ),
atoi32Test{ "-012345", 0, os.EINVAL }, atoi32Test( "-012345", 0, os.EINVAL ),
atoi32Test{ "12345x", 0, os.EINVAL }, atoi32Test( "12345x", 0, os.EINVAL ),
atoi32Test{ "-12345x", 0, os.EINVAL }, atoi32Test( "-12345x", 0, os.EINVAL ),
atoi32Test{ "987654321", 987654321, nil }, atoi32Test( "987654321", 987654321, nil ),
atoi32Test{ "-987654321", -987654321, nil }, atoi32Test( "-987654321", -987654321, nil ),
atoi32Test{ "2147483647", 1<<31-1, nil }, atoi32Test( "2147483647", 1<<31-1, nil ),
atoi32Test{ "-2147483647", -(1<<31-1), nil }, atoi32Test( "-2147483647", -(1<<31-1), nil ),
atoi32Test{ "2147483648", 1<<31-1, os.ERANGE }, atoi32Test( "2147483648", 1<<31-1, os.ERANGE ),
atoi32Test{ "-2147483648", -1<<31, nil }, atoi32Test( "-2147483648", -1<<31, nil ),
atoi32Test{ "2147483649", 1<<31-1, os.ERANGE }, atoi32Test( "2147483649", 1<<31-1, os.ERANGE ),
atoi32Test{ "-2147483649", -1<<31, os.ERANGE }, atoi32Test( "-2147483649", -1<<31, os.ERANGE ),
} )
func TestAtoui64(t *testing.T) { func TestAtoui64(t *testing.T) {
for i := 0; i < len(atoui64tests); i++ { for i := 0; i < len(atoui64tests); i++ {

View file

@ -192,7 +192,7 @@ type leftCheat struct {
cutoff string; // minus one digit if original < a. cutoff string; // minus one digit if original < a.
} }
var leftcheats = []leftCheat { var leftcheats = []leftCheat (
// Leading digits of 1/2^i = 5^i. // Leading digits of 1/2^i = 5^i.
// 5^23 is not an exact 64-bit floating point number, // 5^23 is not an exact 64-bit floating point number,
// so have to use bc for the math. // so have to use bc for the math.
@ -205,35 +205,35 @@ var leftcheats = []leftCheat {
int(log2*NR+1), $0, 2**NR) int(log2*NR+1), $0, 2**NR)
}' }'
*/ */
leftCheat{ 0, "" }, leftCheat( 0, "" ),
leftCheat{ 1, "5" }, // * 2 leftCheat( 1, "5" ), // * 2
leftCheat{ 1, "25" }, // * 4 leftCheat( 1, "25" ), // * 4
leftCheat{ 1, "125" }, // * 8 leftCheat( 1, "125" ), // * 8
leftCheat{ 2, "625" }, // * 16 leftCheat( 2, "625" ), // * 16
leftCheat{ 2, "3125" }, // * 32 leftCheat( 2, "3125" ), // * 32
leftCheat{ 2, "15625" }, // * 64 leftCheat( 2, "15625" ), // * 64
leftCheat{ 3, "78125" }, // * 128 leftCheat( 3, "78125" ), // * 128
leftCheat{ 3, "390625" }, // * 256 leftCheat( 3, "390625" ), // * 256
leftCheat{ 3, "1953125" }, // * 512 leftCheat( 3, "1953125" ), // * 512
leftCheat{ 4, "9765625" }, // * 1024 leftCheat( 4, "9765625" ), // * 1024
leftCheat{ 4, "48828125" }, // * 2048 leftCheat( 4, "48828125" ), // * 2048
leftCheat{ 4, "244140625" }, // * 4096 leftCheat( 4, "244140625" ), // * 4096
leftCheat{ 4, "1220703125" }, // * 8192 leftCheat( 4, "1220703125" ), // * 8192
leftCheat{ 5, "6103515625" }, // * 16384 leftCheat( 5, "6103515625" ), // * 16384
leftCheat{ 5, "30517578125" }, // * 32768 leftCheat( 5, "30517578125" ), // * 32768
leftCheat{ 5, "152587890625" }, // * 65536 leftCheat( 5, "152587890625" ), // * 65536
leftCheat{ 6, "762939453125" }, // * 131072 leftCheat( 6, "762939453125" ), // * 131072
leftCheat{ 6, "3814697265625" }, // * 262144 leftCheat( 6, "3814697265625" ), // * 262144
leftCheat{ 6, "19073486328125" }, // * 524288 leftCheat( 6, "19073486328125" ), // * 524288
leftCheat{ 7, "95367431640625" }, // * 1048576 leftCheat( 7, "95367431640625" ), // * 1048576
leftCheat{ 7, "476837158203125" }, // * 2097152 leftCheat( 7, "476837158203125" ), // * 2097152
leftCheat{ 7, "2384185791015625" }, // * 4194304 leftCheat( 7, "2384185791015625" ), // * 4194304
leftCheat{ 7, "11920928955078125" }, // * 8388608 leftCheat( 7, "11920928955078125" ), // * 8388608
leftCheat{ 8, "59604644775390625" }, // * 16777216 leftCheat( 8, "59604644775390625" ), // * 16777216
leftCheat{ 8, "298023223876953125" }, // * 33554432 leftCheat( 8, "298023223876953125" ), // * 33554432
leftCheat{ 8, "1490116119384765625" }, // * 67108864 leftCheat( 8, "1490116119384765625" ), // * 67108864
leftCheat{ 9, "7450580596923828125" }, // * 134217728 leftCheat( 9, "7450580596923828125" ), // * 134217728
} )
// Is the leading prefix of b lexicographically less than s? // Is the leading prefix of b lexicographically less than s?
func prefixIsLessThan(b []byte, s string) bool { func prefixIsLessThan(b []byte, s string) bool {

View file

@ -16,18 +16,18 @@ type shiftTest struct {
out string; out string;
} }
var shifttests = []shiftTest { var shifttests = []shiftTest (
shiftTest{ 0, -100, "0" }, shiftTest( 0, -100, "0" ),
shiftTest{ 0, 100, "0" }, shiftTest( 0, 100, "0" ),
shiftTest{ 1, 100, "1267650600228229401496703205376" }, shiftTest( 1, 100, "1267650600228229401496703205376" ),
shiftTest{ 1, -100, shiftTest( 1, -100,
"0.00000000000000000000000000000078886090522101180541" "0.00000000000000000000000000000078886090522101180541"
"17285652827862296732064351090230047702789306640625" }, "17285652827862296732064351090230047702789306640625" ),
shiftTest{ 12345678, 8, "3160493568" }, shiftTest( 12345678, 8, "3160493568" ),
shiftTest{ 12345678, -8, "48225.3046875" }, shiftTest( 12345678, -8, "48225.3046875" ),
shiftTest{ 195312, 9, "99999744" }, shiftTest( 195312, 9, "99999744" ),
shiftTest{ 1953125, 9, "1000000000" }, shiftTest( 1953125, 9, "1000000000" ),
} )
func TestDecimalShift(t *testing.T) { func TestDecimalShift(t *testing.T) {
ok := true; ok := true;
@ -48,23 +48,23 @@ type roundTest struct {
int uint64; int uint64;
} }
var roundtests = []roundTest { var roundtests = []roundTest (
roundTest{ 0, 4, "0", "0", "0", 0 }, roundTest( 0, 4, "0", "0", "0", 0 ),
roundTest{ 12344999, 4, "12340000", "12340000", "12350000", 12340000 }, roundTest( 12344999, 4, "12340000", "12340000", "12350000", 12340000 ),
roundTest{ 12345000, 4, "12340000", "12340000", "12350000", 12340000 }, roundTest( 12345000, 4, "12340000", "12340000", "12350000", 12340000 ),
roundTest{ 12345001, 4, "12340000", "12350000", "12350000", 12350000 }, roundTest( 12345001, 4, "12340000", "12350000", "12350000", 12350000 ),
roundTest{ 23454999, 4, "23450000", "23450000", "23460000", 23450000 }, roundTest( 23454999, 4, "23450000", "23450000", "23460000", 23450000 ),
roundTest{ 23455000, 4, "23450000", "23460000", "23460000", 23460000 }, roundTest( 23455000, 4, "23450000", "23460000", "23460000", 23460000 ),
roundTest{ 23455001, 4, "23450000", "23460000", "23460000", 23460000 }, roundTest( 23455001, 4, "23450000", "23460000", "23460000", 23460000 ),
roundTest{ 99994999, 4, "99990000", "99990000", "100000000", 99990000 }, roundTest( 99994999, 4, "99990000", "99990000", "100000000", 99990000 ),
roundTest{ 99995000, 4, "99990000", "100000000", "100000000", 100000000 }, roundTest( 99995000, 4, "99990000", "100000000", "100000000", 100000000 ),
roundTest{ 99999999, 4, "99990000", "100000000", "100000000", 100000000 }, roundTest( 99999999, 4, "99990000", "100000000", "100000000", 100000000 ),
roundTest{ 12994999, 4, "12990000", "12990000", "13000000", 12990000 }, roundTest( 12994999, 4, "12990000", "12990000", "13000000", 12990000 ),
roundTest{ 12995000, 4, "12990000", "13000000", "13000000", 13000000 }, roundTest( 12995000, 4, "12990000", "13000000", "13000000", 13000000 ),
roundTest{ 12999999, 4, "12990000", "13000000", "13000000", 13000000 }, roundTest( 12999999, 4, "12990000", "13000000", "13000000", 13000000 ),
} )
func TestDecimalRound(t *testing.T) { func TestDecimalRound(t *testing.T) {
for i := 0; i < len(roundtests); i++ { for i := 0; i < len(roundtests); i++ {
@ -93,18 +93,18 @@ type roundIntTest struct {
int uint64; int uint64;
} }
var roundinttests = []roundIntTest { var roundinttests = []roundIntTest (
roundIntTest{ 0, 100, 0 }, roundIntTest( 0, 100, 0 ),
roundIntTest{ 512, -8, 2 }, roundIntTest( 512, -8, 2 ),
roundIntTest{ 513, -8, 2 }, roundIntTest( 513, -8, 2 ),
roundIntTest{ 640, -8, 2 }, roundIntTest( 640, -8, 2 ),
roundIntTest{ 641, -8, 3 }, roundIntTest( 641, -8, 3 ),
roundIntTest{ 384, -8, 2 }, roundIntTest( 384, -8, 2 ),
roundIntTest{ 385, -8, 2 }, roundIntTest( 385, -8, 2 ),
roundIntTest{ 383, -8, 1 }, roundIntTest( 383, -8, 1 ),
roundIntTest{ 1, 100, 1<<64-1 }, roundIntTest( 1, 100, 1<<64-1 ),
roundIntTest{ 1000, 0, 1000 }, roundIntTest( 1000, 0, 1000 ),
} )
func TestDecimalRoundedInteger(t *testing.T) { func TestDecimalRoundedInteger(t *testing.T) {
for i := 0; i < len(roundinttests); i++ { for i := 0; i < len(roundinttests); i++ {

View file

@ -21,8 +21,8 @@ type floatInfo struct {
expbits uint; expbits uint;
bias int; bias int;
} }
var float32info = floatInfo{ 23, 8, -127 } var float32info = floatInfo( 23, 8, -127 )
var float64info = floatInfo{ 52, 11, -1023 } var float64info = floatInfo( 52, 11, -1023 )
func fmtB(neg bool, mant uint64, exp int, flt *floatInfo) string func fmtB(neg bool, mant uint64, exp int, flt *floatInfo) string
func fmtE(neg bool, d *decimal, prec int) string func fmtE(neg bool, d *decimal, prec int) string

View file

@ -24,80 +24,80 @@ const (
above1e23 = 100000000000000008388608; above1e23 = 100000000000000008388608;
) )
var ftoatests = []ftoaTest { var ftoatests = []ftoaTest (
ftoaTest{ 1, 'e', 5, "1.00000e+00" }, ftoaTest( 1, 'e', 5, "1.00000e+00" ),
ftoaTest{ 1, 'f', 5, "1.00000" }, ftoaTest( 1, 'f', 5, "1.00000" ),
ftoaTest{ 1, 'g', 5, "1" }, ftoaTest( 1, 'g', 5, "1" ),
ftoaTest{ 1, 'g', -1, "1" }, ftoaTest( 1, 'g', -1, "1" ),
ftoaTest{ 20, 'g', -1, "20" }, ftoaTest( 20, 'g', -1, "20" ),
ftoaTest{ 1234567.8, 'g', -1, "1.2345678e+06" }, ftoaTest( 1234567.8, 'g', -1, "1.2345678e+06" ),
ftoaTest{ 200000, 'g', -1, "200000" }, ftoaTest( 200000, 'g', -1, "200000" ),
ftoaTest{ 2000000, 'g', -1, "2e+06" }, ftoaTest( 2000000, 'g', -1, "2e+06" ),
ftoaTest{ 0, 'e', 5, "0.00000e+00" }, ftoaTest( 0, 'e', 5, "0.00000e+00" ),
ftoaTest{ 0, 'f', 5, "0.00000" }, ftoaTest( 0, 'f', 5, "0.00000" ),
ftoaTest{ 0, 'g', 5, "0" }, ftoaTest( 0, 'g', 5, "0" ),
ftoaTest{ 0, 'g', -1, "0" }, ftoaTest( 0, 'g', -1, "0" ),
ftoaTest{ -1, 'e', 5, "-1.00000e+00" }, ftoaTest( -1, 'e', 5, "-1.00000e+00" ),
ftoaTest{ -1, 'f', 5, "-1.00000" }, ftoaTest( -1, 'f', 5, "-1.00000" ),
ftoaTest{ -1, 'g', 5, "-1" }, ftoaTest( -1, 'g', 5, "-1" ),
ftoaTest{ -1, 'g', -1, "-1" }, ftoaTest( -1, 'g', -1, "-1" ),
ftoaTest{ 12, 'e', 5, "1.20000e+01" }, ftoaTest( 12, 'e', 5, "1.20000e+01" ),
ftoaTest{ 12, 'f', 5, "12.00000" }, ftoaTest( 12, 'f', 5, "12.00000" ),
ftoaTest{ 12, 'g', 5, "12" }, ftoaTest( 12, 'g', 5, "12" ),
ftoaTest{ 12, 'g', -1, "12" }, ftoaTest( 12, 'g', -1, "12" ),
ftoaTest{ 123456700, 'e', 5, "1.23457e+08" }, ftoaTest( 123456700, 'e', 5, "1.23457e+08" ),
ftoaTest{ 123456700, 'f', 5, "123456700.00000" }, ftoaTest( 123456700, 'f', 5, "123456700.00000" ),
ftoaTest{ 123456700, 'g', 5, "1.2346e+08" }, ftoaTest( 123456700, 'g', 5, "1.2346e+08" ),
ftoaTest{ 123456700, 'g', -1, "1.234567e+08" }, ftoaTest( 123456700, 'g', -1, "1.234567e+08" ),
ftoaTest{ 1.2345e6, 'e', 5, "1.23450e+06" }, ftoaTest( 1.2345e6, 'e', 5, "1.23450e+06" ),
ftoaTest{ 1.2345e6, 'f', 5, "1234500.00000" }, ftoaTest( 1.2345e6, 'f', 5, "1234500.00000" ),
ftoaTest{ 1.2345e6, 'g', 5, "1.2345e+06" }, ftoaTest( 1.2345e6, 'g', 5, "1.2345e+06" ),
ftoaTest{ 1e23, 'e', 17, "9.99999999999999916e+22" }, ftoaTest( 1e23, 'e', 17, "9.99999999999999916e+22" ),
ftoaTest{ 1e23, 'f', 17, "99999999999999991611392.00000000000000000" }, ftoaTest( 1e23, 'f', 17, "99999999999999991611392.00000000000000000" ),
ftoaTest{ 1e23, 'g', 17, "9.9999999999999992e+22" }, ftoaTest( 1e23, 'g', 17, "9.9999999999999992e+22" ),
ftoaTest{ 1e23, 'e', -1, "1e+23" }, ftoaTest( 1e23, 'e', -1, "1e+23" ),
ftoaTest{ 1e23, 'f', -1, "100000000000000000000000" }, ftoaTest( 1e23, 'f', -1, "100000000000000000000000" ),
ftoaTest{ 1e23, 'g', -1, "1e+23" }, ftoaTest( 1e23, 'g', -1, "1e+23" ),
ftoaTest{ below1e23, 'e', 17, "9.99999999999999748e+22" }, ftoaTest( below1e23, 'e', 17, "9.99999999999999748e+22" ),
ftoaTest{ below1e23, 'f', 17, "99999999999999974834176.00000000000000000" }, ftoaTest( below1e23, 'f', 17, "99999999999999974834176.00000000000000000" ),
ftoaTest{ below1e23, 'g', 17, "9.9999999999999975e+22" }, ftoaTest( below1e23, 'g', 17, "9.9999999999999975e+22" ),
ftoaTest{ below1e23, 'e', -1, "9.999999999999997e+22" }, ftoaTest( below1e23, 'e', -1, "9.999999999999997e+22" ),
ftoaTest{ below1e23, 'f', -1, "99999999999999970000000" }, ftoaTest( below1e23, 'f', -1, "99999999999999970000000" ),
ftoaTest{ below1e23, 'g', -1, "9.999999999999997e+22" }, ftoaTest( below1e23, 'g', -1, "9.999999999999997e+22" ),
ftoaTest{ above1e23, 'e', 17, "1.00000000000000008e+23" }, ftoaTest( above1e23, 'e', 17, "1.00000000000000008e+23" ),
ftoaTest{ above1e23, 'f', 17, "100000000000000008388608.00000000000000000" }, ftoaTest( above1e23, 'f', 17, "100000000000000008388608.00000000000000000" ),
ftoaTest{ above1e23, 'g', 17, "1.0000000000000001e+23" }, ftoaTest( above1e23, 'g', 17, "1.0000000000000001e+23" ),
ftoaTest{ above1e23, 'e', -1, "1.0000000000000001e+23" }, ftoaTest( above1e23, 'e', -1, "1.0000000000000001e+23" ),
ftoaTest{ above1e23, 'f', -1, "100000000000000010000000" }, ftoaTest( above1e23, 'f', -1, "100000000000000010000000" ),
ftoaTest{ above1e23, 'g', -1, "1.0000000000000001e+23" }, ftoaTest( above1e23, 'g', -1, "1.0000000000000001e+23" ),
ftoaTest{ fdiv(5e-304, 1e20), 'g', -1, "5e-324" }, ftoaTest( fdiv(5e-304, 1e20), 'g', -1, "5e-324" ),
ftoaTest{ fdiv(-5e-304, 1e20), 'g', -1, "-5e-324" }, ftoaTest( fdiv(-5e-304, 1e20), 'g', -1, "-5e-324" ),
ftoaTest{ 32, 'g', -1, "32" }, ftoaTest( 32, 'g', -1, "32" ),
ftoaTest{ 32, 'g', 0, "3e+01" }, ftoaTest( 32, 'g', 0, "3e+01" ),
ftoaTest{ 100, 'x', -1, "%x" }, ftoaTest( 100, 'x', -1, "%x" ),
ftoaTest{ math.NaN(), 'g', -1, "NaN" }, ftoaTest( math.NaN(), 'g', -1, "NaN" ),
ftoaTest{ -math.NaN(), 'g', -1, "NaN" }, ftoaTest( -math.NaN(), 'g', -1, "NaN" ),
ftoaTest{ math.Inf(0), 'g', -1, "+Inf" }, ftoaTest( math.Inf(0), 'g', -1, "+Inf" ),
ftoaTest{ math.Inf(-1), 'g', -1, "-Inf" }, ftoaTest( math.Inf(-1), 'g', -1, "-Inf" ),
ftoaTest{ -math.Inf(0), 'g', -1, "-Inf" }, ftoaTest( -math.Inf(0), 'g', -1, "-Inf" ),
ftoaTest{ -1, 'b', -1, "-4503599627370496p-52" }, ftoaTest( -1, 'b', -1, "-4503599627370496p-52" ),
} )
func TestFtoa(t *testing.T) { func TestFtoa(t *testing.T) {
if strconv.FloatSize != 32 { if strconv.FloatSize != 32 {

View file

@ -16,29 +16,29 @@ type itoa64Test struct {
out string; out string;
} }
var itoa64tests = []itoa64Test { var itoa64tests = []itoa64Test (
itoa64Test{ 0, "0" }, itoa64Test( 0, "0" ),
itoa64Test{ 1, "1" }, itoa64Test( 1, "1" ),
itoa64Test{ -1, "-1" }, itoa64Test( -1, "-1" ),
itoa64Test{ 12345678, "12345678" }, itoa64Test( 12345678, "12345678" ),
itoa64Test{ -987654321, "-987654321" }, itoa64Test( -987654321, "-987654321" ),
itoa64Test{ 1<<31-1, "2147483647" }, itoa64Test( 1<<31-1, "2147483647" ),
itoa64Test{ -1<<31+1, "-2147483647" }, itoa64Test( -1<<31+1, "-2147483647" ),
itoa64Test{ 1<<31, "2147483648" }, itoa64Test( 1<<31, "2147483648" ),
itoa64Test{ -1<<31, "-2147483648" }, itoa64Test( -1<<31, "-2147483648" ),
itoa64Test{ 1<<31+1, "2147483649" }, itoa64Test( 1<<31+1, "2147483649" ),
itoa64Test{ -1<<31-1, "-2147483649" }, itoa64Test( -1<<31-1, "-2147483649" ),
itoa64Test{ 1<<32-1, "4294967295" }, itoa64Test( 1<<32-1, "4294967295" ),
itoa64Test{ -1<<32+1, "-4294967295" }, itoa64Test( -1<<32+1, "-4294967295" ),
itoa64Test{ 1<<32, "4294967296" }, itoa64Test( 1<<32, "4294967296" ),
itoa64Test{ -1<<32, "-4294967296" }, itoa64Test( -1<<32, "-4294967296" ),
itoa64Test{ 1<<32+1, "4294967297" }, itoa64Test( 1<<32+1, "4294967297" ),
itoa64Test{ -1<<32-1, "-4294967297" }, itoa64Test( -1<<32-1, "-4294967297" ),
itoa64Test{ 1<<50, "1125899906842624" }, itoa64Test( 1<<50, "1125899906842624" ),
itoa64Test{ 1<<63-1, "9223372036854775807" }, itoa64Test( 1<<63-1, "9223372036854775807" ),
itoa64Test{ -1<<63+1, "-9223372036854775807" }, itoa64Test( -1<<63+1, "-9223372036854775807" ),
itoa64Test{ -1<<63, "-9223372036854775808" }, itoa64Test( -1<<63, "-9223372036854775808" ),
} )
func TestItoa(t *testing.T) { func TestItoa(t *testing.T) {
for i := 0; i < len(itoa64tests); i++ { for i := 0; i < len(itoa64tests); i++ {
@ -65,11 +65,11 @@ type uitoa64Test struct {
} }
// TODO: should be able to call this atoui64tests. // TODO: should be able to call this atoui64tests.
var uitoa64tests = []uitoa64Test { var uitoa64tests = []uitoa64Test (
uitoa64Test{ 1<<63-1, "9223372036854775807" }, uitoa64Test( 1<<63-1, "9223372036854775807" ),
uitoa64Test{ 1<<63, "9223372036854775808" }, uitoa64Test( 1<<63, "9223372036854775808" ),
uitoa64Test{ 1<<63+1, "9223372036854775809" }, uitoa64Test( 1<<63+1, "9223372036854775809" ),
uitoa64Test{ 1<<64-2, "18446744073709551614" }, uitoa64Test( 1<<64-2, "18446744073709551614" ),
uitoa64Test{ 1<<64-1, "18446744073709551615" }, uitoa64Test( 1<<64-1, "18446744073709551615" ),
} )

View file

@ -14,14 +14,14 @@ type quoteTest struct {
out string; out string;
} }
var quotetests = []quoteTest { var quotetests = []quoteTest (
quoteTest{ "\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"` }, quoteTest( "\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"` ),
quoteTest{ "\\", `"\\"` }, quoteTest( "\\", `"\\"` ),
quoteTest{ "abc\xffdef", `"abc\xffdef"` }, quoteTest( "abc\xffdef", `"abc\xffdef"` ),
quoteTest{ "\u263a", `"\u263a"` }, quoteTest( "\u263a", `"\u263a"` ),
quoteTest{ "\U0010ffff", `"\U0010ffff"` }, quoteTest( "\U0010ffff", `"\U0010ffff"` ),
quoteTest{ "\x04", `"\x04"` }, quoteTest( "\x04", `"\x04"` ),
} )
func TestQuote(t *testing.T) { func TestQuote(t *testing.T) {
for i := 0; i < len(quotetests); i++ { for i := 0; i < len(quotetests); i++ {
@ -37,46 +37,46 @@ type canBackquoteTest struct {
out bool; out bool;
} }
var canbackquotetests = []canBackquoteTest { var canbackquotetests = []canBackquoteTest (
canBackquoteTest{ "`", false }, canBackquoteTest( "`", false ),
canBackquoteTest{ string(0), false }, canBackquoteTest( string(0), false ),
canBackquoteTest{ string(1), false }, canBackquoteTest( string(1), false ),
canBackquoteTest{ string(2), false }, canBackquoteTest( string(2), false ),
canBackquoteTest{ string(3), false }, canBackquoteTest( string(3), false ),
canBackquoteTest{ string(4), false }, canBackquoteTest( string(4), false ),
canBackquoteTest{ string(5), false }, canBackquoteTest( string(5), false ),
canBackquoteTest{ string(6), false }, canBackquoteTest( string(6), false ),
canBackquoteTest{ string(7), false }, canBackquoteTest( string(7), false ),
canBackquoteTest{ string(8), false }, canBackquoteTest( string(8), false ),
canBackquoteTest{ string(9), false }, canBackquoteTest( string(9), false ),
canBackquoteTest{ string(10), false }, canBackquoteTest( string(10), false ),
canBackquoteTest{ string(11), false }, canBackquoteTest( string(11), false ),
canBackquoteTest{ string(12), false }, canBackquoteTest( string(12), false ),
canBackquoteTest{ string(13), false }, canBackquoteTest( string(13), false ),
canBackquoteTest{ string(14), false }, canBackquoteTest( string(14), false ),
canBackquoteTest{ string(15), false }, canBackquoteTest( string(15), false ),
canBackquoteTest{ string(16), false }, canBackquoteTest( string(16), false ),
canBackquoteTest{ string(17), false }, canBackquoteTest( string(17), false ),
canBackquoteTest{ string(18), false }, canBackquoteTest( string(18), false ),
canBackquoteTest{ string(19), false }, canBackquoteTest( string(19), false ),
canBackquoteTest{ string(20), false }, canBackquoteTest( string(20), false ),
canBackquoteTest{ string(21), false }, canBackquoteTest( string(21), false ),
canBackquoteTest{ string(22), false }, canBackquoteTest( string(22), false ),
canBackquoteTest{ string(23), false }, canBackquoteTest( string(23), false ),
canBackquoteTest{ string(24), false }, canBackquoteTest( string(24), false ),
canBackquoteTest{ string(25), false }, canBackquoteTest( string(25), false ),
canBackquoteTest{ string(26), false }, canBackquoteTest( string(26), false ),
canBackquoteTest{ string(27), false }, canBackquoteTest( string(27), false ),
canBackquoteTest{ string(28), false }, canBackquoteTest( string(28), false ),
canBackquoteTest{ string(29), false }, canBackquoteTest( string(29), false ),
canBackquoteTest{ string(30), false }, canBackquoteTest( string(30), false ),
canBackquoteTest{ string(31), false }, canBackquoteTest( string(31), false ),
canBackquoteTest{ `' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true }, canBackquoteTest( `' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true ),
canBackquoteTest{ `0123456789`, true }, canBackquoteTest( `0123456789`, true ),
canBackquoteTest{ `ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true }, canBackquoteTest( `ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true ),
canBackquoteTest{ `abcdefghijklmnopqrstuvwxyz`, true }, canBackquoteTest( `abcdefghijklmnopqrstuvwxyz`, true ),
canBackquoteTest{ ``, true }, canBackquoteTest( ``, true ),
} )
func TestCanBackquote(t *testing.T) { func TestCanBackquote(t *testing.T) {
for i := 0; i < len(canbackquotetests); i++ { for i := 0; i < len(canbackquotetests); i++ {

View file

@ -30,10 +30,10 @@ type ExplodeTest struct {
s string; s string;
a []string; a []string;
} }
var explodetests = []ExplodeTest { var explodetests = []ExplodeTest (
ExplodeTest{ abcd, []string{"a", "b", "c", "d"} }, ExplodeTest( abcd, []string("a", "b", "c", "d") ),
ExplodeTest{ faces, []string{"☺", "☻", "☹" } }, ExplodeTest( faces, []string("☺", "☻", "☹" ) ),
} )
func TestExplode(t *testing.T) { func TestExplode(t *testing.T) {
for i := 0; i < len(explodetests); i++ { for i := 0; i < len(explodetests); i++ {
tt := explodetests[i]; tt := explodetests[i];
@ -54,16 +54,16 @@ type SplitTest struct {
sep string; sep string;
a []string; a []string;
} }
var splittests = []SplitTest { var splittests = []SplitTest (
SplitTest{ abcd, "a", []string{"", "bcd"} }, SplitTest( abcd, "a", []string("", "bcd") ),
SplitTest{ abcd, "z", []string{"abcd"} }, SplitTest( abcd, "z", []string("abcd") ),
SplitTest{ abcd, "", []string{"a", "b", "c", "d"} }, SplitTest( abcd, "", []string("a", "b", "c", "d") ),
SplitTest{ commas, ",", []string{"1", "2", "3", "4"} }, SplitTest( commas, ",", []string("1", "2", "3", "4") ),
SplitTest{ dots, "...", []string{"1", ".2", ".3", ".4"} }, SplitTest( dots, "...", []string("1", ".2", ".3", ".4") ),
SplitTest{ faces, "☹", []string{"☺☻", ""} }, SplitTest( faces, "☹", []string("☺☻", "") ),
SplitTest{ faces, "~", []string{faces} }, SplitTest( faces, "~", []string(faces) ),
SplitTest{ faces, "", []string{"☺", "☻", "☹"} }, SplitTest( faces, "", []string("☺", "☻", "☹") ),
} )
func TestSplit(t *testing.T) { func TestSplit(t *testing.T) {
for i := 0; i < len(splittests); i++ { for i := 0; i < len(splittests); i++ {
tt := splittests[i]; tt := splittests[i];

View file

@ -202,7 +202,7 @@ func (b *Writer) write0(buf []byte) *os.Error {
} }
var newline = []byte{'\n'} var newline = []byte('\n')
func (b *Writer) writePadding(textw, cellw int) (err *os.Error) { func (b *Writer) writePadding(textw, cellw int) (err *os.Error) {
if b.padbytes[0] == '\t' { if b.padbytes[0] == '\t' {

View file

@ -46,12 +46,12 @@ type Time struct {
Zone string; Zone string;
} }
var nonleapyear = []int{ var nonleapyear = []int(
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
} )
var leapyear = []int{ var leapyear = []int(
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
} )
func months(year int64) []int { func months(year int64) []int {
if year%4 == 0 && (year%100 != 0 || year%400 == 0) { if year%4 == 0 && (year%100 != 0 || year%400 == 0) {
@ -221,7 +221,7 @@ func (t *Time) Seconds() int64 {
return sec return sec
} }
var _LongDayNames = []string{ var _LongDayNames = []string(
"Sunday", "Sunday",
"Monday", "Monday",
"Tuesday", "Tuesday",
@ -229,9 +229,9 @@ var _LongDayNames = []string{
"Thursday", "Thursday",
"Friday", "Friday",
"Saturday" "Saturday"
} )
var _ShortDayNames = []string{ var _ShortDayNames = []string(
"Sun", "Sun",
"Mon", "Mon",
"Tue", "Tue",
@ -239,9 +239,9 @@ var _ShortDayNames = []string{
"Thu", "Thu",
"Fri", "Fri",
"Sat" "Sat"
} )
var _ShortMonthNames = []string{ var _ShortMonthNames = []string(
"Jan", "Jan",
"Feb", "Feb",
"Mar", "Mar",
@ -254,7 +254,7 @@ var _ShortMonthNames = []string{
"Oct", "Oct",
"Nov", "Nov",
"Dec" "Dec"
} )
func _Copy(dst []byte, s string) { func _Copy(dst []byte, s string) {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {

View file

@ -14,20 +14,20 @@ type _TimeTest struct {
golden Time; golden Time;
} }
var utctests = []_TimeTest { var utctests = []_TimeTest (
_TimeTest{0, Time{1970, 1, 1, 0, 0, 0, Thursday, 0, "GMT"}}, _TimeTest(0, Time(1970, 1, 1, 0, 0, 0, Thursday, 0, "GMT")),
_TimeTest{1221681866, Time{2008, 9, 17, 20, 4, 26, Wednesday, 0, "GMT"}}, _TimeTest(1221681866, Time(2008, 9, 17, 20, 4, 26, Wednesday, 0, "GMT")),
_TimeTest{-1221681866, Time{1931, 4, 16, 3, 55, 34, Thursday, 0, "GMT"}}, _TimeTest(-1221681866, Time(1931, 4, 16, 3, 55, 34, Thursday, 0, "GMT")),
_TimeTest{1e18, Time{31688740476, 10, 23, 1, 46, 40, Friday, 0, "GMT"}}, _TimeTest(1e18, Time(31688740476, 10, 23, 1, 46, 40, Friday, 0, "GMT")),
_TimeTest{-1e18, Time{-31688736537, 3, 10, 22, 13, 20, Tuesday, 0, "GMT"}}, _TimeTest(-1e18, Time(-31688736537, 3, 10, 22, 13, 20, Tuesday, 0, "GMT")),
_TimeTest{0x7fffffffffffffff, Time{292277026596, 12, 4, 15, 30, 7, Sunday, 0, "GMT"}}, _TimeTest(0x7fffffffffffffff, Time(292277026596, 12, 4, 15, 30, 7, Sunday, 0, "GMT")),
_TimeTest{-0x8000000000000000, Time{-292277022657, 1, 27, 8, 29, 52, Sunday, 0, "GMT"}} _TimeTest(-0x8000000000000000, Time(-292277022657, 1, 27, 8, 29, 52, Sunday, 0, "GMT"))
} )
var localtests = []_TimeTest { var localtests = []_TimeTest (
_TimeTest{0, Time{1969, 12, 31, 16, 0, 0, Wednesday, -8*60*60, "PST"}}, _TimeTest(0, Time(1969, 12, 31, 16, 0, 0, Wednesday, -8*60*60, "PST")),
_TimeTest{1221681866, Time{2008, 9, 17, 13, 4, 26, Wednesday, -7*60*60, "PDT"}} _TimeTest(1221681866, Time(2008, 9, 17, 13, 4, 26, Wednesday, -7*60*60, "PDT"))
} )
func _Same(t, u *Time) bool { func _Same(t, u *Time) bool {
return t.Year == u.Year return t.Year == u.Year

View file

@ -87,7 +87,7 @@ type _Zonetime struct {
func parseinfo(bytes []byte) (zt []_Zonetime, err *os.Error) { func parseinfo(bytes []byte) (zt []_Zonetime, err *os.Error) {
data1 := _Data{bytes, false}; data1 := _Data(bytes, false);
data := &data1; data := &data1;
// 4-byte magic "TZif" // 4-byte magic "TZif"
@ -127,21 +127,21 @@ func parseinfo(bytes []byte) (zt []_Zonetime, err *os.Error) {
} }
// Transition times. // Transition times.
txtimes1 := _Data{data.Read(n[NTime]*4), false}; txtimes1 := _Data(data.Read(n[NTime]*4), false);
txtimes := &txtimes1; txtimes := &txtimes1;
// Time zone indices for transition times. // Time zone indices for transition times.
txzones := data.Read(n[NTime]); txzones := data.Read(n[NTime]);
// Zone info structures // Zone info structures
zonedata1 := _Data{data.Read(n[NZone]*6), false}; zonedata1 := _Data(data.Read(n[NZone]*6), false);
zonedata := &zonedata1; zonedata := &zonedata1;
// Time zone abbreviations. // Time zone abbreviations.
abbrev := data.Read(n[NChar]); abbrev := data.Read(n[NChar]);
// Leap-second time pairs // Leap-second time pairs
leapdata1 := _Data{data.Read(n[NLeap]*8), false}; leapdata1 := _Data(data.Read(n[NLeap]*8), false);
leapdata := &leapdata1; leapdata := &leapdata1;
// Whether tx times associated with local time types // Whether tx times associated with local time types

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ import (
"unicode"; "unicode";
) )
var upper = []int{ var upper = []int(
0x41, 0x41,
0xc0, 0xc0,
0xd8, 0xd8,
@ -31,9 +31,9 @@ var upper = []int{
0x10400, 0x10400,
0x1d400, 0x1d400,
0x1d7ca, 0x1d7ca,
} )
var notupper = []int{ var notupper = []int(
0x40, 0x40,
0x5b, 0x5b,
0x61, 0x61,
@ -44,9 +44,9 @@ var notupper = []int{
0x2150, 0x2150,
0xffff, 0xffff,
0x10000, 0x10000,
} )
var letter = []int{ var letter = []int(
0x41, 0x41,
0x61, 0x61,
0xaa, 0xaa,
@ -79,9 +79,9 @@ var letter = []int{
0x20000, 0x20000,
0x2f800, 0x2f800,
0x2fa1d, 0x2fa1d,
} )
var notletter = []int{ var notletter = []int(
0x20, 0x20,
0x35, 0x35,
0x375, 0x375,
@ -90,7 +90,7 @@ var notletter = []int{
0xfffe, 0xfffe,
0x1ffff, 0x1ffff,
0x10ffff, 0x10ffff,
} )
func TestIsLetter(t *testing.T) { func TestIsLetter(t *testing.T) {
for i, r := range(upper) { for i, r := range(upper) {

View file

@ -17,33 +17,33 @@ type Utf8Map struct {
str string; str string;
} }
var utf8map = []Utf8Map { var utf8map = []Utf8Map (
Utf8Map{ 0x0000, "\x00" }, Utf8Map( 0x0000, "\x00" ),
Utf8Map{ 0x0001, "\x01" }, Utf8Map( 0x0001, "\x01" ),
Utf8Map{ 0x007e, "\x7e" }, Utf8Map( 0x007e, "\x7e" ),
Utf8Map{ 0x007f, "\x7f" }, Utf8Map( 0x007f, "\x7f" ),
Utf8Map{ 0x0080, "\xc2\x80" }, Utf8Map( 0x0080, "\xc2\x80" ),
Utf8Map{ 0x0081, "\xc2\x81" }, Utf8Map( 0x0081, "\xc2\x81" ),
Utf8Map{ 0x00bf, "\xc2\xbf" }, Utf8Map( 0x00bf, "\xc2\xbf" ),
Utf8Map{ 0x00c0, "\xc3\x80" }, Utf8Map( 0x00c0, "\xc3\x80" ),
Utf8Map{ 0x00c1, "\xc3\x81" }, Utf8Map( 0x00c1, "\xc3\x81" ),
Utf8Map{ 0x00c8, "\xc3\x88" }, Utf8Map( 0x00c8, "\xc3\x88" ),
Utf8Map{ 0x00d0, "\xc3\x90" }, Utf8Map( 0x00d0, "\xc3\x90" ),
Utf8Map{ 0x00e0, "\xc3\xa0" }, Utf8Map( 0x00e0, "\xc3\xa0" ),
Utf8Map{ 0x00f0, "\xc3\xb0" }, Utf8Map( 0x00f0, "\xc3\xb0" ),
Utf8Map{ 0x00f8, "\xc3\xb8" }, Utf8Map( 0x00f8, "\xc3\xb8" ),
Utf8Map{ 0x00ff, "\xc3\xbf" }, Utf8Map( 0x00ff, "\xc3\xbf" ),
Utf8Map{ 0x0100, "\xc4\x80" }, Utf8Map( 0x0100, "\xc4\x80" ),
Utf8Map{ 0x07ff, "\xdf\xbf" }, Utf8Map( 0x07ff, "\xdf\xbf" ),
Utf8Map{ 0x0800, "\xe0\xa0\x80" }, Utf8Map( 0x0800, "\xe0\xa0\x80" ),
Utf8Map{ 0x0801, "\xe0\xa0\x81" }, Utf8Map( 0x0801, "\xe0\xa0\x81" ),
Utf8Map{ 0xfffe, "\xef\xbf\xbe" }, Utf8Map( 0xfffe, "\xef\xbf\xbe" ),
Utf8Map{ 0xffff, "\xef\xbf\xbf" }, Utf8Map( 0xffff, "\xef\xbf\xbf" ),
Utf8Map{ 0x10000, "\xf0\x90\x80\x80" }, Utf8Map( 0x10000, "\xf0\x90\x80\x80" ),
Utf8Map{ 0x10001, "\xf0\x90\x80\x81" }, Utf8Map( 0x10001, "\xf0\x90\x80\x81" ),
Utf8Map{ 0x10fffe, "\xf4\x8f\xbf\xbe" }, Utf8Map( 0x10fffe, "\xf4\x8f\xbf\xbe" ),
Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" }, Utf8Map( 0x10ffff, "\xf4\x8f\xbf\xbf" ),
} )
// io.StringBytes with one extra byte at end // io.StringBytes with one extra byte at end
func bytes(s string) []byte { func bytes(s string) []byte {
@ -161,12 +161,12 @@ type RuneCountTest struct {
in string; in string;
out int; out int;
} }
var runecounttests = []RuneCountTest { var runecounttests = []RuneCountTest (
RuneCountTest{ "abcd", 4 }, RuneCountTest( "abcd", 4 ),
RuneCountTest{ "☺☻☹", 3 }, RuneCountTest( "☺☻☹", 3 ),
RuneCountTest{ "1,2,3,4", 7 }, RuneCountTest( "1,2,3,4", 7 ),
RuneCountTest{ "\xe2\x00", 2 }, RuneCountTest( "\xe2\x00", 2 ),
} )
func TestRuneCount(t *testing.T) { func TestRuneCount(t *testing.T) {
for i := 0; i < len(runecounttests); i++ { for i := 0; i < len(runecounttests); i++ {
tt := runecounttests[i]; tt := runecounttests[i];

View file

@ -32,16 +32,16 @@ func min(xs []uint64) uint64 {
func main() { func main() {
F := []uint64{2, 3, 5}; F := []uint64(2, 3, 5);
var n = len(F); var n = len(F);
OUT := []uint64{ OUT := []uint64(
2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36,
40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125,
128, 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, 240, 243, 250, 128, 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, 240, 243, 250,
256, 270, 288, 300, 320, 324, 360, 375, 384, 400, 405, 432, 450, 480, 256, 270, 288, 300, 320, 324, 360, 375, 384, 400, 405, 432, 450, 480,
486, 500, 512, 540, 576, 600, 625, 640, 648, 675, 720, 729, 750, 768, 486, 500, 512, 540, 576, 600, 625, 640, 648, 675, 720, 729, 750, 768,
800, 810, 864, 900, 960, 972, 1000, 1024, 1080, 1125, 1152, 1200, 1215, 800, 810, 864, 900, 960, 972, 1000, 1024, 1080, 1125, 1152, 1200, 1215,
1250, 1280, 1296, 1350, 1440, 1458, 1500, 1536, 1600 }; 1250, 1280, 1296, 1350, 1440, 1458, 1500, 1536, 1600 );
x := uint64(1); x := uint64(1);
ins := make([]T, n); ins := make([]T, n);

View file

@ -18,7 +18,7 @@ type T struct {
d byte; d byte;
} }
var a = []int{ 1, 2, 3 } var a = []int( 1, 2, 3 )
var NIL []int; var NIL []int;
func arraycmptest() { func arraycmptest() {
@ -44,7 +44,7 @@ func SameArray(a, b []int) bool {
return true; return true;
} }
var t = T{1.5, 123, "hello", 255} var t = T(1.5, 123, "hello", 255)
var mt = make(map[int]T) var mt = make(map[int]T)
var ma = make(map[int][]int) var ma = make(map[int][]int)

View file

@ -14,7 +14,7 @@ func fn(p PS) int {
return p.get() return p.get()
} }
func main() { func main() {
s := S{1}; s := S(1);
if s.get() != 1 { if s.get() != 1 {
panic() panic()
} }

View file

@ -12,7 +12,7 @@ type S struct { v int }
func (p *S) send(c chan <- int) { c <- p.v } func (p *S) send(c chan <- int) { c <- p.v }
func main() { func main() {
s := S{0}; s := S(0);
var i I = &s; var i I = &s;
c := make(chan int); c := make(chan int);
go i.send(c); go i.send(c);

View file

@ -158,7 +158,7 @@ func getn(in []*dch) []rat {
// Get one rat from each of 2 demand channels // Get one rat from each of 2 demand channels
func get2(in0 *dch, in1 *dch) []rat { func get2(in0 *dch, in1 *dch) []rat {
return getn([]*dch{in0, in1}); return getn([]*dch(in0, in1));
} }
func copy(in *dch, out *dch) { func copy(in *dch, out *dch) {

View file

@ -167,7 +167,7 @@ func getn(in []*dch) []item {
// Get one item from each of 2 demand channels // Get one item from each of 2 demand channels
func get2(in0 *dch, in1 *dch) []item { func get2(in0 *dch, in1 *dch) []item {
return getn([]*dch{in0, in1}); return getn([]*dch(in0, in1));
} }
func copy(in *dch, out *dch){ func copy(in *dch, out *dch){

View file

@ -43,7 +43,7 @@ func Sieve(primes chan<- int) {
func main() { func main() {
primes := make(chan int); primes := make(chan int);
go Sieve(primes); go Sieve(primes);
a := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; a := []int(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
if <-primes != a[i] { panic(a[i])} if <-primes != a[i] { panic(a[i])}
} }

View file

@ -76,13 +76,13 @@ func h() {
func main() { func main() {
go f(); go f();
check([]int{1,4,5,4}); check([]int(1,4,5,4));
a := accum(0); a := accum(0);
b := accum(1); b := accum(1);
go g(a, b); go g(a, b);
check([]int{2,4,6,9}); check([]int(2,4,6,9));
go h(); go h();
check([]int{100,200,101,201,500,101,201,500}); check([]int(100,200,101,201,500,101,201,500));
} }

View file

@ -24,45 +24,45 @@ func eq(a []*R) {
type P struct { a, b int }; type P struct { a, b int };
func NewP(a, b int) *P { func NewP(a, b int) *P {
return &P{a, b} return &P(a, b)
} }
func main() { func main() {
var t T; var t T;
t = T{0, 7.2, "hi", &t}; t = T(0, 7.2, "hi", &t);
var tp *T; var tp *T;
tp = &T{0, 7.2, "hi", &t}; tp = &T(0, 7.2, "hi", &t);
a1 := []int{1,2,3}; a1 := []int(1,2,3);
if len(a1) != 3 { panic("a1") } if len(a1) != 3 { panic("a1") }
a2 := [10]int{1,2,3}; a2 := [10]int(1,2,3);
if len(a2) != 10 || cap(a2) != 10 { panic("a2") } if len(a2) != 10 || cap(a2) != 10 { panic("a2") }
a3 := [10]int{1,2,3,}; a3 := [10]int(1,2,3,);
if len(a3) != 10 || a2[3] != 0 { panic("a3") } if len(a3) != 10 || a2[3] != 0 { panic("a3") }
var oai []int; var oai []int;
oai = []int{1,2,3}; oai = []int(1,2,3);
if len(oai) != 3 { panic("oai") } if len(oai) != 3 { panic("oai") }
at := [...]*T{&t, &t, &t}; at := [...]*T(&t, &t, &t);
if len(at) != 3 { panic("at") } if len(at) != 3 { panic("at") }
c := make(chan int); c := make(chan int);
ac := []chan int{c, c, c}; ac := []chan int(c, c, c);
if len(ac) != 3 { panic("ac") } if len(ac) != 3 { panic("ac") }
aat := [][len(at)]*T{at, at}; aat := [][len(at)]*T(at, at);
if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") } if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") }
s := string([]byte{'h', 'e', 'l', 'l', 'o'}); s := string([]byte('h', 'e', 'l', 'l', 'o'));
if s != "hello" { panic("s") } if s != "hello" { panic("s") }
m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.}; m := map[string]float("one":1.0, "two":2.0, "pi":22./7.);
if len(m) != 3 { panic("m") } if len(m) != 3 { panic("m") }
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)}); eq([]*R(itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)));
p1 := NewP(1, 2); p1 := NewP(1, 2);
p2 := NewP(1, 2); p2 := NewP(1, 2);

View file

@ -6,8 +6,7 @@
package main package main
var a = []int { "a" }; // ERROR "conver|incompatible" var a = []int ( "a" ); // ERROR "conver|incompatible"
var b = int { 1 }; // ERROR "compos"
func f() int func f() int

View file

@ -14,8 +14,8 @@ func main() {
}; };
var s string = "hello"; var s string = "hello";
var f float = 0.2; var f float = 0.2;
t := T{s, f}; t := T(s, f);
type M map[int] int; type M map[int] int;
m0 := M{7:8}; m0 := M(7:8);
} }

View file

@ -8,5 +8,5 @@ package main
func main() { func main() {
type M map[int] int; type M map[int] int;
m1 := M{7 : 8}; m1 := M(7 : 8);
} }

View file

@ -9,8 +9,8 @@ package main
type A []int; type A []int;
func main() { func main() {
a := &A{0}; a := &A(0);
b := &A{0, 1}; b := &A(0, 1);
} }
/* /*

View file

@ -11,7 +11,7 @@ type A []int;
func main() { func main() {
var a [3]A; var a [3]A;
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
a[i] = A{i}; a[i] = A(i);
} }
if a[0][0] != 0 { panic(); } if a[0][0] != 0 { panic(); }
if a[1][0] != 1 { panic(); } if a[1][0] != 1 { panic(); }

View file

@ -10,8 +10,8 @@ type A []int;
type M map[int] int; type M map[int] int;
func main() { func main() {
var a *A = &A{0}; var a *A = &A(0);
var m *M = &M{0 : 0}; // should be legal to use & here for consistency with other composite constructors (prev. line) var m *M = &M(0 : 0); // should be legal to use & here for consistency with other composite constructors (prev. line)
} }
/* /*

View file

@ -6,7 +6,7 @@
package main package main
var a = []int { 1, 2, 3 } var a = []int ( 1, 2, 3 )
func main() { func main() {
if len(a) != 3 { panic("array len") } if len(a) != 3 { panic("array len") }

View file

@ -12,7 +12,7 @@ func main() {
if s != "" { if s != "" {
panic("bad convert") panic("bad convert")
} }
var b1 = [5]byte{'h', 'e', 'l', 'l', 'o'}; var b1 = [5]byte('h', 'e', 'l', 'l', 'o');
if string(b1) != "hello" { if string(b1) != "hello" {
panic("bad convert 1") panic("bad convert 1")
} }

View file

@ -7,7 +7,7 @@
package main package main
type T struct { s string } type T struct { s string }
var t = T{"hi"} var t = T("hi")
func main() {} func main() {}

View file

@ -11,7 +11,7 @@ func foo(a []int) int {
} }
func main() { func main() {
a := &[]int{12}; a := &[]int(12);
if x := a[0] ; x != 12 { panicln(1) } if x := a[0] ; x != 12 { panicln(1) }
if x := (*a)[0]; x != 12 { panicln(2) } if x := (*a)[0]; x != 12 { panicln(2) }
if x := foo(*a) ; x != 12 { panicln(3) } // fails (x is incorrect) if x := foo(*a) ; x != 12 { panicln(3) } // fails (x is incorrect)
@ -28,5 +28,5 @@ panic on line 83 PC=0x14d6
0x52bb?zi 0x52bb?zi
mainstart(1, 0, 1606416432, ...) mainstart(1, 0, 1606416432, ...)
mainstart(0x1, 0x7fff5fbff830, 0x0, ...) mainstart(0x1, 0x7fff5fbff830, 0x0, ...)
uetli:~/Source/go1/test/bugs gri$ uetli:~/Source/go1/test/bugs gri$
*/ */

View file

@ -14,12 +14,12 @@ type Test struct {
out string; out string;
} }
var tests = []Test { var tests = []Test (
Test{ 123.5, "123.5", "123.5" }, Test( 123.5, "123.5", "123.5" ),
Test{ 456.7, "456.7", "456.7" }, Test( 456.7, "456.7", "456.7" ),
Test{ 1e23+8.5e6, "1e23+8.5e6", "1.0000000000000001e+23" }, Test( 1e23+8.5e6, "1e23+8.5e6", "1.0000000000000001e+23" ),
Test{ 100000000000000008388608, "100000000000000008388608", "1.0000000000000001e+23" }, Test( 100000000000000008388608, "100000000000000008388608", "1.0000000000000001e+23" ),
Test{ 1e23+8388609, "1e23+8388609", "1.0000000000000001e+23" }, Test( 1e23+8388609, "1e23+8388609", "1.0000000000000001e+23" ),
// "x" = the floating point value from converting the string x. // "x" = the floating point value from converting the string x.
// These are exactly representable in 64-bit floating point: // These are exactly representable in 64-bit floating point:
@ -32,9 +32,9 @@ var tests = []Test {
// The correct answer, of course, would be "1e23+8388608" = 1e23+8388608. // The correct answer, of course, would be "1e23+8388608" = 1e23+8388608.
// This is not going to be correct until 6g has multiprecision floating point. // This is not going to be correct until 6g has multiprecision floating point.
// A simpler case is "1e23+1", which should also round to 1e23+8388608. // A simpler case is "1e23+1", which should also round to 1e23+8388608.
Test{ 1e23+8.388608e6, "1e23+8.388608e6", "1.0000000000000001e+23" }, Test( 1e23+8.388608e6, "1e23+8.388608e6", "1.0000000000000001e+23" ),
Test{ 1e23+1, "1e23+1", "1.0000000000000001e+23" }, Test( 1e23+1, "1e23+1", "1.0000000000000001e+23" ),
} )
func main() { func main() {
ok := true; ok := true;

View file

@ -244,9 +244,8 @@ fixedbugs/bug073.go:9: illegal types for operand: RSH
int int
=========== fixedbugs/bug074.go =========== fixedbugs/bug074.go
fixedbugs/bug074.go:6: syntax error near string fixedbugs/bug074.go:6: invalid type for composite literal: string
fixedbugs/bug074.go:6: syntax error near string fixedbugs/bug074.go:6: invalid type for composite literal: string
fixedbugs/bug074.go:7: x: undefined
=========== fixedbugs/bug081.go =========== fixedbugs/bug081.go
fixedbugs/bug081.go:5: no type x fixedbugs/bug081.go:5: no type x

View file

@ -9,7 +9,7 @@ package main
var m0 map[string]int var m0 map[string]int
var m1 *map[string]int var m1 *map[string]int
var m2 *map[string]int = &m0 var m2 *map[string]int = &m0
var m3 map[string]int = map[string]int{"a": 1} var m3 map[string]int = map[string]int("a": 1)
var m4 *map[string]int = &m3 var m4 *map[string]int = &m3
var s0 string var s0 string
@ -25,7 +25,7 @@ var a2 *[10]int = &a0
var b0 []int var b0 []int
var b1 *[]int var b1 *[]int
var b2 *[]int = &b0 var b2 *[]int = &b0
var b3 []int = []int{1, 2, 3} var b3 []int = []int(1, 2, 3)
var b4 *[]int = &b3 var b4 *[]int = &b3
func crash() func crash()

View file

@ -6,10 +6,10 @@
package main package main
var a = []int { 1,2, } var a = []int ( 1,2, )
var b = [5]int { 1,2,3 } var b = [5]int ( 1,2,3 )
var c = []int { 1 } var c = []int ( 1 )
var d = [...]int { 1,2,3 } var d = [...]int ( 1,2,3 )
func main() { func main() {
if len(a) != 2 { panicln("len a", len(a)) } if len(a) != 2 { panicln("len a", len(a)) }

View file

@ -31,8 +31,8 @@ func test(name string, i I) {
} }
func ptrs() { func ptrs() {
var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 }; var bigptr BigPtr = BigPtr( 10000, 2000, 300, 45 );
var smallptr SmallPtr = SmallPtr{ 12345 }; var smallptr SmallPtr = SmallPtr( 12345 );
var intptr IntPtr = 12345; var intptr IntPtr = 12345;
test("bigptr", bigptr); test("bigptr", bigptr);
@ -53,8 +53,8 @@ type Int int32
func (z Int) M() int64 { return int64(z) } func (z Int) M() int64 { return int64(z) }
func nonptrs() { func nonptrs() {
var big Big = Big{ 10000, 2000, 300, 45 }; var big Big = Big( 10000, 2000, 300, 45 );
var small Small = Small{ 12345 }; var small Small = Small( 12345 );
var int Int = 12345; var int Int = 12345;
test("big", big); test("big", big);

View file

@ -22,7 +22,7 @@ func (p S1) Get() int { return p.i }
func (p S1) Put(i int) { p.i = i } func (p S1) Put(i int) { p.i = i }
func f1() { func f1() {
s := S1{1}; s := S1(1);
var i I1 = s; var i I1 = s;
i.Put(2); i.Put(2);
check(i.Get() == 1, "f1 i"); check(i.Get() == 1, "f1 i");
@ -30,7 +30,7 @@ func f1() {
} }
func f2() { func f2() {
s := S1{1}; s := S1(1);
var i I1 = &s; var i I1 = &s;
i.Put(2); i.Put(2);
check(i.Get() == 1, "f2 i"); check(i.Get() == 1, "f2 i");
@ -38,7 +38,7 @@ func f2() {
} }
func f3() { func f3() {
s := &S1{1}; s := &S1(1);
var i I1 = s; var i I1 = s;
i.Put(2); i.Put(2);
check(i.Get() == 1, "f3 i"); check(i.Get() == 1, "f3 i");
@ -50,7 +50,7 @@ func (p *S2) Get() int { return p.i }
func (p *S2) Put(i int) { p.i = i } func (p *S2) Put(i int) { p.i = i }
func f4() { func f4() {
s := S2{1}; s := S2(1);
var i I1 = s; var i I1 = s;
i.Put(2); i.Put(2);
check(i.Get() == 2, "f4 i"); check(i.Get() == 2, "f4 i");
@ -58,7 +58,7 @@ func f4() {
} }
func f5() { func f5() {
s := S2{1}; s := S2(1);
var i I1 = &s; var i I1 = &s;
i.Put(2); i.Put(2);
check(i.Get() == 2, "f5 i"); check(i.Get() == 2, "f5 i");
@ -66,7 +66,7 @@ func f5() {
} }
func f6() { func f6() {
s := &S2{1}; s := &S2(1);
var i I1 = s; var i I1 = s;
i.Put(2); i.Put(2);
check(i.Get() == 2, "f6 i"); check(i.Get() == 2, "f6 i");
@ -80,7 +80,7 @@ func (p S3) Get() int64 { return p.l }
func (p S3) Put(i int64) { p.l = i } func (p S3) Put(i int64) { p.l = i }
func f7() { func f7() {
s := S3{1, 2, 3, 4}; s := S3(1, 2, 3, 4);
var i I2 = s; var i I2 = s;
i.Put(5); i.Put(5);
check(i.Get() == 4, "f7 i"); check(i.Get() == 4, "f7 i");
@ -88,7 +88,7 @@ func f7() {
} }
func f8() { func f8() {
s := S3{1, 2, 3, 4}; s := S3(1, 2, 3, 4);
var i I2 = &s; var i I2 = &s;
i.Put(5); i.Put(5);
check(i.Get() == 4, "f8 i"); check(i.Get() == 4, "f8 i");
@ -96,7 +96,7 @@ func f8() {
} }
func f9() { func f9() {
s := &S3{1, 2, 3, 4}; s := &S3(1, 2, 3, 4);
var i I2 = s; var i I2 = s;
i.Put(5); i.Put(5);
check(i.Get() == 4, "f9 i"); check(i.Get() == 4, "f9 i");
@ -108,7 +108,7 @@ func (p *S4) Get() int64 { return p.l }
func (p *S4) Put(i int64) { p.l = i } func (p *S4) Put(i int64) { p.l = i }
func f10() { func f10() {
s := S4{1, 2, 3, 4}; s := S4(1, 2, 3, 4);
var i I2 = s; var i I2 = s;
i.Put(5); i.Put(5);
check(i.Get() == 5, "f10 i"); check(i.Get() == 5, "f10 i");
@ -116,7 +116,7 @@ func f10() {
} }
func f11() { func f11() {
s := S4{1, 2, 3, 4}; s := S4(1, 2, 3, 4);
var i I2 = &s; var i I2 = &s;
i.Put(5); i.Put(5);
check(i.Get() == 5, "f11 i"); check(i.Get() == 5, "f11 i");
@ -124,7 +124,7 @@ func f11() {
} }
func f12() { func f12() {
s := &S4{1, 2, 3, 4}; s := &S4(1, 2, 3, 4);
var i I2 = s; var i I2 = s;
i.Put(5); i.Put(5);
check(i.Get() == 5, "f12 i"); check(i.Get() == 5, "f12 i");

View file

@ -27,9 +27,9 @@ func P(a []string) string {
func main() { func main() {
// Test a map literal. // Test a map literal.
mlit := map[string] int { "0":0, "1":1, "2":2, "3":3, "4":4 }; mlit := map[string] int ( "0":0, "1":1, "2":2, "3":3, "4":4 );
for i := 0; i < len(mlit); i++ { for i := 0; i < len(mlit); i++ {
s := string([]byte{byte(i)+'0'}); s := string([]byte(byte(i)+'0'));
if mlit[s] != i { if mlit[s] != i {
fmt.Printf("mlit[%s] = %d\n", s, mlit[s]) fmt.Printf("mlit[%s] = %d\n", s, mlit[s])
} }
@ -64,14 +64,14 @@ func main() {
s := strconv.Itoa(i); s := strconv.Itoa(i);
s10 := strconv.Itoa(i*10); s10 := strconv.Itoa(i*10);
f := float(i); f := float(i);
t := T{int64(i),f}; t := T(int64(i),f);
apT[i] = new(T); apT[i] = new(T);
apT[i].i = int64(i); apT[i].i = int64(i);
apT[i].f = f; apT[i].f = f;
apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check
apT[2*i].i = int64(i); apT[2*i].i = int64(i);
apT[2*i].f = f; apT[2*i].f = f;
m := M{i: i+1}; m := M(i: i+1);
mib[i] = (i != 0); mib[i] = (i != 0);
mii[i] = 10*i; mii[i] = 10*i;
mfi[float(i)] = 10*i; mfi[float(i)] = 10*i;
@ -140,7 +140,7 @@ func main() {
s := strconv.Itoa(i); s := strconv.Itoa(i);
s10 := strconv.Itoa(i*10); s10 := strconv.Itoa(i*10);
f := float(i); f := float(i);
t := T{int64(i), f}; t := T(int64(i), f);
// BUG m := M(i, i+1); // BUG m := M(i, i+1);
if mib[i] != (i != 0) { if mib[i] != (i != 0) {
fmt.Printf("mib[%d] = %t\n", i, mib[i]); fmt.Printf("mib[%d] = %t\n", i, mib[i]);
@ -193,7 +193,7 @@ func main() {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
s := strconv.Itoa(i); s := strconv.Itoa(i);
f := float(i); f := float(i);
t := T{int64(i), f}; t := T(int64(i), f);
{ {
a, b := mib[i]; a, b := mib[i];
if !b { if !b {
@ -331,7 +331,7 @@ func main() {
for i := count; i < 2*count; i++ { for i := count; i < 2*count; i++ {
s := strconv.Itoa(i); s := strconv.Itoa(i);
f := float(i); f := float(i);
t := T{int64(i),f}; t := T(int64(i),f);
{ {
a, b := mib[i]; a, b := mib[i];
if b { if b {

View file

@ -16,7 +16,7 @@ type I interface {
} }
func main() { func main() {
var t T = T{0,1,2,3,4}; var t T = T(0,1,2,3,4);
var i I; var i I;
i = t; i = t;
if i.Len() != 5 { if i.Len() != 5 {

View file

@ -236,7 +236,7 @@ func (P *Parser) noType(x AST.Expr) AST.Expr {
lit, ok := x.(*AST.TypeLit); lit, ok := x.(*AST.TypeLit);
if ok { if ok {
P.error(lit.Typ.Pos, "expected expression, found type"); P.error(lit.Typ.Pos, "expected expression, found type");
x = &AST.BasicLit{lit.Typ.Pos, Scanner.STRING, ""}; x = &AST.BasicLit(lit.Typ.Pos, Scanner.STRING, "");
} }
} }
return x; return x;
@ -244,7 +244,7 @@ func (P *Parser) noType(x AST.Expr) AST.Expr {
func (P *Parser) newBinaryExpr(pos, tok int, x, y AST.Expr) *AST.BinaryExpr { func (P *Parser) newBinaryExpr(pos, tok int, x, y AST.Expr) *AST.BinaryExpr {
return &AST.BinaryExpr{pos, tok, P.noType(x), P.noType(y)}; return &AST.BinaryExpr(pos, tok, P.noType(x), P.noType(y));
} }
@ -273,13 +273,13 @@ func (P *Parser) parseIdent(scope *SymbolTable.Scope) *AST.Ident {
} else { } else {
assert(obj.Kind != SymbolTable.NONE); assert(obj.Kind != SymbolTable.NONE);
} }
x := &AST.Ident{P.pos, obj}; x := &AST.Ident(P.pos, obj);
P.next(); P.next();
return x; return x;
} }
P.expect(Scanner.IDENT); // use expect() error handling P.expect(Scanner.IDENT); // use expect() error handling
return &AST.Ident{P.pos, nil}; return &AST.Ident(P.pos, nil);
} }
@ -344,7 +344,7 @@ func (P *Parser) parseQualifiedIdent() AST.Expr {
pos := P.pos; pos := P.pos;
P.next(); P.next();
y := P.parseIdent(nil); y := P.parseIdent(nil);
x = &AST.Selector{pos, x, y}; x = &AST.Selector(pos, x, y);
} }
return x; return x;
@ -465,18 +465,18 @@ func (P *Parser) parseVarList(list *array.Array, ellipsis_ok bool) {
continue; continue;
} }
} }
list.Set(i, &AST.BadExpr{0}); list.Set(i, &AST.BadExpr(0));
P.error(t.Pos, "identifier expected"); P.error(t.Pos, "identifier expected");
} }
// add type // add type
list.Push(&AST.TypeLit{typ}); list.Push(&AST.TypeLit(typ));
} else { } else {
// all list entries are types // all list entries are types
// convert all type entries into type expressions // convert all type entries into type expressions
for i, n := i0, list.Len(); i < n; i++ { for i, n := i0, list.Len(); i < n; i++ {
t := list.At(i).(*AST.Type); t := list.At(i).(*AST.Type);
list.Set(i, &AST.TypeLit{t}); list.Set(i, &AST.TypeLit(t));
} }
} }
} }
@ -544,7 +544,7 @@ func (P *Parser) parseResult(ftyp *AST.Type) *AST.Type {
if typ != nil { if typ != nil {
t = AST.NewType(P.pos, AST.STRUCT); t = AST.NewType(P.pos, AST.STRUCT);
t.List = array.New(0); t.List = array.New(0);
t.List.Push(&AST.TypeLit{typ}); t.List.Push(&AST.TypeLit(typ));
t.End = P.pos; t.End = P.pos;
} }
} }
@ -597,7 +597,7 @@ func (P *Parser) parseMethodSpec(list *array.Array) {
list.Push(P.parseIdentList()); list.Push(P.parseIdentList());
t := P.parseSignature(); t := P.parseSignature();
list.Push(&AST.TypeLit{t}); list.Push(&AST.TypeLit(t));
} }
@ -677,7 +677,7 @@ func (P *Parser) parseStructType() *AST.Type {
t.End = P.pos; t.End = P.pos;
P.expect(Scanner.RBRACE); P.expect(Scanner.RBRACE);
// enter fields into struct scope // enter fields into struct scope
for i, n := 0, t.List.Len(); i < n; i++ { for i, n := 0, t.List.Len(); i < n; i++ {
if x, ok := t.List.At(i).(*AST.Ident); ok { if x, ok := t.List.At(i).(*AST.Ident); ok {
@ -826,7 +826,7 @@ func (P *Parser) parseFunctionLit() AST.Expr {
P.scope_lev--; P.scope_lev--;
P.expr_lev--; P.expr_lev--;
return &AST.FunctionLit{pos, typ, body}; return &AST.FunctionLit(pos, typ, body);
} }
@ -848,7 +848,7 @@ func (P *Parser) parseOperand() AST.Expr {
return x; return x;
case Scanner.INT, Scanner.FLOAT, Scanner.STRING: case Scanner.INT, Scanner.FLOAT, Scanner.STRING:
x := &AST.BasicLit{P.pos, P.tok, P.val}; x := &AST.BasicLit(P.pos, P.tok, P.val);
P.next(); P.next();
if x.Tok == Scanner.STRING { if x.Tok == Scanner.STRING {
// TODO should remember the list instead of // TODO should remember the list instead of
@ -865,14 +865,14 @@ func (P *Parser) parseOperand() AST.Expr {
default: default:
t := P.tryType(); t := P.tryType();
if t != nil { if t != nil {
return &AST.TypeLit{t}; return &AST.TypeLit(t);
} else { } else {
P.error(P.pos, "operand expected"); P.error(P.pos, "operand expected");
P.next(); // make progress P.next(); // make progress
} }
} }
return &AST.BadExpr{P.pos}; return &AST.BadExpr(P.pos);
} }
@ -885,11 +885,11 @@ func (P *Parser) parseSelectorOrTypeGuard(x AST.Expr) AST.Expr {
P.expect(Scanner.PERIOD); P.expect(Scanner.PERIOD);
if P.tok == Scanner.IDENT { if P.tok == Scanner.IDENT {
x = &AST.Selector{pos, x, P.parseIdent(nil)}; x = &AST.Selector(pos, x, P.parseIdent(nil));
} else { } else {
P.expect(Scanner.LPAREN); P.expect(Scanner.LPAREN);
x = &AST.TypeGuard{pos, x, P.parseType()}; x = &AST.TypeGuard(pos, x, P.parseType());
P.expect(Scanner.RPAREN); P.expect(Scanner.RPAREN);
} }
@ -909,7 +909,7 @@ func (P *Parser) parseIndex(x AST.Expr) AST.Expr {
P.expr_lev--; P.expr_lev--;
P.expect(Scanner.RBRACK); P.expect(Scanner.RBRACK);
return &AST.Index{pos, x, i}; return &AST.Index(pos, x, i);
} }
@ -920,7 +920,7 @@ func (P *Parser) parseCall(f AST.Expr) AST.Expr {
defer un(trace(P, "Call")); defer un(trace(P, "Call"));
} }
call := &AST.Call{P.pos, f, nil}; call := &AST.Call(P.pos, f, nil);
P.expect(Scanner.LPAREN); P.expect(Scanner.LPAREN);
if P.tok != Scanner.RPAREN { if P.tok != Scanner.RPAREN {
P.expr_lev++; P.expr_lev++;
@ -931,13 +931,13 @@ func (P *Parser) parseCall(f AST.Expr) AST.Expr {
} }
if t != nil { if t != nil {
// we found a type // we found a type
args := &AST.TypeLit{t}; args := &AST.TypeLit(t);
if P.tok == Scanner.COMMA { if P.tok == Scanner.COMMA {
pos := P.pos; pos := P.pos;
P.next(); P.next();
y := P.parseExpressionList(); y := P.parseExpressionList();
// create list manually because NewExpr checks for type expressions // create list manually because NewExpr checks for type expressions
args := &AST.BinaryExpr{pos, Scanner.COMMA, args, y}; args := &AST.BinaryExpr(pos, Scanner.COMMA, args, y);
} }
call.Args = args; call.Args = args;
} else { } else {
@ -1012,7 +1012,7 @@ func (P *Parser) parseCompositeLit(t *AST.Type) AST.Expr {
} }
P.expect(Scanner.RBRACE); P.expect(Scanner.RBRACE);
return &AST.CompositeLit{pos, t, elts}; return &AST.CompositeLit(pos, t, elts);
} }
@ -1064,9 +1064,9 @@ func (P *Parser) parseUnaryExpr() AST.Expr {
// pointer type // pointer type
t := AST.NewType(pos, AST.POINTER); t := AST.NewType(pos, AST.POINTER);
t.Elt = lit.Typ; t.Elt = lit.Typ;
return &AST.TypeLit{t}; return &AST.TypeLit(t);
} else { } else {
return &AST.UnaryExpr{pos, tok, y}; return &AST.UnaryExpr(pos, tok, y);
} }
} }
@ -1124,12 +1124,12 @@ func (P *Parser) parseSimpleStat(range_ok bool) AST.Stat {
P.opt_semi = true; P.opt_semi = true;
if AST.ExprLen(x) == 1 { if AST.ExprLen(x) == 1 {
if label, is_ident := x.(*AST.Ident); is_ident { if label, is_ident := x.(*AST.Ident); is_ident {
return &AST.LabelDecl{pos, label}; return &AST.LabelDecl(pos, label);
} }
} }
P.error(x.Pos(), "illegal label declaration"); P.error(x.Pos(), "illegal label declaration");
return nil; return nil;
case case
Scanner.DEFINE, Scanner.ASSIGN, Scanner.ADD_ASSIGN, Scanner.DEFINE, Scanner.ASSIGN, Scanner.ADD_ASSIGN,
Scanner.SUB_ASSIGN, Scanner.MUL_ASSIGN, Scanner.QUO_ASSIGN, Scanner.SUB_ASSIGN, Scanner.MUL_ASSIGN, Scanner.QUO_ASSIGN,
@ -1142,7 +1142,7 @@ func (P *Parser) parseSimpleStat(range_ok bool) AST.Stat {
if range_ok && P.tok == Scanner.RANGE { if range_ok && P.tok == Scanner.RANGE {
range_pos := P.pos; range_pos := P.pos;
P.next(); P.next();
y = &AST.UnaryExpr{range_pos, Scanner.RANGE, P.parseExpression(1)}; y = &AST.UnaryExpr(range_pos, Scanner.RANGE, P.parseExpression(1));
if tok != Scanner.DEFINE && tok != Scanner.ASSIGN { if tok != Scanner.DEFINE && tok != Scanner.ASSIGN {
P.error(pos, "expected '=' or ':=', found '" + Scanner.TokenString(tok) + "'"); P.error(pos, "expected '=' or ':=', found '" + Scanner.TokenString(tok) + "'");
} }
@ -1153,21 +1153,21 @@ func (P *Parser) parseSimpleStat(range_ok bool) AST.Stat {
} }
} }
// TODO changed ILLEGAL -> NONE // TODO changed ILLEGAL -> NONE
return &AST.ExpressionStat{x.Pos(), Scanner.ILLEGAL, P.newBinaryExpr(pos, tok, x, y)}; return &AST.ExpressionStat(x.Pos(), Scanner.ILLEGAL, P.newBinaryExpr(pos, tok, x, y));
default: default:
if AST.ExprLen(x) != 1 { if AST.ExprLen(x) != 1 {
P.error(x.Pos(), "only one expression allowed"); P.error(x.Pos(), "only one expression allowed");
} }
if P.tok == Scanner.INC || P.tok == Scanner.DEC { if P.tok == Scanner.INC || P.tok == Scanner.DEC {
s := &AST.ExpressionStat{P.pos, P.tok, x}; s := &AST.ExpressionStat(P.pos, P.tok, x);
P.next(); // consume "++" or "--" P.next(); // consume "++" or "--"
return s; return s;
} }
// TODO changed ILLEGAL -> NONE // TODO changed ILLEGAL -> NONE
return &AST.ExpressionStat{x.Pos(), Scanner.ILLEGAL, x}; return &AST.ExpressionStat(x.Pos(), Scanner.ILLEGAL, x);
} }
unreachable(); unreachable();
@ -1182,7 +1182,7 @@ func (P *Parser) parseInvocationStat(keyword int) *AST.ExpressionStat {
pos := P.pos; pos := P.pos;
P.expect(keyword); P.expect(keyword);
return &AST.ExpressionStat{pos, keyword, P.parseExpression(1)}; return &AST.ExpressionStat(pos, keyword, P.parseExpression(1));
} }
@ -1198,7 +1198,7 @@ func (P *Parser) parseReturnStat() *AST.ExpressionStat {
x = P.parseExpressionList(); x = P.parseExpressionList();
} }
return &AST.ExpressionStat{pos, Scanner.RETURN, x}; return &AST.ExpressionStat(pos, Scanner.RETURN, x);
} }
@ -1207,7 +1207,7 @@ func (P *Parser) parseControlFlowStat(tok int) *AST.ControlFlowStat {
defer un(trace(P, "ControlFlowStat")); defer un(trace(P, "ControlFlowStat"));
} }
s := &AST.ControlFlowStat{P.pos, tok, nil}; s := &AST.ControlFlowStat(P.pos, tok, nil);
P.expect(tok); P.expect(tok);
if tok != Scanner.FALLTHROUGH && P.tok == Scanner.IDENT { if tok != Scanner.FALLTHROUGH && P.tok == Scanner.IDENT {
s.Label = P.parseIdent(P.top_scope); s.Label = P.parseIdent(P.top_scope);
@ -1275,7 +1275,7 @@ func (P *Parser) parseIfStat() *AST.IfStat {
// wrap in a block since we don't have one // wrap in a block since we don't have one
body := AST.NewBlock(0, Scanner.LBRACE); body := AST.NewBlock(0, Scanner.LBRACE);
body.List.Push(else_); body.List.Push(else_);
else_ = &AST.CompositeStat{body}; else_ = &AST.CompositeStat(body);
} }
} else { } else {
P.error(P.pos, "'if' or '{' expected - illegal 'else' branch"); P.error(P.pos, "'if' or '{' expected - illegal 'else' branch");
@ -1283,7 +1283,7 @@ func (P *Parser) parseIfStat() *AST.IfStat {
} }
P.closeScope(); P.closeScope();
return &AST.IfStat{pos, init, cond, body, else_}; return &AST.IfStat(pos, init, cond, body, else_);
} }
@ -1299,7 +1299,7 @@ func (P *Parser) parseForStat() *AST.ForStat {
body := P.parseBlock(nil, Scanner.LBRACE); body := P.parseBlock(nil, Scanner.LBRACE);
P.closeScope(); P.closeScope();
return &AST.ForStat{pos, init, cond, post, body}; return &AST.ForStat(pos, init, cond, post, body);
} }
@ -1318,7 +1318,7 @@ func (P *Parser) parseCaseClause() *AST.CaseClause {
P.expect(Scanner.DEFAULT); P.expect(Scanner.DEFAULT);
} }
return &AST.CaseClause{pos, expr, P.parseBlock(nil, Scanner.COLON)}; return &AST.CaseClause(pos, expr, P.parseBlock(nil, Scanner.COLON));
} }
@ -1341,7 +1341,7 @@ func (P *Parser) parseSwitchStat() *AST.SwitchStat {
P.opt_semi = true; P.opt_semi = true;
P.closeScope(); P.closeScope();
return &AST.SwitchStat{pos, init, tag, body}; return &AST.SwitchStat(pos, init, tag, body);
} }
@ -1371,7 +1371,7 @@ func (P *Parser) parseCommClause() *AST.CaseClause {
P.expect(Scanner.DEFAULT); P.expect(Scanner.DEFAULT);
} }
return &AST.CaseClause{pos, expr, P.parseBlock(nil, Scanner.COLON)}; return &AST.CaseClause(pos, expr, P.parseBlock(nil, Scanner.COLON));
} }
@ -1393,7 +1393,7 @@ func (P *Parser) parseSelectStat() *AST.SelectStat {
P.opt_semi = true; P.opt_semi = true;
P.closeScope(); P.closeScope();
return &AST.SelectStat{pos, body}; return &AST.SelectStat(pos, body);
} }
@ -1404,7 +1404,7 @@ func (P *Parser) parseStatement() AST.Stat {
switch P.tok { switch P.tok {
case Scanner.CONST, Scanner.TYPE, Scanner.VAR: case Scanner.CONST, Scanner.TYPE, Scanner.VAR:
return &AST.DeclarationStat{P.parseDeclaration()}; return &AST.DeclarationStat(P.parseDeclaration());
case Scanner.FUNC: case Scanner.FUNC:
// for now we do not allow local function declarations, // for now we do not allow local function declarations,
// instead we assume this starts a function literal // instead we assume this starts a function literal
@ -1422,7 +1422,7 @@ func (P *Parser) parseStatement() AST.Stat {
case Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO, Scanner.FALLTHROUGH: case Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO, Scanner.FALLTHROUGH:
return P.parseControlFlowStat(P.tok); return P.parseControlFlowStat(P.tok);
case Scanner.LBRACE: case Scanner.LBRACE:
return &AST.CompositeStat{P.parseBlock(nil, Scanner.LBRACE)}; return &AST.CompositeStat(P.parseBlock(nil, Scanner.LBRACE));
case Scanner.IF: case Scanner.IF:
return P.parseIfStat(); return P.parseIfStat();
case Scanner.FOR: case Scanner.FOR:
@ -1433,12 +1433,12 @@ func (P *Parser) parseStatement() AST.Stat {
return P.parseSelectStat(); return P.parseSelectStat();
case Scanner.SEMICOLON: case Scanner.SEMICOLON:
// don't consume the ";", it is the separator following the empty statement // don't consume the ";", it is the separator following the empty statement
return &AST.EmptyStat{P.pos}; return &AST.EmptyStat(P.pos);
} }
// no statement found // no statement found
P.error(P.pos, "statement expected"); P.error(P.pos, "statement expected");
return &AST.BadStat{P.pos}; return &AST.BadStat(P.pos);
} }
@ -1459,7 +1459,7 @@ func (P *Parser) parseImportSpec(d *AST.Decl) {
if P.tok == Scanner.STRING { if P.tok == Scanner.STRING {
// TODO eventually the scanner should strip the quotes // TODO eventually the scanner should strip the quotes
d.Val = &AST.BasicLit{P.pos, Scanner.STRING, P.val}; d.Val = &AST.BasicLit(P.pos, Scanner.STRING, P.val);
P.next(); P.next();
} else { } else {
P.expect(Scanner.STRING); // use expect() error handling P.expect(Scanner.STRING); // use expect() error handling
@ -1513,7 +1513,7 @@ func (P *Parser) parseVarSpec(d *AST.Decl) {
func (P *Parser) parseSpec(d *AST.Decl) { func (P *Parser) parseSpec(d *AST.Decl) {
kind := SymbolTable.NONE; kind := SymbolTable.NONE;
switch d.Tok { switch d.Tok {
case Scanner.IMPORT: P.parseImportSpec(d); kind = SymbolTable.PACKAGE; case Scanner.IMPORT: P.parseImportSpec(d); kind = SymbolTable.PACKAGE;
case Scanner.CONST: P.parseConstSpec(d); kind = SymbolTable.CONST; case Scanner.CONST: P.parseConstSpec(d); kind = SymbolTable.CONST;

View file

@ -26,10 +26,10 @@ func f1() {
func CompositeLiterals() { func CompositeLiterals() {
a1 := []int{}; a1 := []int();
a2 := []int{0, 1, 2, }; a2 := []int(0, 1, 2, );
a3 := []int{0, 1, 2, /* ERROR single value expected */ 3 : 4, 5}; /* SYNC */ a3 := []int(0, 1, 2, /* ERROR single value expected */ 3 : 4, 5); /* SYNC */
a1 := []int{0 : 1, 2 : 3, /* ERROR key:value pair expected */ 4, }; /* SYNC */ a1 := []int(0 : 1, 2 : 3, /* ERROR key:value pair expected */ 4, ); /* SYNC */
} }

View file

@ -46,9 +46,9 @@ var (
aa = 5; aa = 5;
u, v, w int = 0, 0, 0; u, v, w int = 0, 0, 0;
foo = "foo"; foo = "foo";
fixed_array0 = [10]int{}; fixed_array0 = [10]int();
fixed_array1 = [10]int{0, 1, 2}; fixed_array1 = [10]int(0, 1, 2);
fixed_array2 = [...]string{"foo", "bar"}; fixed_array2 = [...]string("foo", "bar");
) )
@ -136,7 +136,7 @@ func main() {
println(i + 1000); // the index + 1000 println(i + 1000); // the index + 1000
println(); println();
} }
f3(&[]int{2, 3, 5, 7}, map[string]int{"two":2, "three":3, "five":5, "seven":7}); f3(&[]int(2, 3, 5, 7), map[string]int("two":2, "three":3, "five":5, "seven":7));
// the epilogue // the epilogue
println("foo"); // foo println("foo"); // foo
println("foobar"); // foobar println("foobar"); // foobar