code
stringlengths
10
1.34M
language
stringclasses
1 value
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main type Element interface { } type Vector struct { } func (v *Vector) Insert(i int, e Element) { } func main() { type I struct { val int...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func dosplit(wait chan int ){ select { case <-wait: } } func main() { }
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 873, 2162 package foo func f(x interface{}) { switch t := x.(type) { // ERROR "declared and not used" case int: } } func g(x int...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main // 5g bug used to set up the 0 for -f() before calling f, // and the call to f smashed the register. func f(n int) int { s := 0 for i ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test the behavior of closures. package main import "runtime" var c = make(chan int) func check(a []int) { for i := 0; i < len(a); i++ { n := <...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test floating-point comparison involving NaN. package main import "math" type floatTest struct { name string expr bool want bool } var nan flo...
Go
// cmpout // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that big numbers work as constants and print can print them. package main func main() { print(-(1<<63), "\n") print((1<<63)-1, "\n") }
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test behavior of the blank identifier (_). package main import _ "fmt" var call string type T struct { _, _, _ int } func (T) _() { } func (T)...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that import conflicts are detected by the compiler. // Does not compile. package main import "bufio" // GCCGO_ERROR "previous|not use...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that goroutines and garbage collection run during init. package main import "runtime" var x []byte func init() { c := make(chan int) go s...
Go
// compile // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test function signatures. // Compiled but not run. package main type t1 int type t2 int type t3 int func f1(t1, t2, t3) func f2(t1, t2, t3 boo...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simulating a Turing machine, sort of. package main // brainfuck var p, pc int var a [30000]byte const prog = "++++++++++[>+++++++>++++++++++...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify overflow is detected when using numeric constants. // Does not compile. package main type I interface{} const ( // assume all types...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test the internal "algorithms" for objects larger than a word: hashing, equality etc. package main type T struct { a float64 b int64 c string d...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test character literal syntax. package main import "os" func main() { var i uint64 = ' ' + 'a' + 'ä' + '本' + '\a' + '\b' + '\f' + ...
Go
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go || echo BUG:bug434 // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package ignored
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package one // Issue 3552 type T struct { int } func (t T) F() int { return t.int } type U struct { int int } func (u U) F() int { return u.int } type li...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Use the functions in one.go so that the inlined // forms get type-checked. package two import "./one" func use() { var t one.T var u one.U var v one.V...
Go
// $G $D/$F.go && $L $F.$A && ./$A.out // # switch above to 'run' when bug gets fixed. // # right now it only breaks on 8g // Test for 8g register move bug. The optimizer gets confused // about 16- vs 32-bit moves during splitContractIndex. package main func main() { const c = 0x12345678 index, n, offset := split...
Go
// echo bug395 is broken # takes 90+ seconds to break // # $G $D/$F.go || echo bug395 // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 1909 // Would OOM due to exponential recursion on Foo's expand...
Go
// errorcheck // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that illegal uses of ... are detected. // Does not compile. package main import "unsafe" func sum(args ...int) int { return 0 } va...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test illegal shifts. // Issue 1708, illegal cases. // Does not compile. package p func f(x int) int { return 0 } func g(x interface...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test initialization of package-level variables. package main import "fmt" import "reflect" type S struct { A, B, C, X, Y, Z int } type T struct ...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test of basic recover functionality. package main import "runtime" func main() { test1() test1WithClosures() test2() test3() test4() test5(...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that illegal uses of indirection are caught by the compiler. // Does not compile. package main var m0 map[string]int var m1 *map[stri...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that large integer constant expressions cause overflow. // Does not compile. package main const ( A int = 1 B byte; // ERROR "type ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // A simple test of the garbage collector. package main func main() { for i := 0; i < 1e5; i++ { x := new([100]byte) _ = x } }
Go
// errorcheck // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test line numbers in error messages. // Does not compile. package main var ( _ = x // ERROR "undefined.*x" _ = x // ERROR "undefined.*x" ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test for loops. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail", msg, "\n") panic(1) ...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify simple assignment errors are caught by the compiler. // Does not compile. package main import "sync" type T struct { int sync.Mute...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that basic operations on named types are valid // and preserve the type. // Does not compile. package main type Bool bool type Map ma...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test the 'for range' construct. package main // test range over channels func gen(c chan int, lo, hi int) { for i := lo; i <= hi; i++ { c <- i ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test switch statements. package main import "os" func assert(cond bool, msg string) { if !cond { print("assertion fail: ", msg, "\n") panic(1...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test of recover for run-time errors. // TODO(rsc): // null pointer accesses package main import "strings" var x = make([]byte, 10) func main() ...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test evaluation order. package main var calledf int func f() int { calledf++ return 0 } func g() int { return calledf } var xy string func ...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test closures in if conditions. package main func main() { if func() bool { return true }() {} // 6g used to say this was a syntax error if (fu...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test UTF-8 in strings and character constants. package main import "unicode/utf8" func main() { var chars [6]rune chars[0] = 'a' chars[1] = 'b'...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that error messages say what the source file says // (uint8 vs byte, int32 vs. rune). // Does not compile. package main import ( "fmt...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test zero length structs. // Used to not be evaluated. // Issue 2232. package main func recv(c chan interface{}) struct{} { return (<-c).(struct{...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test literal syntax for basic types. package main var nbad int func assert(cond bool, msg string) { if !cond { if nbad == 0 { print("BUG") ...
Go
// compile // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test legal shifts. // Issue 1708, legal cases. // Compiles but does not run. package p func f(x int) int { return 0 } func g(x interfa...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that even if a file imports runtime, // it cannot get at the low-level runtime definitions // known to the compiler. For normal package...
Go
// runoutput // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test source files and strings containing \r and \r\n. package main import ( "fmt" "strings" ) func main() { prog = strings.Replace(prog, ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test integer literal syntax. package main import "os" func main() { s := 0 + 123 + 0123 + 0000 + 0x0 + 0x123 + 0X0 + 0X123 if s !...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test methods on slices. package main type T []int func (t T) Len() int { return len(t) } type I interface { Len() int } func main() { var t T ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that heavy recursion works. Simple torture test for // segmented stacks: do math in unary by recursion. package main type Number *Number // -...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test variadic functions and calls (dot-dot-dot). package main func sum(args ...int) int { s := 0 for _, v := range args { s += v } return s ...
Go
// Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Garbage collection benchmark: parse Go packages repeatedly. package main import ( "flag" "fmt" "go/ast" "go/parser" "go/token" "log" "net/http" _ ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "runtime" "time" ) type Number struct { next *Number } // ------------------------------------- // Peano primitives ...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "flag" "fmt" "log" "os" "runtime" "runtime/pprof" "time" "unsafe" ) const BranchingFactor = 4 type Object struct { child [Bra...
Go
/* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form ...
Go
// Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "runtime" "sort" "time" ) func gcstats(name string, n int, t time.Duration) { st := new(runtime.MemStats) runtime.ReadMemSt...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that erroneous type switches are caught be the compiler. // Issue 2700, among other things. // Does not compile. package main import ...
Go
// [ "$GORUN" == "" ] || exit 0 # Android runner gets confused by the NUL output // $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && // errchk $G -e tmp.go // rm -f tmp.go // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LI...
Go
// compile // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that when import gives multiple names // to a single type, they still all refer to the same type. package main import _os_ "os" import "os...
Go
// $G $D/empty.go && errchk $G $D/$F.go // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that various kinds of "imported and not used" // errors are caught by the compiler. // Does not compile. pac...
Go
// build // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test general operation by solving a peg solitaire game. // A version of this is in the Go playground. // Don't run it - produces too much output. ...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test reorderings; derived from fixedbugs/bug294.go. package main var log string type TT int func (t TT) a(s string) TT { log += "a(" + s + ")" ...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify allowed and disallowed conversions. // Does not compile. package main // everything here is legal except the ERROR line var c chan i...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that the Go environment variables are present and accessible through // package os and package runtime. package main import ( "os" "runtime"...
Go
// build // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test basic concurrency: the classic prime sieve. // Do not run - loops forever. package main // Send the sequence 2, 3, 4, ... to channel 'ch'. f...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test types of constant expressions, using reflect. package main import "reflect" func typeof(x interface{}) string { return reflect.TypeOf(x).Stri...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Semi-exhaustive test for the append predeclared function. package main import ( "fmt" "reflect" ) func verify(name string, result, expected int...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test close(c), receive of closed channel. // // TODO(rsc): Doesn't check behavior of close(c) when there // are blocked senders/receivers. package m...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Internally a map holds elements in up to 255 bytes of key+value. // When key or value or both are too large, it uses pointers to key+value // instead...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple methods of various types, with pointer and // value receivers. package main type S string type S1 string type I int type I1 int type T ...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that erroneous use of init is detected. // Does not compile. package main import "runtime" func init() { } func main() { init() ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test functions and goroutines. package main func caller(f func(int, int) int, a, b int, c chan int) { c <- f(a, b) } func gocall(f func(int, int)...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that buffered channels are garbage collected properly. // An interesting case because they have finalizers and used to // have self loops that ...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that illegal assignments with both explicit and implicit conversions of literals are detected. // Does not compile. package main // e...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that erroneous switch statements are detected by the compiler. // Does not compile. package main type I interface { M() } func bad(...
Go
// runoutput // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Generate test of 64-bit arithmetic. // Most synthesized routines have different cases for // constants vs variables and even the generated code...
Go
//line x18.go:4 package main func F18() {}
Go
//line x7.go:4 package main func F7() {}
Go
// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func main() { F1() F2() F3() F4() F5() F6() F7() F8() F9() F10() F11() F12() F13() F14() F15() F16...
Go
//line x11.go:4 package main func F11() {}
Go
//line x8.go:4 package main func F8() {}
Go
//line x16.go:4 package main func F16() {}
Go
//line x9.go:4 package main func F9() {}
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //line foo/bar.y:4 package main //line foo/bar.y:60 func main() { //line foo/bar.y:297 f, l := 0, 0 //line yacctab:1 f, l = 1, 1 //line yaccpar:1 f,...
Go
//line x15.go:4 package main func F15() {}
Go
//line x10.go:4 package main func F10() {}
Go
//line x12.go:4 package main func F12() {}
Go
//line x14.go:4 package main func F14() {}
Go
//line x4.go:4 package main func F4() {}
Go
//line x20.go:4 package main func F20() {}
Go
//line x3.go:4 package main func F3() {}
Go
//line x2.go:4 package main func F2() {}
Go
//line x19.go:4 package main func F19() {}
Go
//line x13.go:4 package main func F13() {}
Go
//line x5.go:4 package main func F5() {}
Go
//line x1.go:4 package main func F1() {}
Go
//line x17.go:4 package main func F17() {}
Go
//line x6.go:4 package main func F6() {}
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that predeclared names can be redeclared by the user. package main import "fmt" func main() { n := append + bool + byte + comple...
Go
// compile // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test rune constants, expressions and types. // Compiles but does not run. package rune var ( r0 = 'a' r1 = 'a'+1 r2 = 1+'a' r3 = 'a'*2 r4...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify assignment rules are enforced by the compiler. // Does not compile. package main type ( A [10]int B []int C chan int F func() int...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test integer division and modulus. package main const ( // example from the spec n1 = +5 n2 = -5 d1 = +3 d2 = -3 q1 = +1 q2 = -1 q3 = -1 ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple multi-argument multi-valued function. package main func main() { var x,y int; x,y = simple(10,20,30); if x+y != 65 { panic(x+y); } ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test general operation using s-list. // First Go program ever run (although not in this exact form). package main import "fmt" const nilchar = 0 ...
Go