11package serverHandler
22
3- import "testing"
3+ import (
4+ "os"
5+ "testing"
6+ )
47
58func TestGetMatchInfo (t * testing.T ) {
69 var matchName , matchPrefix bool
710 var childList []string
11+ var info os.FileInfo
812
913 var expect = func (isMatchName , isMatchPrefix bool , isChildList ... string ) bool {
1014 if isMatchName != matchName {
@@ -18,6 +22,10 @@ func TestGetMatchInfo(t *testing.T) {
1822 return false
1923 }
2024
25+ if len (isChildList ) != len (childList ) {
26+ return false
27+ }
28+
2129 if isChildList != nil && childList != nil {
2230 for i := 0 ; i < len (isChildList ); i ++ {
2331 if isChildList [i ] != childList [i ] {
@@ -29,48 +37,63 @@ func TestGetMatchInfo(t *testing.T) {
2937 return true
3038 }
3139
32- matchName , matchPrefix , childList = matchSelection ("" , nil )
40+ info = createPlaceholderFileInfo ("" , true )
41+ matchName , matchPrefix , childList = matchSelection (info , nil )
3342 if ! expect (true , false ) {
3443 t .Error (matchName , matchPrefix , childList )
3544 }
3645
37- matchName , matchPrefix , childList = matchSelection ("" , []string {})
46+ info = createPlaceholderFileInfo ("" , true )
47+ matchName , matchPrefix , childList = matchSelection (info , []string {})
3848 if ! expect (true , false ) {
3949 t .Error (matchName , matchPrefix , childList )
4050 }
4151
42- matchName , matchPrefix , childList = matchSelection ("" , []string {"dir-x" })
52+ info = createPlaceholderFileInfo ("" , true )
53+ matchName , matchPrefix , childList = matchSelection (info , []string {"dir-x" })
4354 if ! expect (false , false ) {
4455 t .Error (matchName , matchPrefix , childList )
4556 }
4657
47- matchName , matchPrefix , childList = matchSelection ("dir-a" , nil )
58+ info = createPlaceholderFileInfo ("dir-a" , true )
59+ matchName , matchPrefix , childList = matchSelection (info , nil )
4860 if ! expect (true , false ) {
4961 t .Error (matchName , matchPrefix , childList )
5062 }
5163
52- matchName , matchPrefix , childList = matchSelection ("dir-a" , []string {"dir-x" })
64+ info = createPlaceholderFileInfo ("dir-a" , true )
65+ matchName , matchPrefix , childList = matchSelection (info , []string {"dir-x" })
5366 if ! expect (false , false ) {
5467 t .Error (matchName , matchPrefix , childList )
5568 }
5669
57- matchName , matchPrefix , childList = matchSelection ("dir-a" , []string {"dir-a" })
70+ info = createPlaceholderFileInfo ("dir-a" , true )
71+ matchName , matchPrefix , childList = matchSelection (info , []string {"dir-a" })
5872 if ! expect (true , false ) {
5973 t .Error (matchName , matchPrefix , childList )
6074 }
6175
62- matchName , matchPrefix , childList = matchSelection ("dir-a" , []string {"dir-a/dir-a1" })
76+ info = createPlaceholderFileInfo ("dir-a" , true )
77+ matchName , matchPrefix , childList = matchSelection (info , []string {"dir-a/dir-a1" })
6378 if ! expect (false , true , "dir-a1" ) {
6479 t .Error (matchName , matchPrefix , childList )
6580 }
6681
67- matchName , matchPrefix , childList = matchSelection ("dir-a" , []string {"dir-a/dir-a1" , "dir-a/dir-a2" , "dir-a/dir-a1/dir-a11" , "dir-b" })
82+ info = createPlaceholderFileInfo ("dir-a" , true )
83+ matchName , matchPrefix , childList = matchSelection (info , []string {"dir-a/dir-a1" , "dir-a/dir-a2" , "dir-a/dir-a1/dir-a11" , "dir-b" })
6884 if ! expect (false , true , "dir-a1" , "dir-a2" , "dir-a1/dir-a11" ) {
6985 t .Error (matchName , matchPrefix , childList )
7086 }
7187
72- matchName , matchPrefix , childList = matchSelection ("dir-a" , []string {"dir-a" , "dir-a/dir-a1" })
73- if ! expect (true , true , "dir-a1" ) {
88+ info = createPlaceholderFileInfoNoCase ("dir-a" , true )
89+ matchName , matchPrefix , childList = matchSelection (info , []string {"Dir-a/dir-a1" })
90+ if ! expect (false , true , "dir-a1" ) {
91+ t .Error (matchName , matchPrefix , childList )
92+ }
93+
94+ info = createPlaceholderFileInfoNoCase ("dir-a" , true )
95+ matchName , matchPrefix , childList = matchSelection (info , []string {"Dir-a/dir-a1" , "dir-a/dir-a2" , "dir-a/dir-a1/dir-a11" , "dir-b" })
96+ if ! expect (false , true , "dir-a1" , "dir-a2" , "dir-a1/dir-a11" ) {
7497 t .Error (matchName , matchPrefix , childList )
7598 }
7699}
0 commit comments