Skip to content

Commit

Permalink
Merge pull request #409 from xushiwei/e
Browse files Browse the repository at this point in the history
testdata
  • Loading branch information
xushiwei committed Jul 5, 2020
2 parents dfac4e3 + ee78b98 commit 8fe7537
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@ func TestFromTestdata(t *testing.T) {
}
}

func TestFromTestdata2(t *testing.T) {
dir, err := os.Getwd()
if err != nil {
t.Fatal("Getwd failed:", err)
}
dir = path.Join(dir, "./testdata")
testFrom(t, dir, "")
}

// -----------------------------------------------------------------------------
78 changes: 78 additions & 0 deletions parser/testdata/mytest.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package testdata

import (
"os"
"go/token"
)

var stmtStart = map[token.Token]bool{
token.BREAK: true,
token.CONST: true,
token.CONTINUE: true,
token.DEFER: true,
token.FALLTHROUGH: true,
token.FOR: true,
token.GO: true,
token.GOTO: true,
token.IF: true,
token.RETURN: true,
token.SELECT: true,
token.SWITCH: true,
token.TYPE: true,
token.VAR: true,
}

type Mode uint

const (
// PackageClauseOnly - stop parsing after package clause
PackageClauseOnly Mode = 1 << iota
// ImportsOnly - stop parsing after import declarations
ImportsOnly
// ParseComments - parse comments and add them to AST
ParseComments
// Trace - print a trace of parsed productions
Trace
// DeclarationErrors - report declaration errors
DeclarationErrors
// AllErrors - report all errors (not just the first 10 on different lines)
AllErrors
)

// FileSystem represents a file system.
type FileSystem interface {
ReadDir(dirname string) ([]os.FileInfo, error)
ReadFile(filename string) ([]byte, error)
Join(elem ...string) string
}

type IF = FileSystem

type Foo struct {
a, b map[string]struct{}
}

func (p *Foo) bar() {
}

func init() {
f, err := os.Open("a")
if err != nil {
return
}
defer f.Close()

ch := make(chan bool, 100)
select {
case <-ch:
println("1")
case ch <- true:
println("2")
}

go func(fs FileSystem) {
if foo, ok := fs.(*Foo); ok {
println(foo)
}
}(nil)
}

0 comments on commit 8fe7537

Please sign in to comment.