@@ -20,38 +20,6 @@ import (
2020 qt "github.com/frankban/quicktest"
2121)
2222
23- func TestGetRelativePath (t * testing.T ) {
24- tests := []struct {
25- path string
26- base string
27- expect any
28- }{
29- {filepath .FromSlash ("/a/b" ), filepath .FromSlash ("/a" ), filepath .FromSlash ("b" )},
30- {filepath .FromSlash ("/a/b/c/" ), filepath .FromSlash ("/a" ), filepath .FromSlash ("b/c/" )},
31- {filepath .FromSlash ("/c" ), filepath .FromSlash ("/a/b" ), filepath .FromSlash ("../../c" )},
32- {filepath .FromSlash ("/c" ), "" , false },
33- }
34- for i , this := range tests {
35- // ultimately a fancy wrapper around filepath.Rel
36- result , err := GetRelativePath (this .path , this .base )
37-
38- if b , ok := this .expect .(bool ); ok && ! b {
39- if err == nil {
40- t .Errorf ("[%d] GetRelativePath didn't return an expected error" , i )
41- }
42- } else {
43- if err != nil {
44- t .Errorf ("[%d] GetRelativePath failed: %s" , i , err )
45- continue
46- }
47- if result != this .expect {
48- t .Errorf ("[%d] GetRelativePath got %v but expected %v" , i , result , this .expect )
49- }
50- }
51-
52- }
53- }
54-
5523func TestMakePathRelative (t * testing.T ) {
5624 type test struct {
5725 inPath , path1 , path2 , output string
@@ -75,54 +43,6 @@ func TestMakePathRelative(t *testing.T) {
7543 }
7644}
7745
78- func TestMakeTitle (t * testing.T ) {
79- type test struct {
80- input , expected string
81- }
82- data := []test {
83- {"Make-Title" , "Make Title" },
84- {"MakeTitle" , "MakeTitle" },
85- {"make_title" , "make_title" },
86- }
87- for i , d := range data {
88- output := MakeTitle (d .input )
89- if d .expected != output {
90- t .Errorf ("Test %d failed. Expected %q got %q" , i , d .expected , output )
91- }
92- }
93- }
94-
95- // Replace Extension is probably poorly named, but the intent of the
96- // function is to accept a path and return only the file name with a
97- // new extension. It's intentionally designed to strip out the path
98- // and only provide the name. We should probably rename the function to
99- // be more explicit at some point.
100- func TestReplaceExtension (t * testing.T ) {
101- type test struct {
102- input , newext , expected string
103- }
104- data := []test {
105- // These work according to the above definition
106- {"/some/random/path/file.xml" , "html" , "file.html" },
107- {"/banana.html" , "xml" , "banana.xml" },
108- {"./banana.html" , "xml" , "banana.xml" },
109- {"banana/pie/index.html" , "xml" , "index.xml" },
110- {"../pies/fish/index.html" , "xml" , "index.xml" },
111- // but these all fail
112- {"filename-without-an-ext" , "ext" , "filename-without-an-ext.ext" },
113- {"/filename-without-an-ext" , "ext" , "filename-without-an-ext.ext" },
114- {"/directory/mydir/" , "ext" , ".ext" },
115- {"mydir/" , "ext" , ".ext" },
116- }
117-
118- for i , d := range data {
119- output := ReplaceExtension (filepath .FromSlash (d .input ), d .newext )
120- if d .expected != output {
121- t .Errorf ("Test %d failed. Expected %q got %q" , i , d .expected , output )
122- }
123- }
124- }
125-
12646func TestExtNoDelimiter (t * testing.T ) {
12747 c := qt .New (t )
12848 c .Assert (ExtNoDelimiter (filepath .FromSlash ("/my/data.json" )), qt .Equals , "json" )
@@ -263,26 +183,6 @@ func TestFieldsSlash(t *testing.T) {
263183 c .Assert (FieldsSlash ("" ), qt .DeepEquals , []string {})
264184}
265185
266- func TestCommonDirPath (t * testing.T ) {
267- c := qt .New (t )
268-
269- for _ , this := range []struct {
270- a , b , expected string
271- }{
272- {"/a/b/c" , "/a/b/d" , "/a/b" },
273- {"/a/b/c" , "a/b/d" , "/a/b" },
274- {"a/b/c" , "/a/b/d" , "/a/b" },
275- {"a/b/c" , "a/b/d" , "a/b" },
276- {"/a/b/c" , "/a/b/c" , "/a/b/c" },
277- {"/a/b/c" , "/a/b/c/d" , "/a/b/c" },
278- {"/a/b/c" , "/a/b" , "/a/b" },
279- {"/a/b/c" , "/a" , "/a" },
280- {"/a/b/c" , "/d/e/f" , "" },
281- } {
282- c .Assert (CommonDirPath (this .a , this .b ), qt .Equals , this .expected , qt .Commentf ("a: %s b: %s" , this .a , this .b ))
283- }
284- }
285-
286186func TestIsSameFilePath (t * testing.T ) {
287187 c := qt .New (t )
288188
0 commit comments