Skip to content

Instantly share code, notes, and snippets.

@emidoots
Created May 6, 2021 23:59
Show Gist options
  • Save emidoots/a8382ad1126e2d214659ed83f3a820f4 to your computer and use it in GitHub Desktop.
Save emidoots/a8382ad1126e2d214659ed83f3a820f4 to your computer and use it in GitHub Desktop.

Index

Package testdata

testdata is a small package containing sample Go source code used for testing the indexing routines of github.com/sourcegraph/lsif-go.

Index

const Const = 5

Const is a constant equal to 5. It's the best constant I've ever written. 😹

const ConstBlock1 = 1

Docs for the const block itself.

ConstBlock1 is a constant in a block.

const ConstBlock2 = 2

Docs for the const block itself.

ConstBlock2 is a constant in a block.

const Score = uint64(42)

Score is just a hardcoded number.

const secretScore = secret.SecretScore
var Var Interface = ...

Var is a variable interface.

var unexportedVar Interface = ...

unexportedVar is an unexported variable interface.

var BigVar Interface = ...
var VarBlock1 = "if you're reading this"

What are docs, really? I can't say for sure, I don't write any. But look, a CAT!

      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'
    '---''(_/--'  `-'\_)

It's sleeping! Some people write that as sleeping but Markdown isn't allowed in Go docstrings, right? right?!

This has some docs

var VarBlock2 = "hi"

What are docs, really? I can't say for sure, I don't write any. But look, a CAT!

      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'
    '---''(_/--'  `-'\_)

It's sleeping! Some people write that as sleeping but Markdown isn't allowed in Go docstrings, right? right?!

var _ = Interface(&Struct{})

Yeah this is some Go magic incantation which is common.

 ,_     _
 |\\_,-~/
 / _  _ |    ,--.
(  @  @ )   / ,-'
 \  _T_/-._( (
/         `. \
|         _  \ |
\ \ ,  /      |
 || |-_\__   /
((_/`(____,-'

var wg sync.WaitGroup
type Embedded struct {
	// EmbeddedField has some docs!
	EmbeddedField string
	Field         string // conflicts with parent "Field"
}

Embedded is a struct, to be embedded in another struct.

type Struct struct {
	*Embedded
	Field     string
	Anonymous struct {
		FieldA int
		FieldB int
		FieldC int
	}
}
type Interface interface {
	ImplementsInterface() string
}

Interface has docs too

func NewInterface() Interface
type X struct {
	bar string
}

Go can be fun

And confusing

type Y struct {
	baz float
}

Go can be fun

type TestInterface interface {
	// Do does a test thing.
	Do(ctx context.Context, data string) (score int, _ error)
}

TestInterface is an interface used for testing.

type TestStruct struct {
	// SimpleA docs
	SimpleA int
	// SimpleB docs
	SimpleB int
	// SimpleC docs
	SimpleC int

	FieldWithTag           string `json:"tag"`
	FieldWithAnonymousType struct {
		NestedA string
		NestedB string
		// NestedC docs
		NestedC string
	}

	EmptyStructField struct{}
}

TestStruct is a struct used for testing.

func (ts *TestStruct) Doer(ctx context.Context, data string) (score int, err error)

Doer is similar to the test interface (but not the same).

type TestEmptyStruct struct{}
type StructTagRegression struct {
	Value int `key:",range=[:}"`
}

StructTagRegression is a struct that caused panic in the wild. Added here to support a regression test.

See https://github.com/tal-tech/go-zero/blob/11dd3d75ecceaa3f5772024fb3f26dec1ada8e9c/core/mapping/unmarshaler_test.go#L2272.

type TestEqualsStruct = struct {
	Value int
}
type ParallelizableFunc func(ctx context.Context) error

ParallelizableFunc is a function that can be called concurrently with other instances of this function type.

type SecretBurger = secret.Burger

Type aliased doc

type BadBurger = struct {
	Field string
}
func Parallel(ctx context.Context, fns ...ParallelizableFunc) error

Parallel invokes each of the given parallelizable functions in their own goroutines and returns the first error to occur. This method will block until all goroutines have returned.

func Switch(interfaceValue interface{}) bool

secret is a package that holds secrets.

Index

const SecretScore = uint64(43)

SecretScore is like score but secret.

type Burger struct {
	Field int
}

Original doc

This package has no tests.

Index

func foo() bool

This package has tests.

Index

func foo() bool
func TestFoo(t *testing.T)

This package has tests, but in a separate _test package.

Index

func foo() bool

Index

func TestFoo(t *testing.T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment