Skip to content

Commit

Permalink
support pkgsite delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusirous committed Dec 28, 2023
1 parent 58a8ccd commit a89dd4b
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 73 deletions.
9 changes: 8 additions & 1 deletion stdsym/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"flag"
"log"
"os"
"regexp"
Expand All @@ -19,6 +20,12 @@ func main() {
}

func run() error {
web := flag.Bool("-web", false, "support web href")
flag.Parse()
deli := "."
if *web {
deli = "#"
}
stdPattern := "std"
pkgs, err := gostdsym.LoadPackages(stdPattern)
if err != nil {
Expand All @@ -30,7 +37,7 @@ func run() error {
if isSkipPackage(pattern) {
continue
}
out, err := gostdsym.GetPackageSymbols(pattern)
out, err := gostdsym.GetPackageSymbols(pattern, deli)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func LoadPackages(pattern string) ([]string, error) {
}

// GetPackageSymbols extracts all exported symbols from a package.
func GetPackageSymbols(pattern string) ([]string, error) {
func GetPackageSymbols(pattern string, deli string) ([]string, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
Expand All @@ -44,7 +44,7 @@ func GetPackageSymbols(pattern string) ([]string, error) {

syms = slices.Compact(syms)
for i := range syms {
syms[i] = buildPkg.ImportPath + "." + syms[i]
syms[i] = buildPkg.ImportPath + deli + syms[i]
}
syms = append(syms, buildPkg.ImportPath)
return syms, nil
Expand Down
170 changes: 100 additions & 70 deletions symbol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,77 @@ func TestAll(t *testing.T) {

for _, test := range []struct {
in string
deli string
want []string
}{
{in: "cmp", want: []string{"cmp", "cmp.Less", "cmp.Ordered", "cmp.Compare"}},
{in: "html/template", want: []string{
"html/template",
"html/template.CSS",
"html/template.ErrAmbigContext",
"html/template.ErrBadHTML",
"html/template.ErrBranchEnd",
"html/template.ErrEndContext",
"html/template.ErrJSTemplate",
"html/template.ErrNoSuchTemplate",
"html/template.ErrOutputContext",
"html/template.ErrPartialCharset",
"html/template.ErrPartialEscape",
"html/template.ErrPredefinedEscaper",
"html/template.ErrRangeLoopReentry",
"html/template.ErrSlashAmbig",
"html/template.Error",
"html/template.Error.Error",
"html/template.ErrorCode",
"html/template.FuncMap",
"html/template.HTML",
"html/template.HTMLAttr",
"html/template.HTMLEscape",
"html/template.HTMLEscapeString",
"html/template.HTMLEscaper",
"html/template.IsTrue",
"html/template.JS",
"html/template.JSEscape",
"html/template.JSEscapeString",
"html/template.JSEscaper",
"html/template.JSStr",
"html/template.Must",
"html/template.New",
"html/template.OK",
"html/template.ParseFS",
"html/template.ParseFiles",
"html/template.ParseGlob",
"html/template.Srcset",
"html/template.Template",
"html/template.Template.AddParseTree",
"html/template.Template.Clone",
"html/template.Template.DefinedTemplates",
"html/template.Template.Delims",
"html/template.Template.Execute",
"html/template.Template.ExecuteTemplate",
"html/template.Template.Funcs",
"html/template.Template.Lookup",
"html/template.Template.Name",
"html/template.Template.New",
"html/template.Template.Option",
"html/template.Template.Parse",
"html/template.Template.ParseFS",
"html/template.Template.ParseFiles",
"html/template.Template.ParseGlob",
"html/template.Template.Templates",
"html/template.URL",
"html/template.URLQueryEscaper",
"html/template.eatAttrName",
"html/template.errorf",
"html/template.parseFS",
"html/template.parseFiles",
"html/template.parseGlob",
}},
{in: "cmp", deli: ".", want: []string{"cmp", "cmp.Less", "cmp.Ordered", "cmp.Compare"}},
{in: "html/template",
deli: ".",
want: []string{
"html/template",
"html/template.CSS",
"html/template.ErrAmbigContext",
"html/template.ErrBadHTML",
"html/template.ErrBranchEnd",
"html/template.ErrEndContext",
"html/template.ErrJSTemplate",
"html/template.ErrNoSuchTemplate",
"html/template.ErrOutputContext",
"html/template.ErrPartialCharset",
"html/template.ErrPartialEscape",
"html/template.ErrPredefinedEscaper",
"html/template.ErrRangeLoopReentry",
"html/template.ErrSlashAmbig",
"html/template.Error",
"html/template.Error.Error",
"html/template.ErrorCode",
"html/template.FuncMap",
"html/template.HTML",
"html/template.HTMLAttr",
"html/template.HTMLEscape",
"html/template.HTMLEscapeString",
"html/template.HTMLEscaper",
"html/template.IsTrue",
"html/template.JS",
"html/template.JSEscape",
"html/template.JSEscapeString",
"html/template.JSEscaper",
"html/template.JSStr",
"html/template.Must",
"html/template.New",
"html/template.OK",
"html/template.ParseFS",
"html/template.ParseFiles",
"html/template.ParseGlob",
"html/template.Srcset",
"html/template.Template",
"html/template.Template.AddParseTree",
"html/template.Template.Clone",
"html/template.Template.DefinedTemplates",
"html/template.Template.Delims",
"html/template.Template.Execute",
"html/template.Template.ExecuteTemplate",
"html/template.Template.Funcs",
"html/template.Template.Lookup",
"html/template.Template.Name",
"html/template.Template.New",
"html/template.Template.Option",
"html/template.Template.Parse",
"html/template.Template.ParseFS",
"html/template.Template.ParseFiles",
"html/template.Template.ParseGlob",
"html/template.Template.Templates",
"html/template.URL",
"html/template.URLQueryEscaper",
"html/template.eatAttrName",
"html/template.errorf",
"html/template.parseFS",
"html/template.parseFiles",
"html/template.parseGlob",
}},
{
in: "container/list",

in: "container/list",
deli: ".",
want: []string{
"container/list",
"container/list.Element",
Expand All @@ -106,10 +109,36 @@ func TestAll(t *testing.T) {
"container/list.List.Remove",
},
},

{
in: "context",

in: "container/list",
deli: "#",
want: []string{
"container/list",
"container/list#Element",
"container/list#Element.Next",
"container/list#Element.Prev",
"container/list#List",
"container/list#New",
"container/list#List.Back",
"container/list#List.Front",
"container/list#List.Init",
"container/list#List.InsertAfter",
"container/list#List.InsertBefore",
"container/list#List.Len",
"container/list#List.MoveAfter",
"container/list#List.MoveBefore",
"container/list#List.MoveToBack",
"container/list#List.MoveToFront",
"container/list#List.PushBack",
"container/list#List.PushBackList",
"container/list#List.PushFront",
"container/list#List.PushFrontList",
"container/list#List.Remove",
},
},
{
in: "context",
deli: ".",
want: []string{
"context",
"context.AfterFunc",
Expand All @@ -132,7 +161,8 @@ func TestAll(t *testing.T) {
},
},
{
in: "errors",
in: "errors",
deli: ".",
want: []string{
"errors",
"errors.Is",
Expand All @@ -144,7 +174,7 @@ func TestAll(t *testing.T) {
},
},
} {
got, err := GetPackageSymbols(test.in)
got, err := GetPackageSymbols(test.in, test.deli)
if err != nil {
t.Fatalf("want no error for MustExtract, got: %v", err)
}
Expand Down

0 comments on commit a89dd4b

Please sign in to comment.