Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
1.2 kB · 54 lines
Go
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455package codesearch
import ( "testing"
"github.com/sourcegraph/zoekt/query")
func TestIsRepoOnly(t *testing.T) { cases := []struct { query string want bool }{ {"repo:foo", true}, {"repo:foo repo:bar", true}, {"repo:foo bar", false}, {"repo:foo file:x", false}, {"file:x", false}, {"type:repo foo", true}, {"foo", false}, {"branch:main", false}, }
for _, tc := range cases { t.Run(tc.query, func(t *testing.T) { q, err := query.Parse(tc.query) if err != nil { t.Fatalf("parse %q: %v", tc.query, err) } if got := isRepoOnly(q); got != tc.want { t.Errorf("isRepoOnly(%q) = %v, want %v", tc.query, got, tc.want) } }) }}
func TestExtractDID(t *testing.T) { cases := []struct { tmpl string want string }{ {"https://tangled.org/did:plc:abc123/blob/{{.Version}}/{{.Path}}", "did:plc:abc123"}, {"http://localhost:3000/did:web:example.com/blob/{{.Version}}/{{.Path}}", "did:web:example.com"}, {"", ""}, }
for _, tc := range cases { t.Run(tc.tmpl, func(t *testing.T) { if got := extractDID(tc.tmpl); string(got) != tc.want { t.Errorf("extractDID(%q) = %q, want %q", tc.tmpl, got, tc.want) } }) }}