[BACK]Return to path_test.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

Annotation of pkgsrc/pkgtools/pkglint/files/path_test.go, Revision 1.4

1.1       rillig      1: package pkglint
                      2:
                      3: import (
                      4:        "gopkg.in/check.v1"
                      5:        "io"
                      6:        "os"
                      7:        "runtime"
                      8:        "strings"
                      9: )
                     10:
                     11: func (s *Suite) Test_NewPath(c *check.C) {
                     12:        t := s.Init(c)
                     13:
                     14:        t.CheckEquals(NewPath("filename"), NewPath("filename"))
                     15:        t.CheckEquals(NewPath("\\"), NewPath("\\"))
                     16:        c.Check(NewPath("\\"), check.Not(check.Equals), NewPath("/"))
                     17: }
                     18:
                     19: func (s *Suite) Test_Path_String(c *check.C) {
                     20:        t := s.Init(c)
                     21:
                     22:        for _, p := range []string{"", "filename", "a/b", "c\\d"} {
                     23:                t.CheckEquals(NewPath(p).String(), p)
                     24:        }
                     25: }
                     26:
                     27: func (s *Suite) Test_Path_GoString(c *check.C) {
                     28:        t := s.Init(c)
                     29:
                     30:        test := func(p Path, s string) {
                     31:                t.CheckEquals(p.GoString(), s)
                     32:        }
                     33:
                     34:        test("", "\"\"")
                     35:        test("filename", "\"filename\"")
                     36:        test("a/b", "\"a/b\"")
                     37:        test("c\\d", "\"c\\\\d\"")
                     38: }
                     39:
1.3       rillig     40: func (s *Suite) Test_Path_IsEmpty(c *check.C) {
                     41:        t := s.Init(c)
                     42:
                     43:        test := func(p Path, isEmpty bool) {
                     44:                t.CheckEquals(p.IsEmpty(), isEmpty)
                     45:        }
                     46:
                     47:        test("", true)
                     48:        test(".", false)
                     49:        test("/", false)
                     50: }
                     51:
1.4     ! rillig     52: func (s *Suite) Test_Path_DirClean(c *check.C) {
1.1       rillig     53:        t := s.Init(c)
                     54:
                     55:        test := func(p, dir Path) {
1.4     ! rillig     56:                t.CheckEquals(p.DirClean(), dir)
        !            57:        }
        !            58:
        !            59:        test("", ".")
        !            60:        test("././././", ".")
        !            61:        test("/root", "/")
        !            62:        test("filename", ".")
        !            63:        test("dir/filename", "dir")
        !            64:        test("dir/filename\\with\\backslash", "dir")
        !            65:
        !            66:        // TODO: I didn't expect that Dir would return the cleaned path.
        !            67:        test("././././dir/filename", "dir")
        !            68: }
        !            69:
        !            70: func (s *Suite) Test_Path_DirNoClean(c *check.C) {
        !            71:        t := s.Init(c)
        !            72:
        !            73:        test := func(p, dir Path) {
        !            74:                t.CheckEquals(p.DirNoClean(), dir)
1.1       rillig     75:        }
                     76:
                     77:        test("", ".")
                     78:        test("././././", ".")
                     79:        test("/root", "/")
                     80:        test("filename", ".")
                     81:        test("dir/filename", "dir")
                     82:        test("dir/filename\\with\\backslash", "dir")
                     83: }
                     84:
                     85: func (s *Suite) Test_Path_Base(c *check.C) {
                     86:        t := s.Init(c)
                     87:
                     88:        test := func(p Path, base string) {
                     89:                t.CheckEquals(p.Base(), base)
                     90:        }
                     91:
                     92:        test("", ".") // That's a bit surprising
                     93:        test("././././", ".")
                     94:        test("/root", "root")
                     95:        test("filename", "filename")
                     96:        test("dir/filename", "filename")
                     97:        test("dir/filename\\with\\backslash", "filename\\with\\backslash")
                     98: }
                     99:
                    100: func (s *Suite) Test_Path_Split(c *check.C) {
                    101:        t := s.Init(c)
                    102:
                    103:        test := func(p, dir, base string) {
                    104:                actualDir, actualBase := NewPath(p).Split()
                    105:
                    106:                t.CheckDeepEquals(
                    107:                        []string{actualDir.String(), actualBase},
                    108:                        []string{dir, base})
                    109:        }
                    110:
                    111:        test("", "", "")
                    112:        test("././././", "././././", "")
                    113:        test("/root", "/", "root")
                    114:        test("filename", "", "filename")
                    115:        test("dir/filename", "dir/", "filename")
                    116:        test("dir/filename\\with\\backslash", "dir/", "filename\\with\\backslash")
                    117: }
                    118:
                    119: func (s *Suite) Test_Path_Parts(c *check.C) {
                    120:        t := s.Init(c)
                    121:
                    122:        test := func(p string, parts ...string) {
                    123:                t.CheckDeepEquals(NewPath(p).Parts(), parts)
                    124:        }
                    125:
1.2       rillig    126:        // Only the empty path returns an empty slice.
                    127:        test("", nil...)
                    128:
                    129:        // The standard cases for relative paths.
                    130:        test("relative", "relative")
                    131:        test("relative/subdir", "relative", "subdir")
                    132:        test("relative////subdir", "relative", "subdir")
                    133:        test("relative/..", "relative", "..")
                    134:        test("relative/.", "relative")
                    135:
                    136:        // Leading dots are removed when they are followed by something.
                    137:        test("./relative", "relative")
                    138:
                    139:        // A path consisting of only dots produces a single dot.
                    140:        test("./././.", ".")
                    141:
                    142:        // Slashes at the end are treated like a single dot.
                    143:        test("././././", ".")
                    144:        test(".///////", ".")
                    145:
                    146:        // Absolute paths have an empty first component.
                    147:        test("/", "")
                    148:        test("/.", "")
                    149:        test("/root", "", "root")
                    150:
                    151:        // The backslash is not a path separator.
1.1       rillig    152:        test("dir/filename\\with\\backslash", "dir", "filename\\with\\backslash")
                    153: }
                    154:
                    155: func (s *Suite) Test_Path_Count(c *check.C) {
                    156:        t := s.Init(c)
                    157:
                    158:        test := func(p string, count int) {
                    159:                t.CheckEquals(NewPath(p).Count(), count)
                    160:        }
                    161:
1.2       rillig    162:        test("././././", 1)
                    163:        test("/root", 2)
1.1       rillig    164:        test("filename", 1)
                    165:        test("dir/filename", 2)
                    166:        test("dir/filename\\with\\backslash", 2)
1.2       rillig    167:
                    168:        // Only the empty path returns an empty slice.
                    169:        test("", 0)
                    170:
                    171:        // The standard cases for canonical relative paths.
                    172:        test("relative", 1)
                    173:        test("relative/subdir", 2)
                    174:        test("relative////subdir", 2)
                    175:        test("relative/..", 2)
                    176:        test("relative/.", 1)
                    177:
                    178:        // A path consisting of only dots produces a single dot.
                    179:        test("./././.", 1)
                    180:
                    181:        // Slashes at the end are treated like a single dot.
                    182:        test("././././", 1)
                    183:        test(".///////", 1)
                    184:
                    185:        // Absolute paths have an empty first component.
                    186:        test("/", 1)
                    187:        test("/.", 1)
                    188:        test("/root", 2)
                    189:
                    190:        // The backslash is not a path separator.
                    191:        test("dir/filename\\with\\backslash", 2)
1.1       rillig    192: }
                    193:
                    194: func (s *Suite) Test_Path_HasPrefixText(c *check.C) {
                    195:        t := s.Init(c)
                    196:
                    197:        test := func(p, prefix string, hasPrefix bool) {
                    198:                t.CheckEquals(NewPath(p).HasPrefixText(prefix), hasPrefix)
                    199:        }
                    200:
                    201:        test("", "", true)
                    202:        test("filename", "", true)
                    203:        test("", "x", false)
                    204:        test("/root", "/r", true)
                    205:        test("/root", "/root", true)
                    206:        test("/root", "/root/", false)
                    207:        test("/root", "root/", false)
                    208: }
                    209:
                    210: func (s *Suite) Test_Path_HasPrefixPath(c *check.C) {
                    211:        t := s.Init(c)
                    212:
                    213:        test := func(p, prefix Path, hasPrefix bool) {
                    214:                t.CheckEquals(p.HasPrefixPath(prefix), hasPrefix)
                    215:        }
                    216:
                    217:        test("", "", true)
                    218:        test("filename", "", false)
                    219:        test("", "x", false)
                    220:        test("/root", "/r", false)
                    221:        test("/root", "/root", true)
1.2       rillig    222:
                    223:        // Even though the textual representation of the prefix is longer than
                    224:        // the path. The trailing slash marks the path as a directory, and
                    225:        // there are only a few cases where the difference matters, such as
                    226:        // in rsync and mkdir.
                    227:        test("/root", "/root/", true)
                    228:
1.1       rillig    229:        test("/root/", "/root", true)
1.2       rillig    230:        test("/root/", "root", false)
1.1       rillig    231:        test("/root/subdir", "/root", true)
1.2       rillig    232:        test("filename", ".", true)
                    233:        test("filename", "./filename", true)
                    234:        test("filename", "./file", false)
                    235:        test("filename", "./filename/sub", false)
                    236:        test("/anything", ".", false)
1.1       rillig    237: }
                    238:
                    239: func (s *Suite) Test_Path_ContainsText(c *check.C) {
                    240:        t := s.Init(c)
                    241:
                    242:        test := func(p Path, text string, contains bool) {
                    243:                t.CheckEquals(p.ContainsText(text), contains)
                    244:        }
                    245:
                    246:        test("", "", true)
                    247:        test("filename", "", true)
                    248:        test("filename", ".", false)
                    249:        test("a.b", ".", true)
                    250:        test("..", ".", true)
                    251:        test("", "x", false)
                    252:        test("/root", "/r", true)
                    253:        test("/root", "/root", true)
                    254:        test("/root", "/root/", false)
                    255:        test("/root", "root/", false)
                    256:        test("/root", "ro", true)
                    257:        test("/root", "ot", true)
                    258: }
                    259:
                    260: func (s *Suite) Test_Path_ContainsPath(c *check.C) {
                    261:        t := s.Init(c)
                    262:
                    263:        test := func(p, sub Path, contains bool) {
                    264:                t.CheckEquals(p.ContainsPath(sub), contains)
                    265:        }
                    266:
                    267:        test("", "", true)          // It doesn't make sense to search for empty paths.
                    268:        test(".", "", false)        // It doesn't make sense to search for empty paths.
1.3       rillig    269:        test("filename", ".", true) // Every relative path contains "." implicitly at the beginning
1.1       rillig    270:        test("a.b", ".", true)
                    271:        test("..", ".", true)
                    272:        test("filename", "", false)
                    273:        test("filename", "filename", true)
                    274:        test("a/b/c", "a", true)
                    275:        test("a/b/c", "b", true)
                    276:        test("a/b/c", "c", true)
                    277:        test("a/b/c", "a/b", true)
                    278:        test("a/b/c", "b/c", true)
                    279:        test("a/b/c", "a/b/c", true)
                    280:        test("aa/b/c", "a", false)
                    281:        test("a/bb/c", "b", false)
                    282:        test("a/bb/c", "b/c", false)
                    283:        test("mk/fetch/fetch.mk", "mk", true)
                    284:        test("category/package/../../wip/mk/../..", "mk", true)
1.3       rillig    285:
                    286:        test("a", "a", true)
                    287:        test("a", "b", false)
                    288:        test("a", "A", false)
                    289:        test("a/b/c", "a", true)
                    290:        test("a/b/c", "b", true)
                    291:        test("a/b/c", "c", true)
                    292:        test("a/b/c", "a/b", true)
                    293:        test("a/b/c", "b/c", true)
                    294:        test("a/b/c", "a/b/c", true)
                    295:        test("aa/bb/cc", "a/b", false)
                    296:        test("aa/bb/cc", "a/bb", false)
                    297:        test("aa/bb/cc", "aa/b", false)
                    298:        test("aa/bb/cc", "aa/bb", true)
                    299:        test("aa/bb/cc", "a", false)
                    300:        test("aa/bb/cc", "b", false)
                    301:        test("aa/bb/cc", "c", false)
1.1       rillig    302: }
                    303:
                    304: func (s *Suite) Test_Path_HasSuffixText(c *check.C) {
                    305:        t := s.Init(c)
                    306:
                    307:        test := func(p Path, suffix string, has bool) {
                    308:                t.CheckEquals(p.HasSuffixText(suffix), has)
                    309:        }
                    310:
                    311:        test("", "", true)
                    312:        test("a/bb/c", "", true)
                    313:        test("a/bb/c", "c", true)
                    314:        test("a/bb/c", "/c", true)
                    315:        test("a/bb/c", "b/c", true)
                    316:        test("aa/b/c", "bb", false)
                    317: }
                    318:
                    319: func (s *Suite) Test_Path_HasSuffixPath(c *check.C) {
                    320:        t := s.Init(c)
                    321:
                    322:        test := func(p, suffix Path, has bool) {
                    323:                t.CheckEquals(p.HasSuffixPath(suffix), has)
                    324:        }
                    325:
                    326:        test("", "", true)
                    327:        test("a/bb/c", "", false)
                    328:        test("a/bb/c", "c", true)
                    329:        test("a/bb/c", "/c", false)
                    330:        test("a/bb/c", "b/c", false)
                    331:        test("aa/b/c", "bb", false)
                    332: }
                    333:
                    334: func (s *Suite) Test_Path_HasBase(c *check.C) {
                    335:        t := s.Init(c)
                    336:
                    337:        test := func(p Path, suffix string, hasBase bool) {
                    338:                t.CheckEquals(p.HasBase(suffix), hasBase)
                    339:        }
                    340:
                    341:        test("dir/file", "e", false)
                    342:        test("dir/file", "file", true)
                    343:        test("dir/file", "file.ext", false)
                    344:        test("dir/file", "/file", false)
                    345:        test("dir/file", "dir/file", false)
                    346: }
                    347:
                    348: func (s *Suite) Test_Path_TrimSuffix(c *check.C) {
                    349:        t := s.Init(c)
                    350:
                    351:        test := func(p Path, suffix string, result Path) {
                    352:                t.CheckEquals(p.TrimSuffix(suffix), result)
                    353:        }
                    354:
                    355:        test("dir/file", "e", "dir/fil")
                    356:        test("dir/file", "file", "dir/")
                    357:        test("dir/file", "/file", "dir")
                    358:        test("dir/file", "dir/file", "")
                    359:        test("dir/file", "subdir/file", "dir/file")
                    360: }
                    361:
                    362: func (s *Suite) Test_Path_Replace(c *check.C) {
                    363:        t := s.Init(c)
                    364:
                    365:        test := func(p Path, from, to string, result Path) {
                    366:                t.CheckEquals(p.Replace(from, to), result)
                    367:        }
                    368:
                    369:        test("dir/file", "dir", "other", "other/file")
                    370:        test("dir/file", "r", "sk", "disk/file")
                    371:        test("aaa/file", "a", "sub/", "sub/sub/sub//file")
                    372: }
                    373:
                    374: func (s *Suite) Test_Path_JoinClean(c *check.C) {
                    375:        t := s.Init(c)
                    376:
                    377:        test := func(p Path, suffix Path, result Path) {
                    378:                t.CheckEquals(p.JoinClean(suffix), result)
                    379:        }
                    380:
                    381:        test("dir", "file", "dir/file")
                    382:        test("dir", "///file", "dir/file")
                    383:        test("dir/./../dir/", "///file", "dir/file")
                    384:        test("dir", "..", ".")
                    385: }
                    386:
                    387: func (s *Suite) Test_Path_JoinNoClean(c *check.C) {
                    388:        t := s.Init(c)
                    389:
                    390:        test := func(p, suffix Path, result Path) {
                    391:                t.CheckEquals(p.JoinNoClean(suffix), result)
                    392:        }
                    393:
                    394:        test("dir", "file", "dir/file")
                    395:        test("dir", "///file", "dir////file")
                    396:        test("dir/./../dir/", "///file", "dir/./../dir/////file")
                    397:        test("dir", "..", "dir/..")
                    398: }
                    399:
                    400: func (s *Suite) Test_Path_Clean(c *check.C) {
                    401:        t := s.Init(c)
                    402:
                    403:        test := func(p, result Path) {
                    404:                t.CheckEquals(p.Clean(), result)
                    405:        }
                    406:
                    407:        test("", ".")
                    408:        test(".", ".")
                    409:        test("./././", ".")
                    410:        test("a/bb///../c", "a/c")
                    411: }
                    412:
1.2       rillig    413: func (s *Suite) Test_Path_CleanDot(c *check.C) {
                    414:        t := s.Init(c)
                    415:
                    416:        test := func(p, result Path) {
                    417:                t.CheckEquals(p.CleanDot(), result)
                    418:        }
                    419:
                    420:        test("", "")
                    421:        test(".", ".")
                    422:        test("./././", ".")
                    423:        test("a/bb///../c", "a/bb/../c")
                    424:        test("./filename", "filename")
                    425:        test("/absolute", "/absolute")
                    426:        test("/usr/pkgsrc/wip/package", "/usr/pkgsrc/wip/package")
                    427:        test("/usr/pkgsrc/wip/package/../mk/git-package.mk", "/usr/pkgsrc/wip/package/../mk/git-package.mk")
1.4     ! rillig    428:        test("a//b", "a/b")
        !           429: }
        !           430:
        !           431: func (s *Suite) Test_Path_CleanPath(c *check.C) {
        !           432:        t := s.Init(c)
        !           433:
        !           434:        test := func(from, to Path) {
        !           435:                t.CheckEquals(from.CleanPath(), to)
        !           436:        }
        !           437:
        !           438:        test("simple/path", "simple/path")
        !           439:        test("/absolute/path", "/absolute/path")
        !           440:
        !           441:        // Single dot components are removed, unless it's the only component of the path.
        !           442:        test("./././.", ".")
        !           443:        test("./././", ".")
        !           444:        test("dir/multi/././/file", "dir/multi/file")
        !           445:        test("dir/", "dir")
        !           446:
        !           447:        test("dir/", "dir")
        !           448:
        !           449:        // Components like aa/bb/../.. are removed, but not in the initial part of the path,
        !           450:        // and only if they are not followed by another "..".
        !           451:        test("dir/../dir/../dir/../dir/subdir/../../Makefile", "dir/../dir/../dir/../Makefile")
        !           452:        test("111/222/../../333/444/../../555/666/../../777/888/9", "111/222/../../777/888/9")
        !           453:        test("1/2/3/../../4/5/6/../../7/8/9/../../../../10", "1/2/3/../../4/7/8/9/../../../../10")
        !           454:        test("cat/pkg.v1/../../cat/pkg.v2/Makefile", "cat/pkg.v1/../../cat/pkg.v2/Makefile")
        !           455:        test("aa/../../../../../a/b/c/d", "aa/../../../../../a/b/c/d")
        !           456:        test("aa/bb/../../../../a/b/c/d", "aa/bb/../../../../a/b/c/d")
        !           457:        test("aa/bb/cc/../../../a/b/c/d", "aa/bb/cc/../../../a/b/c/d")
        !           458:        test("aa/bb/cc/dd/../../a/b/c/d", "aa/bb/a/b/c/d")
        !           459:        test("aa/bb/cc/dd/ee/../a/b/c/d", "aa/bb/cc/dd/ee/../a/b/c/d")
        !           460:        test("../../../../../a/b/c/d", "../../../../../a/b/c/d")
        !           461:        test("aa/../../../../a/b/c/d", "aa/../../../../a/b/c/d")
        !           462:        test("aa/bb/../../../a/b/c/d", "aa/bb/../../../a/b/c/d")
        !           463:        test("aa/bb/cc/../../a/b/c/d", "aa/bb/cc/../../a/b/c/d")
        !           464:        test("aa/bb/cc/dd/../a/b/c/d", "aa/bb/cc/dd/../a/b/c/d")
        !           465:        test("aa/../cc/../../a/b/c/d", "aa/../cc/../../a/b/c/d")
        !           466:
        !           467:        // The initial 2 components of the path are typically category/package, when
        !           468:        // pkglint is called from the pkgsrc top-level directory.
        !           469:        // This path serves as the context and therefore is always kept.
        !           470:        test("aa/bb/../../cc/dd/../../ee/ff", "aa/bb/../../ee/ff")
        !           471:        test("aa/bb/../../cc/dd/../..", "aa/bb/../..")
        !           472:        test("aa/bb/cc/dd/../..", "aa/bb")
        !           473:        test("aa/bb/../../cc/dd/../../ee/ff/buildlink3.mk", "aa/bb/../../ee/ff/buildlink3.mk")
        !           474:        test("./aa/bb/../../cc/dd/../../ee/ff/buildlink3.mk", "aa/bb/../../ee/ff/buildlink3.mk")
        !           475:
        !           476:        test("../.", "..")
        !           477:        test("../././././././.", "..")
        !           478:        test(".././././././././", "..")
        !           479:
        !           480:        test(
        !           481:                "x11/kde-runtime4/../../misc/kdepimlibs4/../../databases/openldap-client/buildlink3.mk",
        !           482:                "x11/kde-runtime4/../../databases/openldap-client/buildlink3.mk")
1.2       rillig    483: }
                    484:
1.1       rillig    485: func (s *Suite) Test_Path_IsAbs(c *check.C) {
                    486:        t := s.Init(c)
                    487:
                    488:        test := func(p Path, abs bool) {
                    489:                t.CheckEquals(p.IsAbs(), abs)
                    490:        }
                    491:
                    492:        test("", false)
                    493:        test(".", false)
                    494:        test("a/b", false)
                    495:        test("/a", true)
                    496:        test("C:/", runtime.GOOS == "windows")
                    497:        test("c:/", runtime.GOOS == "windows")
                    498: }
                    499:
                    500: func (s *Suite) Test_Path_Rel(c *check.C) {
                    501:        t := s.Init(c)
                    502:
                    503:        base := NewPath(".")
                    504:        abc := NewPath("a/b/c")
                    505:        defFile := NewPath("d/e/f/file")
                    506:
                    507:        t.CheckEquals(abc.Rel(defFile), NewPath("../../../d/e/f/file"))
                    508:        t.CheckEquals(base.Rel(base), NewPath("."))
                    509:        t.CheckEquals(abc.Rel(base), NewPath("../../../."))
                    510: }
                    511:
1.4     ! rillig    512: func (s *Suite) Test_NewCurrPath(c *check.C) {
        !           513:        t := s.Init(c)
        !           514:
        !           515:        curr := NewCurrPath("dir/.///file")
        !           516:
        !           517:        t.CheckEquals(curr.String(), "dir/.///file")
        !           518: }
        !           519:
        !           520: func (s *Suite) Test_NewCurrPathString(c *check.C) {
        !           521:        t := s.Init(c)
        !           522:
        !           523:        curr := NewCurrPathString("dir/.///file")
        !           524:
        !           525:        t.CheckEquals(curr.String(), "dir/.///file")
        !           526: }
        !           527:
        !           528: func (s *Suite) Test_NewCurrPathSlash(c *check.C) {
        !           529:        t := s.Init(c)
        !           530:
        !           531:        test := func(path, curr string) {
        !           532:                t.CheckEquals(NewCurrPathSlash(path).String(), curr)
        !           533:        }
        !           534:        testWindows := func(path, currWindows, currOther string) {
        !           535:                t.CheckEquals(
        !           536:                        NewCurrPathSlash(path).String(),
        !           537:                        condStr(runtime.GOOS == "windows", currWindows, currOther))
        !           538:        }
        !           539:
        !           540:        test("filename", "filename")
        !           541:        test("dir/.///file", "dir/.///file")
        !           542:
        !           543:        testWindows("\\", "/", "\\")
        !           544: }
        !           545:
        !           546: func (s *Suite) Test_NewCurrPathSlash__windows(c *check.C) {
        !           547:        t := s.Init(c)
        !           548:
        !           549:        if runtime.GOOS != "windows" {
        !           550:                return
        !           551:        }
        !           552:
        !           553:        curr := NewCurrPathSlash("dir\\.\\\\\\file")
        !           554:
        !           555:        t.CheckEquals(curr.String(), "dir/.///file")
        !           556: }
        !           557:
        !           558: func (s *Suite) Test_CurrPath_GoString(c *check.C) {
        !           559:        t := s.Init(c)
        !           560:
        !           561:        // Tabs in filenames are rare, probably typos.
        !           562:        curr := NewCurrPath("dir/file\t")
        !           563:
        !           564:        t.CheckEquals(curr.GoString(), "\"dir/file\\t\"")
        !           565: }
        !           566:
        !           567: func (s *Suite) Test_CurrPath_String(c *check.C) {
        !           568:        t := s.Init(c)
        !           569:
        !           570:        // Tabs in filenames are rare, probably typos.
        !           571:        curr := NewCurrPath("dir/file\t")
        !           572:
        !           573:        t.CheckEquals(curr.String(), "dir/file\t")
        !           574: }
        !           575:
        !           576: func (s *Suite) Test_CurrPath_AsPath(c *check.C) {
        !           577:        t := s.Init(c)
        !           578:
        !           579:        // Tabs in filenames are rare, probably typos.
        !           580:        curr := NewCurrPath("dir/file\t")
        !           581:
        !           582:        t.CheckEquals(curr.AsPath(), NewPath("dir/file\t"))
        !           583: }
        !           584:
        !           585: func (s *Suite) Test_CurrPath_IsEmpty(c *check.C) {
        !           586:        t := s.Init(c)
        !           587:
        !           588:        test := func(curr CurrPath, isEmpty bool) {
        !           589:                t.CheckEquals(curr.IsEmpty(), isEmpty)
        !           590:        }
        !           591:
        !           592:        test("", true)
        !           593:        test(".", false)
        !           594:        test("/", false)
        !           595: }
        !           596:
        !           597: func (s *Suite) Test_CurrPath_DirClean(c *check.C) {
        !           598:        t := s.Init(c)
        !           599:
        !           600:        test := func(curr, dir CurrPath) {
        !           601:                t.CheckEquals(curr.DirClean(), dir)
        !           602:        }
        !           603:
        !           604:        test("./dir/../dir///./file", "dir")
        !           605: }
        !           606:
        !           607: func (s *Suite) Test_CurrPath_DirNoClean(c *check.C) {
        !           608:        t := s.Init(c)
        !           609:
        !           610:        test := func(curr, dir CurrPath) {
        !           611:                t.CheckEquals(curr.DirNoClean(), dir)
        !           612:        }
        !           613:
        !           614:        test("./dir/../dir///./file", "./dir/../dir")
        !           615: }
        !           616:
        !           617: func (s *Suite) Test_CurrPath_Base(c *check.C) {
        !           618:        t := s.Init(c)
        !           619:
        !           620:        test := func(curr CurrPath, base string) {
        !           621:                t.CheckEquals(curr.Base(), base)
        !           622:        }
        !           623:
        !           624:        test("dir/file", "file")
        !           625: }
        !           626:
        !           627: func (s *Suite) Test_CurrPath_Split(c *check.C) {
        !           628:        t := s.Init(c)
        !           629:
        !           630:        test := func(curr, dir CurrPath, base string) {
        !           631:                actualDir, actualBase := curr.Split()
        !           632:                t.CheckEquals(actualDir, dir)
        !           633:                t.CheckEquals(actualBase, base)
        !           634:        }
        !           635:
        !           636:        test("dir/file", "dir/", "file")
        !           637: }
        !           638:
        !           639: func (s *Suite) Test_CurrPath_Parts(c *check.C) {
        !           640:        t := s.Init(c)
        !           641:
        !           642:        test := func(curr CurrPath, parts ...string) {
        !           643:                t.CheckDeepEquals(curr.Parts(), parts)
        !           644:        }
        !           645:
        !           646:        test("dir/file", "dir", "file")
        !           647: }
        !           648:
        !           649: func (s *Suite) Test_CurrPath_IsAbs(c *check.C) {
        !           650:        t := s.Init(c)
        !           651:
        !           652:        test := func(curr CurrPath, isAbs bool) {
        !           653:                t.CheckDeepEquals(curr.IsAbs(), isAbs)
        !           654:        }
        !           655:
        !           656:        test("/", true)
        !           657:        test("./", false)
        !           658:        test("C:/", runtime.GOOS == "windows")
        !           659: }
        !           660:
        !           661: func (s *Suite) Test_CurrPath_HasPrefixPath(c *check.C) {
        !           662:        t := s.Init(c)
        !           663:
        !           664:        test := func(curr, prefix CurrPath, hasPrefix bool) {
        !           665:                t.CheckEquals(curr.HasPrefixPath(prefix), hasPrefix)
        !           666:        }
        !           667:
        !           668:        test("dir/file", "dir", true)
        !           669:        test("dir/file", "file", false)
        !           670:        test("dir", ".", true)
        !           671: }
        !           672:
        !           673: func (s *Suite) Test_CurrPath_ContainsPath(c *check.C) {
        !           674:        t := s.Init(c)
        !           675:
        !           676:        test := func(curr CurrPath, sub Path, hasPrefix bool) {
        !           677:                t.CheckEquals(curr.ContainsPath(sub), hasPrefix)
        !           678:        }
        !           679:
        !           680:        test("dir/file", "dir", true)
        !           681:        test("dir/file", "file", true)
        !           682:        test("dir/file", "fi", false)
        !           683:        test("dir", ".", true)
        !           684: }
        !           685:
        !           686: func (s *Suite) Test_CurrPath_ContainsText(c *check.C) {
        !           687:        t := s.Init(c)
        !           688:
        !           689:        test := func(curr CurrPath, sub string, hasPrefix bool) {
        !           690:                t.CheckEquals(curr.ContainsText(sub), hasPrefix)
        !           691:        }
        !           692:
        !           693:        test("dir/file", "dir", true)
        !           694:        test("dir/file", "r/f", true)
        !           695: }
        !           696:
        !           697: func (s *Suite) Test_CurrPath_HasSuffixPath(c *check.C) {
        !           698:        t := s.Init(c)
        !           699:
        !           700:        test := func(curr CurrPath, suffix Path, hasPrefix bool) {
        !           701:                t.CheckEquals(curr.HasSuffixPath(suffix), hasPrefix)
        !           702:        }
        !           703:
        !           704:        test("dir/file", "dir", false)
        !           705:        test("dir/file", "file", true)
        !           706:        test("dir/file", "le", false)
        !           707:
        !           708:        // In contrast to HasPrefixPath, it doesn't really make sense to
        !           709:        // ask whether a path ends with the current directory.
        !           710:        test("dir", ".", false)
        !           711: }
        !           712:
        !           713: func (s *Suite) Test_CurrPath_HasSuffixText(c *check.C) {
        !           714:        t := s.Init(c)
        !           715:
        !           716:        test := func(curr CurrPath, suffix string, hasPrefix bool) {
        !           717:                t.CheckEquals(curr.HasSuffixText(suffix), hasPrefix)
        !           718:        }
        !           719:
        !           720:        test("dir/file", "dir", false)
        !           721:        test("dir/file", "file", true)
        !           722:        test("dir/file", "le", true)
        !           723: }
        !           724:
        !           725: func (s *Suite) Test_CurrPath_HasBase(c *check.C) {
        !           726:        t := s.Init(c)
        !           727:
        !           728:        test := func(curr CurrPath, base string, hasPrefix bool) {
        !           729:                t.CheckEquals(curr.HasBase(base), hasPrefix)
        !           730:        }
        !           731:
        !           732:        test("dir/file", "dir", false)
        !           733:        test("dir/file", "file", true)
        !           734:        test("dir/file", "le", false)
        !           735: }
        !           736:
        !           737: func (s *Suite) Test_CurrPath_TrimSuffix(c *check.C) {
        !           738:        t := s.Init(c)
        !           739:
        !           740:        test := func(curr CurrPath, suffix string, trimmed CurrPath) {
        !           741:                t.CheckEquals(curr.TrimSuffix(suffix), trimmed)
        !           742:        }
        !           743:
        !           744:        test("dir/file", "dir", "dir/file")
        !           745:        test("dir/file", "file", "dir/")
        !           746:        test("dir/file", "le", "dir/fi")
        !           747: }
        !           748:
        !           749: func (s *Suite) Test_CurrPath_ReplaceSuffix(c *check.C) {
        !           750:        t := s.Init(c)
        !           751:
        !           752:        test := func(curr CurrPath, from, to string, replaced CurrPath) {
        !           753:                t.CheckEquals(curr.ReplaceSuffix(from, to), replaced)
        !           754:        }
        !           755:
        !           756:        test("dir/file", "file", "subdir", "dir/subdir")
        !           757:
        !           758:        // The path must actually end with the suffix, otherwise there is
        !           759:        // the risk of creating unintended paths.
        !           760:        t.ExpectAssert(
        !           761:                func() { test("dir/file", "no-match", "anything", "dir/file") })
        !           762: }
        !           763:
        !           764: func (s *Suite) Test_CurrPath_Clean(c *check.C) {
        !           765:        t := s.Init(c)
        !           766:
        !           767:        test := func(curr, cleaned CurrPath) {
        !           768:                t.CheckEquals(curr.Clean(), cleaned)
        !           769:        }
        !           770:
        !           771:        test("dir/file", "dir/file")
        !           772:        test("dir/.////../file", "file")
        !           773: }
        !           774:
        !           775: func (s *Suite) Test_CurrPath_CleanDot(c *check.C) {
        !           776:        t := s.Init(c)
        !           777:
        !           778:        test := func(curr, cleaned CurrPath) {
        !           779:                t.CheckEquals(curr.CleanDot(), cleaned)
        !           780:        }
        !           781:
        !           782:        test("dir/file", "dir/file")
        !           783:        test("dir/.////../file", "dir/../file")
        !           784: }
        !           785:
        !           786: func (s *Suite) Test_CurrPath_CleanPath(c *check.C) {
        !           787:        t := s.Init(c)
        !           788:
        !           789:        test := func(curr, cleaned CurrPath) {
        !           790:                t.CheckEquals(curr.CleanPath(), cleaned)
        !           791:        }
        !           792:
        !           793:        test("a/b/../../c/d/../../e/../f", "a/b/../../e/../f")
        !           794: }
        !           795:
        !           796: func (s *Suite) Test_CurrPath_JoinNoClean(c *check.C) {
        !           797:        t := s.Init(c)
        !           798:
        !           799:        test := func(curr CurrPath, other Path, joined CurrPath) {
        !           800:                t.CheckEquals(curr.JoinNoClean(other), joined)
        !           801:        }
        !           802:
        !           803:        test("", "", "/")
        !           804:        test(".", "file", "./file")
        !           805:        test("dir", "subdir/file", "dir/subdir/file")
        !           806: }
        !           807:
        !           808: func (s *Suite) Test_CurrPath_JoinClean(c *check.C) {
        !           809:        t := s.Init(c)
        !           810:
        !           811:        test := func(curr CurrPath, other Path, joined CurrPath) {
        !           812:                t.CheckEquals(curr.JoinClean(other), joined)
        !           813:        }
        !           814:
        !           815:        test("", "", "")
        !           816:        test(".", "./////file", "file")
        !           817:        test("dir/./.", "../subdir/file", "subdir/file")
        !           818: }
        !           819:
        !           820: func (s *Suite) Test_CurrPath_Rel(c *check.C) {
        !           821:        t := s.Init(c)
        !           822:
        !           823:        test := func(curr, suffix CurrPath, rel Path) {
        !           824:                t.CheckEquals(curr.Rel(suffix), rel)
        !           825:        }
        !           826:
        !           827:        test("dir/subdir", "dir", "..")
        !           828:        test("dir/subdir", "file", "../../file")
        !           829: }
        !           830:
        !           831: func (s *Suite) Test_CurrPath_Rename(c *check.C) {
1.1       rillig    832:        t := s.Init(c)
                    833:
                    834:        f := t.CreateFileLines("filename.old",
                    835:                "line 1")
                    836:        t.CheckEquals(f.IsFile(), true)
1.4     ! rillig    837:        dst := f.ReplaceSuffix(".old", ".new")
1.1       rillig    838:
                    839:        err := f.Rename(dst)
                    840:
                    841:        assertNil(err, "Rename")
                    842:        t.CheckEquals(f.IsFile(), false)
                    843:        t.CheckFileLines("filename.new",
                    844:                "line 1")
                    845: }
                    846:
1.4     ! rillig    847: func (s *Suite) Test_CurrPath_Lstat(c *check.C) {
1.1       rillig    848:        t := s.Init(c)
                    849:
1.4     ! rillig    850:        testDir := func(f CurrPath, isDir bool) {
1.1       rillig    851:                st, err := f.Lstat()
                    852:                assertNil(err, "Lstat")
                    853:                t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
                    854:        }
                    855:
                    856:        t.CreateFileLines("subdir/file")
                    857:        t.CreateFileLines("file")
                    858:
                    859:        testDir(t.File("subdir"), true)
                    860:        testDir(t.File("file"), false)
                    861: }
                    862:
1.4     ! rillig    863: func (s *Suite) Test_CurrPath_Stat(c *check.C) {
1.1       rillig    864:        t := s.Init(c)
                    865:
1.4     ! rillig    866:        testDir := func(f CurrPath, isDir bool) {
1.1       rillig    867:                st, err := f.Stat()
                    868:                assertNil(err, "Stat")
                    869:                t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
                    870:        }
                    871:
                    872:        t.CreateFileLines("subdir/file")
                    873:        t.CreateFileLines("file")
                    874:
                    875:        testDir(t.File("subdir"), true)
                    876:        testDir(t.File("file"), false)
                    877: }
                    878:
1.4     ! rillig    879: func (s *Suite) Test_CurrPath_Exists(c *check.C) {
1.1       rillig    880:        t := s.Init(c)
                    881:
1.4     ! rillig    882:        test := func(f CurrPath, exists bool) {
1.1       rillig    883:                t.CheckEquals(f.Exists(), exists)
                    884:        }
                    885:
                    886:        t.CreateFileLines("subdir/file")
                    887:        t.CreateFileLines("file")
                    888:
                    889:        test(t.File("subdir"), true)
                    890:        test(t.File("file"), true)
                    891:        test(t.File("enoent"), false)
                    892: }
                    893:
1.4     ! rillig    894: func (s *Suite) Test_CurrPath_IsFile(c *check.C) {
1.1       rillig    895:        t := s.Init(c)
                    896:
                    897:        t.CreateFileLines("dir/file")
                    898:
                    899:        t.CheckEquals(t.File("nonexistent").IsFile(), false)
                    900:        t.CheckEquals(t.File("dir").IsFile(), false)
                    901:        t.CheckEquals(t.File("dir/nonexistent").IsFile(), false)
                    902:        t.CheckEquals(t.File("dir/file").IsFile(), true)
                    903: }
                    904:
1.4     ! rillig    905: func (s *Suite) Test_CurrPath_IsDir(c *check.C) {
1.1       rillig    906:        t := s.Init(c)
                    907:
                    908:        t.CreateFileLines("dir/file")
                    909:
                    910:        t.CheckEquals(t.File("nonexistent").IsDir(), false)
                    911:        t.CheckEquals(t.File("dir").IsDir(), true)
                    912:        t.CheckEquals(t.File("dir/nonexistent").IsDir(), false)
                    913:        t.CheckEquals(t.File("dir/file").IsDir(), false)
                    914: }
                    915:
1.4     ! rillig    916: func (s *Suite) Test_CurrPath_Chmod(c *check.C) {
1.1       rillig    917:        t := s.Init(c)
                    918:
1.4     ! rillig    919:        testWritable := func(f CurrPath, writable bool) {
1.1       rillig    920:                lstat, err := f.Lstat()
                    921:                assertNil(err, "Lstat")
                    922:                t.CheckEquals(lstat.Mode().Perm()&0200 != 0, writable)
                    923:        }
                    924:
                    925:        f := t.CreateFileLines("file")
                    926:        testWritable(f, true)
                    927:
                    928:        err := f.Chmod(0444)
                    929:        assertNil(err, "Chmod")
                    930:
                    931:        testWritable(f, false)
                    932: }
                    933:
1.4     ! rillig    934: func (s *Suite) Test_CurrPath_ReadDir(c *check.C) {
1.1       rillig    935:        t := s.Init(c)
                    936:
                    937:        t.CreateFileLines("subdir/file")
                    938:        t.CreateFileLines("file")
                    939:        t.CreateFileLines("CVS/Entries")
                    940:        t.CreateFileLines(".git/info/exclude")
                    941:
                    942:        infos, err := t.File(".").ReadDir()
                    943:
                    944:        assertNil(err, "ReadDir")
                    945:        var names []string
                    946:        for _, info := range infos {
                    947:                names = append(names, info.Name())
                    948:        }
                    949:
                    950:        t.CheckDeepEquals(names, []string{".git", "CVS", "file", "subdir"})
                    951: }
                    952:
1.4     ! rillig    953: func (s *Suite) Test_CurrPath_ReadPaths(c *check.C) {
        !           954:        t := s.Init(c)
        !           955:
        !           956:        t.CreateFileLines("dir/subdir/file")
        !           957:        t.CreateFileLines("dir/CVS/Entries")
        !           958:        t.CreateFileLines("dir/file")
        !           959:
        !           960:        p := t.File("dir")
        !           961:
        !           962:        paths := p.ReadPaths()
        !           963:
        !           964:        t.CheckDeepEquals(paths, []CurrPath{
        !           965:                t.File("dir/file"),
        !           966:                t.File("dir/subdir")})
        !           967: }
        !           968:
        !           969: func (s *Suite) Test_CurrPath_Open(c *check.C) {
1.1       rillig    970:        t := s.Init(c)
                    971:
                    972:        t.CreateFileLines("filename",
                    973:                "line 1",
                    974:                "line 2")
                    975:
                    976:        f, err := t.File("filename").Open()
                    977:
                    978:        assertNil(err, "Open")
                    979:        defer func() { assertNil(f.Close(), "Close") }()
                    980:        var sb strings.Builder
                    981:        n, err := io.Copy(&sb, f)
                    982:        assertNil(err, "Copy")
                    983:        t.CheckEquals(n, int64(14))
                    984:        t.CheckEquals(sb.String(), "line 1\nline 2\n")
                    985: }
                    986:
1.4     ! rillig    987: func (s *Suite) Test_CurrPath_ReadString(c *check.C) {
1.1       rillig    988:        t := s.Init(c)
                    989:
                    990:        t.CreateFileLines("filename",
                    991:                "line 1",
                    992:                "line 2")
                    993:
                    994:        text, err := t.File("filename").ReadString()
                    995:
                    996:        assertNil(err, "ReadString")
                    997:        t.CheckEquals(text, "line 1\nline 2\n")
                    998: }
                    999:
1.4     ! rillig   1000: func (s *Suite) Test_CurrPath_WriteString(c *check.C) {
1.1       rillig   1001:        t := s.Init(c)
                   1002:
                   1003:        err := t.File("filename").WriteString("line 1\nline 2\n")
                   1004:
                   1005:        assertNil(err, "WriteString")
                   1006:        t.CheckFileLines("filename",
                   1007:                "line 1",
                   1008:                "line 2")
                   1009: }
1.4     ! rillig   1010:
        !          1011: func (s *Suite) Test_NewPkgsrcPath(c *check.C) {
        !          1012:        t := s.Init(c)
        !          1013:
        !          1014:        p := NewPkgsrcPath("category/package")
        !          1015:
        !          1016:        t.CheckEquals(p.AsPath(), NewPath("category/package"))
        !          1017: }
        !          1018:
        !          1019: func (s *Suite) Test_PkgsrcPath_String(c *check.C) {
        !          1020:        t := s.Init(c)
        !          1021:
        !          1022:        p := NewPkgsrcPath("any string..././")
        !          1023:
        !          1024:        str := p.String()
        !          1025:
        !          1026:        // No normalization takes place because it is typically not needed.
        !          1027:        t.CheckEquals(str, "any string..././")
        !          1028: }
        !          1029:
        !          1030: func (s *Suite) Test_PkgsrcPath_AsPath(c *check.C) {
        !          1031:        t := s.Init(c)
        !          1032:
        !          1033:        pp := NewPkgsrcPath("./category/package/Makefile")
        !          1034:
        !          1035:        p := pp.AsPath()
        !          1036:
        !          1037:        t.CheckEquals(p.String(), "./category/package/Makefile")
        !          1038: }
        !          1039:
        !          1040: func (s *Suite) Test_PkgsrcPath_DirClean(c *check.C) {
        !          1041:        t := s.Init(c)
        !          1042:
        !          1043:        pp := NewPkgsrcPath("./dir/../dir/base///.")
        !          1044:
        !          1045:        dir := pp.DirClean()
        !          1046:
        !          1047:        t.CheckEquals(dir, NewPkgsrcPath("dir/base"))
        !          1048: }
        !          1049:
        !          1050: func (s *Suite) Test_PkgsrcPath_DirNoClean(c *check.C) {
        !          1051:        t := s.Init(c)
        !          1052:
        !          1053:        pp := NewPkgsrcPath("./dir/../dir/base///.")
        !          1054:
        !          1055:        dir := pp.DirNoClean()
        !          1056:
        !          1057:        t.CheckEquals(dir, NewPkgsrcPath("./dir/../dir/base"))
        !          1058: }
        !          1059:
        !          1060: func (s *Suite) Test_PkgsrcPath_Base(c *check.C) {
        !          1061:        t := s.Init(c)
        !          1062:
        !          1063:        pp := NewPkgsrcPath("dir/base///.")
        !          1064:
        !          1065:        base := pp.Base()
        !          1066:
        !          1067:        t.CheckEquals(base, ".")
        !          1068: }
        !          1069:
        !          1070: func (s *Suite) Test_PkgsrcPath_Count(c *check.C) {
        !          1071:        t := s.Init(c)
        !          1072:
        !          1073:        pp := NewPkgsrcPath("./...////dir")
        !          1074:
        !          1075:        count := pp.Count()
        !          1076:
        !          1077:        t.CheckEquals(count, 2)
        !          1078: }
        !          1079:
        !          1080: func (s *Suite) Test_PkgsrcPath_HasPrefixPath(c *check.C) {
        !          1081:        t := s.Init(c)
        !          1082:
        !          1083:        pp := NewPkgsrcPath("./././///prefix/suffix")
        !          1084:
        !          1085:        hasPrefixPath := pp.HasPrefixPath("prefix")
        !          1086:
        !          1087:        t.CheckEquals(hasPrefixPath, true)
        !          1088: }
        !          1089:
        !          1090: func (s *Suite) Test_PkgsrcPath_JoinNoClean(c *check.C) {
        !          1091:        t := s.Init(c)
        !          1092:
        !          1093:        pp := NewPkgsrcPath("base///.")
        !          1094:
        !          1095:        joined := pp.JoinNoClean("./../rel")
        !          1096:
        !          1097:        t.CheckEquals(joined, NewPkgsrcPath("base///././../rel"))
        !          1098: }
        !          1099:
        !          1100: func (s *Suite) Test_PkgsrcPath_JoinRel(c *check.C) {
        !          1101:        t := s.Init(c)
        !          1102:
        !          1103:        pp := NewPkgsrcPath("base///.")
        !          1104:
        !          1105:        joined := pp.JoinRel("./../rel")
        !          1106:
        !          1107:        t.CheckEquals(joined, NewPkgsrcPath("base///././../rel"))
        !          1108: }
        !          1109:
        !          1110: func (s *Suite) Test_NewPackagePath(c *check.C) {
        !          1111:        t := s.Init(c)
        !          1112:
        !          1113:        p := NewPackagePath("../../category/package")
        !          1114:
        !          1115:        t.CheckEquals(p.AsPath(), NewPath("../../category/package"))
        !          1116: }
        !          1117:
        !          1118: func (s *Suite) Test_PackagePath_AsPath(c *check.C) {
        !          1119:        t := s.Init(c)
        !          1120:
        !          1121:        pp := NewPackagePath("../../category/package/Makefile")
        !          1122:
        !          1123:        p := pp.AsPath()
        !          1124:
        !          1125:        t.CheckEquals(p.String(), "../../category/package/Makefile")
        !          1126: }
        !          1127:
        !          1128: func (s *Suite) Test_PackagePath_String(c *check.C) {
        !          1129:        t := s.Init(c)
        !          1130:
        !          1131:        pp := NewPackagePath("../../category/package/Makefile")
        !          1132:
        !          1133:        str := pp.String()
        !          1134:
        !          1135:        t.CheckEquals(str, "../../category/package/Makefile")
        !          1136: }
        !          1137:
        !          1138: func (s *Suite) Test_PackagePath_JoinNoClean(c *check.C) {
        !          1139:        t := s.Init(c)
        !          1140:
        !          1141:        pp := NewPackagePath("../../category/package/Makefile")
        !          1142:
        !          1143:        p := pp.JoinNoClean("patches")
        !          1144:
        !          1145:        t.CheckEquals(p.String(), "../../category/package/Makefile/patches")
        !          1146: }
        !          1147:
        !          1148: func (s *Suite) Test_PackagePath_IsEmpty(c *check.C) {
        !          1149:        t := s.Init(c)
        !          1150:
        !          1151:        test := func(p PackagePath, isEmpty bool) {
        !          1152:                t.CheckEquals(p.IsEmpty(), isEmpty)
        !          1153:        }
        !          1154:
        !          1155:        test("", true)
        !          1156:        test(".", false)
        !          1157: }
        !          1158:
        !          1159: func (s *Suite) Test_NewRelPath(c *check.C) {
        !          1160:        t := s.Init(c)
        !          1161:
        !          1162:        rel := NewRelPath("dir/file")
        !          1163:
        !          1164:        t.CheckEquals(rel.String(), "dir/file")
        !          1165: }
        !          1166:
        !          1167: func (s *Suite) Test_NewRelPathString(c *check.C) {
        !          1168:        t := s.Init(c)
        !          1169:
        !          1170:        rel := NewRelPathString("dir/file")
        !          1171:
        !          1172:        t.CheckEquals(rel.String(), "dir/file")
        !          1173: }
        !          1174:
        !          1175: func (s *Suite) Test_RelPath_AsPath(c *check.C) {
        !          1176:        t := s.Init(c)
        !          1177:
        !          1178:        rel := NewRelPath("relative")
        !          1179:
        !          1180:        path := rel.AsPath()
        !          1181:
        !          1182:        t.CheckEquals(path.String(), "relative")
        !          1183: }
        !          1184:
        !          1185: func (s *Suite) Test_RelPath_String(c *check.C) {
        !          1186:        t := s.Init(c)
        !          1187:
        !          1188:        rel := NewRelPath(".///rel")
        !          1189:
        !          1190:        str := rel.String()
        !          1191:
        !          1192:        t.CheckEquals(str, ".///rel")
        !          1193: }
        !          1194:
        !          1195: func (s *Suite) Test_RelPath_DirClean(c *check.C) {
        !          1196:        t := s.Init(c)
        !          1197:
        !          1198:        rel := NewRelPath("./dir/../dir///./file")
        !          1199:
        !          1200:        dir := rel.DirClean()
        !          1201:
        !          1202:        t.CheckEquals(dir, NewRelPath("dir"))
        !          1203: }
        !          1204:
        !          1205: func (s *Suite) Test_RelPath_DirNoClean(c *check.C) {
        !          1206:        t := s.Init(c)
        !          1207:
        !          1208:        rel := NewRelPath("./dir/../dir///./file")
        !          1209:
        !          1210:        dir := rel.DirNoClean()
        !          1211:
        !          1212:        t.CheckEquals(dir, NewRelPath("./dir/../dir"))
        !          1213: }
        !          1214:
        !          1215: func (s *Suite) Test_RelPath_Base(c *check.C) {
        !          1216:        t := s.Init(c)
        !          1217:
        !          1218:        rel := NewRelPath("./dir////./file")
        !          1219:
        !          1220:        base := rel.Base()
        !          1221:
        !          1222:        t.CheckEquals(base, "file")
        !          1223: }
        !          1224:
        !          1225: func (s *Suite) Test_RelPath_HasBase(c *check.C) {
        !          1226:        t := s.Init(c)
        !          1227:
        !          1228:        test := func(rel RelPath, base string, hasBase bool) {
        !          1229:                t.CheckEquals(rel.HasBase(base), hasBase)
        !          1230:        }
        !          1231:
        !          1232:        test("./dir/Makefile", "Makefile", true)
        !          1233:        test("./dir/Makefile", "Make", false)
        !          1234:        test("./dir/Makefile", "file", false)
        !          1235:        test("./dir/Makefile", "dir/Makefile", false)
        !          1236: }
        !          1237:
        !          1238: func (s *Suite) Test_RelPath_Parts(c *check.C) {
        !          1239:        t := s.Init(c)
        !          1240:
        !          1241:        rel := NewRelPath("./dir/.///base")
        !          1242:
        !          1243:        parts := rel.Parts()
        !          1244:
        !          1245:        t.CheckDeepEquals(parts, []string{"dir", "base"})
        !          1246: }
        !          1247:
        !          1248: func (s *Suite) Test_RelPath_Count(c *check.C) {
        !          1249:        t := s.Init(c)
        !          1250:
        !          1251:        rel := NewRelPath("./dir/.///base")
        !          1252:
        !          1253:        count := rel.Count()
        !          1254:
        !          1255:        t.CheckDeepEquals(count, 2)
        !          1256: }
        !          1257:
        !          1258: func (s *Suite) Test_RelPath_Clean(c *check.C) {
        !          1259:        t := s.Init(c)
        !          1260:
        !          1261:        rel := NewRelPath("a/b/../../c/d/../../e/../f")
        !          1262:
        !          1263:        cleaned := rel.Clean()
        !          1264:
        !          1265:        t.CheckEquals(cleaned, NewRelPath("f"))
        !          1266: }
        !          1267:
        !          1268: func (s *Suite) Test_RelPath_CleanPath(c *check.C) {
        !          1269:        t := s.Init(c)
        !          1270:
        !          1271:        rel := NewRelPath("a/b/../../c/d/../../e/../f")
        !          1272:
        !          1273:        cleaned := rel.CleanPath()
        !          1274:
        !          1275:        t.CheckEquals(cleaned, NewRelPath("a/b/../../e/../f"))
        !          1276: }
        !          1277:
        !          1278: func (s *Suite) Test_RelPath_JoinNoClean(c *check.C) {
        !          1279:        t := s.Init(c)
        !          1280:
        !          1281:        rel := NewRelPath("basedir/.//")
        !          1282:
        !          1283:        joined := rel.JoinNoClean("./other")
        !          1284:
        !          1285:        t.CheckEquals(joined, NewRelPath("basedir/.///./other"))
        !          1286: }
        !          1287:
        !          1288: func (s *Suite) Test_RelPath_Replace(c *check.C) {
        !          1289:        t := s.Init(c)
        !          1290:
        !          1291:        rel := NewRelPath("dir/subdir/file")
        !          1292:
        !          1293:        replaced := rel.Replace("/", ":")
        !          1294:
        !          1295:        t.CheckEquals(replaced, NewRelPath("dir:subdir:file"))
        !          1296: }
        !          1297:
        !          1298: func (s *Suite) Test_RelPath_HasPrefixPath(c *check.C) {
        !          1299:        t := s.Init(c)
        !          1300:
        !          1301:        rel := NewRelPath("dir/subdir/file")
        !          1302:
        !          1303:        t.CheckEquals(rel.HasPrefixPath("dir"), true)
        !          1304:        t.CheckEquals(rel.HasPrefixPath("dir/sub"), false)
        !          1305:        t.CheckEquals(rel.HasPrefixPath("subdir"), false)
        !          1306: }
        !          1307:
        !          1308: func (s *Suite) Test_RelPath_ContainsPath(c *check.C) {
        !          1309:        t := s.Init(c)
        !          1310:
        !          1311:        rel := NewRelPath("dir/subdir/file")
        !          1312:
        !          1313:        t.CheckEquals(rel.ContainsPath("dir"), true)
        !          1314:        t.CheckEquals(rel.ContainsPath("dir/sub"), false)
        !          1315:        t.CheckEquals(rel.ContainsPath("subdir"), true)
        !          1316: }
        !          1317:
        !          1318: func (s *Suite) Test_RelPath_ContainsText(c *check.C) {
        !          1319:        t := s.Init(c)
        !          1320:
        !          1321:        rel := NewRelPath("dir/subdir/file")
        !          1322:
        !          1323:        t.CheckEquals(rel.ContainsText("dir"), true)
        !          1324:        t.CheckEquals(rel.ContainsText("dir/sub"), true)
        !          1325:        t.CheckEquals(rel.ContainsText("subdir"), true)
        !          1326:        t.CheckEquals(rel.ContainsText("super"), false)
        !          1327: }
        !          1328:
        !          1329: func (s *Suite) Test_RelPath_HasSuffixPath(c *check.C) {
        !          1330:        t := s.Init(c)
        !          1331:
        !          1332:        rel := NewRelPath("dir/subdir/file")
        !          1333:
        !          1334:        t.CheckEquals(rel.HasSuffixPath("file"), true)
        !          1335:        t.CheckEquals(rel.HasSuffixPath("subdir/file"), true)
        !          1336:        t.CheckEquals(rel.HasSuffixPath("subdir"), false)
        !          1337: }

CVSweb <webmaster@jp.NetBSD.org>