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.
// Test typed integer constants.
package main
import "fmt"
type T int
func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
const (
A T... | 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 unsafe.Sizeof, unsafe.Alignof, and unsafe.Offsetof all return uintptr.
package main
import "unsafe"
type T struct {
X int
}
var t T
f... | 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 pointers and interface types cannot be method receivers.
// Does not compile.
package main
type T struct {
a int
}
type P *T
ty... | 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 len non-constants are not constants, http://golang.org/issue/3244.
package p
var b struct {
a[10]int
}
var m map[string][20]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 len constants and non-constants, http://golang.org/issue/3244.
package main
var b struct {
a[10]int
}
var m map[string][20]int
var s [][30]... | Go |
// compile
// 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 a source file does not need a final newline.
// Compiles but does not run.
// No newline at the end of this file.
package main | 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 basic operations on named types are valid
// and preserve the type.
package main
type Array [10]byte
type Bool bool
type Chan chan int
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 trailing commas. DO NOT gofmt THIS FILE.
package main
var a = []int{1, 2, }
var b = [5]int{1, 2, 3, }
var c = []int{1, }
var d = [...]int{1, 2... | Go |
// skip # used by import3
// 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.
// Various declarations of exported variables and functions.
// Imported by import3.go.
package p
var C1 chan <- chan int = (chan<... | 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 it is illegal to take the address of a function.
// Does not compile.
package main
var notmain func()
func main() {
var x = &m... | 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 function signatures are detected.
// Does not compile.
package main
type t1 int
type t2 int
type t3 int
func f1(*t2, x ... | 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 the implementation catches nil ptr indirection
// in a large address space.
package main
import "unsafe"
// Having a big address space ... | 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 nil.
package main
import (
"fmt"
"time"
)
type T struct {
i int
}
type IN interface{}
func main() {
var i *int
var f *float32
var s *... | 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 the run-time behavior of escape analysis-related optimizations.
package main
func main() {
test1()
}
func test1() {
check1(0)
check1(1)
... | Go |
// $G $D/import2.go && $G $D/$F.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.
// Test that all the types from import2.go made it
// intact and with the same meaning, by assigning to or using them.
pac... | Go |
// $G $F.go && $L $F.$A && ./$A.out arg1 arg2
// 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 os.Args.
package main
import "os"
func main() {
if len(os.Args) != 3 {
panic("argc")
}
if os.Args... | Go |
/*
This is a little test app that demonstrates how goweb
is to be used in a real application.
INSTALL GOWEB
=============
You may need to install 'goweb' in order to import it here.
To do this navigate to the 'goweb/goweb' directory in a terminal
and type:
gomake install
This should put a copy of gowe... | Go |
package goweb
import (
"regexp"
"strings"
)
/*
Route
*/
// Represents a single route mapping
type Route struct {
pattern string
parameterKeys ParameterKeyMap
extension string
Path string
Controller Controller
MatcherFuncs []RouteMatcherFunc
}
func (r *Route) String() string {
return... | Go |
package goweb
/*
Constants
*/
// Regex placeholder pattern
var ROUTE_REGEX_PLACEHOLDER string = "(.*)"
// HTTP Methods
const GET_HTTP_METHOD string = "GET"
const POST_HTTP_METHOD string = "POST"
const PUT_HTTP_METHOD string = "PUT"
const DELETE_HTTP_METHOD string = "DELETE"
/*
Error messages
*/
const ERR_STANDARD... | Go |
package goweb
// Handler method to read an item by the specified ID
type RestReader interface {
Read(id string, c *Context)
}
// Handler method to read many items
type RestManyReader interface {
ReadMany(c *Context)
}
// Handler method to update a single item specified by the ID
type RestUpdater interface {
Updat... | Go |
package goweb
/*
RouteManager
*/
// Manages routes and matching
type RouteManager struct {
routes []*Route
}
// Creates a route that maps the specified path to the specified controller
// along with any optional RouteMatcherFunc modifiers
func (manager *RouteManager) Map(path string, controller Controller, matcher... | Go |
package goweb
// Represents the return value for RouteMatcher functions
type RouteMatcherFuncValue int
// Functions used to decide whether a route matches a request or not
type RouteMatcherFunc func(c *Context) RouteMatcherFuncValue
// Indicates that the RouteMatcherFunc doesn't care whether the
// route is a Match ... | Go |
package goweb
import (
"net/http"
"strings"
)
// Constant string for HTML format
const HTML_FORMAT string = "HTML"
// Constant string for XML format
const XML_FORMAT string = "XML"
// Constant string for JSON format
const JSON_FORMAT string = "JSON"
// The fallback format if one cannot be determined by the reque... | Go |
package goweb
import (
"errors"
"fmt"
"net/http"
)
// CookieIsMissing is returned when a cookie is missing.
var CookieIsMissing error = errors.New("Cookie is missing")
// SignedCookieIsMissing is returned when the signed cookie is missing.
var SignedCookieIsMissing error = errors.New("Signed cookie is missing")
... | Go |
package goweb
// Holds parameter keys and actual values
type ParameterValueMap map[string]string
| Go |
package goweb
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"strings"
)
// types that impliment RequestDecoder can unmarshal
// the request body into an apropriate type/struct
type RequestDecoder interface {
Unmarshal(cx *Context, v interface{}) error
}
// a JSON decoder for request body (just a w... | Go |
package goweb
import "net/http"
// The standard API response object
type standardResponse struct {
// The context of the request that initiated this response
C string
// The HTTP Status code of this response
S int
// The data (if any) for this response
D interface{}
// A list of any errors that occurred wh... | Go |
package goweb
import (
"fmt"
"log"
"net/http"
"runtime/debug"
"strings"
)
// Wraps a controllerFunc to catch any panics, log them and
// respond with an appropriate error
func safeControllerFunc(controllerFunc func(*Context)) func(*Context) {
return func(cx *Context) {
defer func() {
if err := recover(); e... | Go |
package goweb
import "strings"
/*
Path parsing
*/
// Tests whether a path segment is dynamic or not
func isDynamicSegment(segment string) bool {
return strings.HasPrefix(segment, "{") && strings.HasSuffix(segment, "}")
}
func isExtensionSegment(segment string) bool {
return strings.HasPrefix(segment, ".")
}
// ... | Go |
package goweb
import (
"net/http"
"strings"
)
// Object holding details about the request and responses
type Context struct {
// The underlying http.Request for this context
Request *http.Request
// The underlying http.ResponseWriter for this context
ResponseWriter http.ResponseWriter
// A ParameterValueMap... | Go |
package goweb
import (
"crypto/sha1"
"fmt"
)
// HashSecret represents a secret string that is used to hash cookies.
//
// For true security, this should be changed for each application.
var HashSecret string = "cX8Os0wfB6uCGZZSZHIi6rKsy7b0scE9"
// Hash one-way hashes a string with the private HashSecret value.
fu... | Go |
package goweb
// Interface for controller types that handle requests
type Controller interface {
// When implemented, handles the request
HandleRequest(c *Context)
}
// The ControllerFunc type is an adapter to allow the use of
// ordinary functions as goweb handlers. If f is a function
// with the appropriate sig... | Go |
package goweb
import (
"errors"
"net/http"
"strings"
)
// A handler type to handle actual http requests using the
// DefaultRouteManager to route requests to the right places
type HttpHandler struct{}
// Serves the HTTP request and writes the response to the specified writer
func (handler *HttpHandler) ServeHTTP(... | Go |
package goweb
import (
"encoding/json"
"errors"
"strings"
)
// Interface describing an object responsible for
// handling transformed/formatted response data
type Formatter interface {
// method to transform response
Format(context *Context, input interface{}) ([]uint8, error)
// method that decides if this fo... | Go |
package goweb
import (
"fmt"
"net/url"
"reflect"
"strconv"
)
// Fill a struct `v` from the values in `form`
func UnmarshalForm(form url.Values, v interface{}) error {
// check v is valid
rv := reflect.ValueOf(v).Elem()
// dereference pointer
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// get type
rt :... | Go |
package goweb
// Holds parameter keys and their respective positions in the path
type ParameterKeyMap map[string]int
| Go |
package goweb
import (
"regexp"
"strings"
)
/*
Route
*/
// Represents a single route mapping
type Route struct {
pattern string
parameterKeys ParameterKeyMap
extension string
Path string
Controller Controller
MatcherFuncs []RouteMatcherFunc
}
func (r *Route) String() string {
return... | Go |
package goweb
/*
Constants
*/
// Regex placeholder pattern
var ROUTE_REGEX_PLACEHOLDER string = "(.*)"
// HTTP Methods
const GET_HTTP_METHOD string = "GET"
const POST_HTTP_METHOD string = "POST"
const PUT_HTTP_METHOD string = "PUT"
const DELETE_HTTP_METHOD string = "DELETE"
/*
Error messages
*/
const ERR_STANDARD... | Go |
package goweb
// Handler method to read an item by the specified ID
type RestReader interface {
Read(id string, c *Context)
}
// Handler method to read many items
type RestManyReader interface {
ReadMany(c *Context)
}
// Handler method to update a single item specified by the ID
type RestUpdater interface {
Updat... | Go |
package goweb
/*
RouteManager
*/
// Manages routes and matching
type RouteManager struct {
routes []*Route
}
// Creates a route that maps the specified path to the specified controller
// along with any optional RouteMatcherFunc modifiers
func (manager *RouteManager) Map(path string, controller Controller, matcher... | Go |
package goweb
// Represents the return value for RouteMatcher functions
type RouteMatcherFuncValue int
// Functions used to decide whether a route matches a request or not
type RouteMatcherFunc func(c *Context) RouteMatcherFuncValue
// Indicates that the RouteMatcherFunc doesn't care whether the
// route is a Match ... | Go |
package goweb
import (
"net/http"
"strings"
)
// Constant string for HTML format
const HTML_FORMAT string = "HTML"
// Constant string for XML format
const XML_FORMAT string = "XML"
// Constant string for JSON format
const JSON_FORMAT string = "JSON"
// The fallback format if one cannot be determined by the reque... | Go |
package goweb
import (
"errors"
"fmt"
"net/http"
)
// CookieIsMissing is returned when a cookie is missing.
var CookieIsMissing error = errors.New("Cookie is missing")
// SignedCookieIsMissing is returned when the signed cookie is missing.
var SignedCookieIsMissing error = errors.New("Signed cookie is missing")
... | Go |
package goweb
// Holds parameter keys and actual values
type ParameterValueMap map[string]string
| Go |
package goweb
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"strings"
)
// types that impliment RequestDecoder can unmarshal
// the request body into an apropriate type/struct
type RequestDecoder interface {
Unmarshal(cx *Context, v interface{}) error
}
// a JSON decoder for request body (just a w... | Go |
package goweb
import "net/http"
// The standard API response object
type standardResponse struct {
// The context of the request that initiated this response
C string
// The HTTP Status code of this response
S int
// The data (if any) for this response
D interface{}
// A list of any errors that occurred wh... | Go |
package goweb
import (
"fmt"
"log"
"net/http"
"runtime/debug"
"strings"
)
// Wraps a controllerFunc to catch any panics, log them and
// respond with an appropriate error
func safeControllerFunc(controllerFunc func(*Context)) func(*Context) {
return func(cx *Context) {
defer func() {
if err := recover(); e... | Go |
package goweb
import "strings"
/*
Path parsing
*/
// Tests whether a path segment is dynamic or not
func isDynamicSegment(segment string) bool {
return strings.HasPrefix(segment, "{") && strings.HasSuffix(segment, "}")
}
func isExtensionSegment(segment string) bool {
return strings.HasPrefix(segment, ".")
}
// ... | Go |
package goweb
import (
"net/http"
"strings"
)
// Object holding details about the request and responses
type Context struct {
// The underlying http.Request for this context
Request *http.Request
// The underlying http.ResponseWriter for this context
ResponseWriter http.ResponseWriter
// A ParameterValueMap... | Go |
package goweb
import (
"crypto/sha1"
"fmt"
)
// HashSecret represents a secret string that is used to hash cookies.
//
// For true security, this should be changed for each application.
var HashSecret string = "cX8Os0wfB6uCGZZSZHIi6rKsy7b0scE9"
// Hash one-way hashes a string with the private HashSecret value.
fu... | Go |
package goweb
// Interface for controller types that handle requests
type Controller interface {
// When implemented, handles the request
HandleRequest(c *Context)
}
// The ControllerFunc type is an adapter to allow the use of
// ordinary functions as goweb handlers. If f is a function
// with the appropriate sig... | Go |
package goweb
import (
"errors"
"net/http"
"strings"
)
// A handler type to handle actual http requests using the
// DefaultRouteManager to route requests to the right places
type HttpHandler struct{}
// Serves the HTTP request and writes the response to the specified writer
func (handler *HttpHandler) ServeHTTP(... | Go |
package goweb
import (
"encoding/json"
"errors"
"strings"
)
// Interface describing an object responsible for
// handling transformed/formatted response data
type Formatter interface {
// method to transform response
Format(context *Context, input interface{}) ([]uint8, error)
// method that decides if this fo... | Go |
package goweb
import (
"fmt"
"net/url"
"reflect"
"strconv"
)
// Fill a struct `v` from the values in `form`
func UnmarshalForm(form url.Values, v interface{}) error {
// check v is valid
rv := reflect.ValueOf(v).Elem()
// dereference pointer
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
// get type
rt :... | Go |
package goweb
// Holds parameter keys and their respective positions in the path
type ParameterKeyMap map[string]int
| 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 unsafe.Sizeof, unsafe.Alignof, and unsafe.Offsetof all return uintptr.
package main
import "unsafe"
type T struct {
X int
}
var t T
f... | Go |
// run cmplxdivide1.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.
// Driver for complex division table defined in cmplxdivide1.go
package main
import (
"fmt"
"math"
"math/cmplx"
)
type Test struc... | 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.
// Solve the 2,3,5 problem (print all numbers with 2, 3, or 5 as factor) using channels.
// Test the solution, silently.
package main
type T chan uint... | 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 |
// cmpout
// 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 println can be the target of a go statement.
package main
import "time"
func main() {
go println(42, true, false, true, 1.5, "world... | 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 |
// skip
// 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.
// Run runs tests in the test directory.
//
// TODO(bradfitz): docs of some sort, once we figure out how we're changing
// headers of files
package m... | 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 illegal composite literals are detected.
// Does not compile.
package main
var m map[int][3]int
func f() [3]int
func fp() *[3... | 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 typed integer constants.
package main
import "fmt"
type T int
func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
const (
A 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 simultaneous assignment.
package main
var a, b, c, d, e, f, g, h, i int
func printit() {
println(a, b, c, d, e, f, g, h, i)
}
func testit(p... | 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 |
// 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 |
// 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 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.
// 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 |
// $G $D/import2.go && $G $D/$F.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.
// Test that all the types from import2.go made it
// intact and with the same meaning, by assigning to or using them.
pac... | Go |
// compile
// 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 a source file does not need a final newline.
// Compiles but does not run.
// No newline at the end of this file.
package main | Go |
// $G $F.go && $L $F.$A && ./$A.out arg1 arg2
// 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 os.Args.
package main
import "os"
func main() {
if len(os.Args) != 3 {
panic("argc")
}
if os.Args... | 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 dynamic interface checks treat byte=uint8
// and rune=int or rune=int32.
package main
func main() {
var x interface{}
x = byte(1)
sw... | 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.
// Semi-exhaustive test for the copy predeclared function.
package main
import (
"fmt"
"os"
)
const N = 40
var input8 = make([]uint8, N)
var outpu... | 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 illegal conversions involving strings are detected.
// Does not compile.
package main
type Tbyte []byte
type Trune []rune
type ... | 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 |
// 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 |
// 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 during recursive panics.
// Here be dragons.
package main
import "runtime"
func main() {
test1()
test2()
test3()
test4()
tes... | 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 nil.
package main
import (
"fmt"
"time"
)
type T struct {
i int
}
type IN interface{}
func main() {
var i *int
var f *float32
var s *... | Go |
// skip
// 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.
// Test method expressions with arguments.
// This file is not tested by itself; it is imported by method4.go.
package method4a
type T1 int
type T2 ... | 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 |
// 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 returning &T{} from a function causes an allocation.
package main
type T struct {
int
}
func f() *T {
return &T{1}
}
func main() {
... | 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 incorrect short declarations and redeclarations are detected.
// Does not compile.
package main
func f1() 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 zero length structs.
// Used to not be evaluated.
// Issue 2232.
package main
func recv(c chan interface{}) struct{} {
return (<-c).(struct{... | 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 in if condition.
package main
var calledf = false
func f() int {
calledf = true
return 1
}
func g() int {
if !calledf {... | 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 len non-constants are not constants, http://golang.org/issue/3244.
package p
var b struct {
a[10]int
}
var m map[string][20]int
... | 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 result parameters are in the same scope as regular parameters.
// Does not compile.
package main
func f1(a int) (int, float32) {
... | 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 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 |
// $G $D/ddd2.go && $G $D/$F.go && $L $F.$A && ./$A.out
// 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 that variadic functions work across package boundaries.
package main
import "./ddd2"
func 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.
// Test that predeclared names can be redeclared by the user.
package main
import "fmt"
func main() {
n :=
append +
bool +
byte +
comple... | 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 |
// 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 |
// 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 boolean and numeric constants.
package main
const (
c0 = 0
cm1 = -1
chuge = 1 << 100
chuge_1 = chuge - 1
c1 = chuge >> 100
c3div2... | 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 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 erroneous type switches are caught be the compiler.
// Does not compile.
package main
import "io"
func whatis(x interfa... | 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 trailing commas. DO NOT gofmt THIS FILE.
package main
var a = []int{1, 2, }
var b = [5]int{1, 2, 3, }
var c = []int{1, }
var d = [...]int{1, 2... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.