Debian Codegraph @

parity_test.go

raw
1 package strcase
2
3 import (
4 "go/ast"
5 "go/parser"
6 "go/token"
7 "reflect"
8 "sort"
9 "testing"
10 )
11
12 func parseFuncs(t *testing.T, filename string) []string {
13 fset := token.NewFileSet()
14 af, err := parser.ParseFile(fset, filename, nil, parser.AllErrors)
15 if err != nil {
16 t.Fatal(err)
17 }
18 var names []string
19 for _, d := range af.Decls {
20 if fd, _ := d.(*ast.FuncDecl); fd != nil {
21 if fd.Name == nil {
22 continue
23 }
24 name := fd.Name.Name
25 if ast.IsExported(name) {
26 names = append(names, name)
27 }
28 }
29 }
30 sort.Strings(names)
31 return names
32 }
33
34 // Test that the strcase and bytcase packages have the same API
35 func TestPackageParity(t *testing.T) {
36 strnames := parseFuncs(t, "strcase.go")
37 bytenames := parseFuncs(t, "bytcase/bytcase.go")
38 if !reflect.DeepEqual(strnames, bytenames) {
39 t.Fatalf("The API of the strcase and bytcase packages differs:\n"+
40 "strcase: %q\n"+
41 "bytcase: %q\n", strnames, bytenames)
42 }
43 }