Home | History | Annotate | Download | only in objabi
      1 // Copyright 2017 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package objabi
      6 
      7 import "testing"
      8 
      9 func TestPathToPrefix(t *testing.T) {
     10 	tests := []struct {
     11 		Path     string
     12 		Expected string
     13 	}{{"foo/bar/v1", "foo/bar/v1"},
     14 		{"foo/bar/v.1", "foo/bar/v%2e1"},
     15 		{"f.o.o/b.a.r/v1", "f.o.o/b.a.r/v1"},
     16 		{"f.o.o/b.a.r/v.1", "f.o.o/b.a.r/v%2e1"},
     17 		{"f.o.o/b.a.r/v..1", "f.o.o/b.a.r/v%2e%2e1"},
     18 		{"f.o.o/b.a.r/v..1.", "f.o.o/b.a.r/v%2e%2e1%2e"},
     19 		{"f.o.o/b.a.r/v%1", "f.o.o/b.a.r/v%251"},
     20 		{"runtime", "runtime"},
     21 		{"sync/atomic", "sync/atomic"},
     22 		{"golang.org/x/tools/godoc", "golang.org/x/tools/godoc"},
     23 		{"foo.bar/baz.quux", "foo.bar/baz%2equux"},
     24 		{"", ""},
     25 		{"%foo%bar", "%25foo%25bar"},
     26 		{"\x01\x00\x7F", "%01%00%7f%e2%98%ba"},
     27 	}
     28 	for _, tc := range tests {
     29 		if got := PathToPrefix(tc.Path); got != tc.Expected {
     30 			t.Errorf("expected PathToPrefix(%s) = %s, got %s", tc.Path, tc.Expected, got)
     31 		}
     32 	}
     33 }
     34