|
| 1 | +-- runTests #[ |
| 2 | +-- ("FindRecursive", fun (currentTmpDir : FilePath) => do -- TODO: this is a limitation of glob-posix, no support of recursion |
| 3 | +-- writeFile "foo.txt" "content" |
| 4 | +-- createDir "subdir" |
| 5 | +-- writeFile "subdir/bar.txt" "content" |
| 6 | +-- writeFile "subdir/foo.txt" "content" |
| 7 | +-- createDir "subdir/another_subdir" |
| 8 | +-- writeFile "subdir/another_subdir/bar.txt" "content" |
| 9 | +-- writeFile "subdir/another_subdir/foo.txt" "content" |
| 10 | +-- assertGlob nel![PatternSegment.doubleStar, nes!"foo.txt"] #["foo.txt", "subdir/foo.txt", "subdir/another_subdir/foo.txt"] |
| 11 | +-- assertGlob nel![nes!"foo.txt"]] #["foo.txt"] |
| 12 | +-- assertGlob nel![PatternSegment.oneStar, nes!"foo.txt"] #["subdir/foo.txt"] |
| 13 | +-- ] |
| 14 | +-- -- ("BasicWildcard", fun (_tmpDir : FilePath) => do |
| 15 | +-- -- writeFile "file1.txt" "content" |
| 16 | +-- -- writeFile "file2.txt" "content" |
| 17 | +-- -- writeFile "image.png" "content" |
| 18 | +-- -- createDir "subdir" |
| 19 | +-- -- writeFile "subdir/file3.txt" "content" |
| 20 | +-- -- createDir "empty_dir" |
| 21 | +-- |
| 22 | +-- -- let results ← glob "*.txt" |
| 23 | +-- -- assertEq "Basic wildcard *.txt" #["file1.txt", "file2.txt"] results |
| 24 | +-- |
| 25 | +-- -- let allFiles ← glob "*" |
| 26 | +-- -- assertEq "All files *" #["file1.txt", "file2.txt", "image.png", "empty_dir", "subdir"] allFiles), |
| 27 | +-- -- ("QuestionMark", fun (_tmpDir : FilePath) => do |
| 28 | +-- -- writeFile "doc1" "content" |
| 29 | +-- -- writeFile "doc2" "content" |
| 30 | +-- -- writeFile "doc_long" "content" |
| 31 | +-- |
| 32 | +-- -- let results ← glob "doc?" |
| 33 | +-- -- assertEq "Question mark doc?" #["doc1", "doc2"] results), |
| 34 | +-- -- ("CharacterClass", fun (_tmpDir : FilePath) => do |
| 35 | +-- -- writeFile "apple" "content" |
| 36 | +-- -- writeFile "apricot" "content" |
| 37 | +-- -- writeFile "banana" "content" |
| 38 | +-- -- assertEq "Character class a[p-r]*" #["apple", "apricot"] (← glob "a[p-r]*")), |
| 39 | +-- -- ("GlobWithDirMark", fun (_tmpDir : FilePath) => do |
| 40 | +-- -- writeFile "file.txt" "content" |
| 41 | +-- -- createDir "mydir" |
| 42 | +-- -- createDir "another_dir" |
| 43 | +-- -- let expected := #["file.txt", "mydir/", "another_dir/"] |
| 44 | +-- -- assertEq "globWithDirMark *" expected (← globWithDirMark "*")), |
| 45 | +-- -- ("GlobUnsorted", fun (_tmpDir : FilePath) => do |
| 46 | +-- -- writeFile "c.txt" "c" |
| 47 | +-- -- writeFile "a.txt" "a" |
| 48 | +-- -- writeFile "b.txt" "b" |
| 49 | +-- -- -- We can't assert a specific order, just that all are present and count is correct |
| 50 | +-- -- assertEq "globUnsorted *.txt" #["a.txt", "b.txt", "c.txt"] (← globUnsorted "*.txt")), |
| 51 | +-- -- ("CheckPattern", fun (_tmpDir : FilePath) => do |
| 52 | +-- -- writeFile "existing.txt" "content" |
| 53 | +-- -- writeFile "another.md" "content" |
| 54 | +-- -- assertBool "checkPattern *.txt (true)" true (← checkPattern "*.txt") |
| 55 | +-- -- assertBool "checkPattern *.xyz (false)" false (← checkPattern "*.xyz") |
| 56 | +-- -- assertBool "checkPattern existing.txt (true)" true (← checkPattern "existing.txt") |
| 57 | +-- -- assertBool "checkPattern non_existing.txt (false)" false (← checkPattern "non_existing.txt")), |
| 58 | +-- -- ("GlobMany", fun (_tmpDir : FilePath) => do |
| 59 | +-- -- writeFile "file.txt" "content" |
| 60 | +-- -- writeFile "doc.md" "content" |
| 61 | +-- -- writeFile "image.jpg" "content" |
| 62 | +-- -- writeFile "data.csv" "content" |
| 63 | +-- -- assertEq "globMany multiple extensions" #["file.txt", "doc.md", "data.csv"] (← globMany #["*.txt", "*.md", "*.csv"]) |
| 64 | +-- -- assertEq "globMany mixed (some match, some no match)" #["file.txt"] (← globMany #["*.xyz", "*.txt"]) |
| 65 | +-- -- assertIsEmpty "globMany all no match" (← globMany #["*.xyz", "*.abc"])), |
| 66 | +-- -- ("GlobWithBraces", fun (_tmpDir : FilePath) => do |
| 67 | +-- -- writeFile "config.json" "content" |
| 68 | +-- -- writeFile "config.yaml" "content" |
| 69 | +-- -- writeFile "config.txt" "content" |
| 70 | +-- -- writeFile "data.json" "content" |
| 71 | +-- -- assertEq "globWithBraces config.{json,yaml}" #["config.json", "config.yaml"] (← globWithBraces "config.{json,yaml}")), |
| 72 | +-- -- ("GlobWithTilde", fun (_tmpDir : FilePath) => do |
| 73 | +-- -- -- Tilde expansion is highly environment-dependent. This test primarily checks |
| 74 | +-- -- -- that the flag is passed and doesn't cause a crash. A true functional test |
| 75 | +-- -- -- would require setting up a controlled home directory, which is non-trivial. |
| 76 | +-- -- let homeDirFile := "~/.profile" |
| 77 | +-- -- let results ← globWithTilde homeDirFile |
| 78 | +-- -- if results.isEmpty then |
| 79 | +-- -- IO.println s!"Warning: {homeDirFile} not found or tilde expansion failed. (This might be normal depending on environment/config)" |
| 80 | +-- -- pure () |
| 81 | +-- -- else |
| 82 | +-- -- assertIsNotEmpty "globWithTilde ~/" results |
| 83 | +-- -- IO.println s!"Found {results.size} files with tilde expansion, e.g., {results[0]!}"), |
| 84 | +-- -- ("GlobDirsOnly", fun (tmpDir : FilePath) => do |
| 85 | +-- -- writeFile "file.txt" "content" |
| 86 | +-- -- createDir "dir1" |
| 87 | +-- -- createDir "dir2" |
| 88 | +-- -- writeFile (tmpDir / "dir1" / "nested_file.txt") "content" |
| 89 | +-- -- assertEq "globDirsOnly *" #["dir1/", "dir2/"] (← globDirsOnly "*")), |
| 90 | +-- -- ("GlobSafe", fun (_tmpDir : FilePath) => do |
| 91 | +-- -- writeFile "present.txt" "content" |
| 92 | +-- -- assertEq "globSafe (match)" #["present.txt"] (← globSafe "*.txt") |
| 93 | +-- -- assertEq "globSafe (no match, nocheck)" #["nonexistent.*"] (← globSafe "nonexistent.*") |
| 94 | +-- -- assertEq "globSafe (literal no match, nocheck)" #["definitely_not_here.md"] (← globSafe "definitely_not_here.md")), |
| 95 | +-- -- ("FindByExtension", fun (_tmpDir : FilePath) => do |
| 96 | +-- -- writeFile "a.lean" "content" |
| 97 | +-- -- writeFile "b.md" "content" |
| 98 | +-- -- writeFile "c.lean" "content" |
| 99 | +-- -- assertEq "findByExtension lean" #["a.lean", "c.lean"] (← findByExtension "lean") |
| 100 | +-- -- assertIsEmpty "findByExtension xyz (empty)" (← findByExtension "xyz")), |
| 101 | +-- -- ("FindByExtensions", fun (_tmpDir : FilePath) => do |
| 102 | +-- -- writeFile "a.lean" "content" |
| 103 | +-- -- writeFile "b.md" "content" |
| 104 | +-- -- writeFile "c.txt" "content" |
| 105 | +-- -- writeFile "d.json" "content" |
| 106 | +-- -- assertEq "findByExtensions lean, txt" #["a.lean", "c.txt"] (← findByExtensions #["lean", "txt"]) |
| 107 | +-- -- assertIsEmpty "findByExtensions xyz, abc (empty)" (← findByExtensions #["xyz", "abc"])), |
| 108 | +-- -- ("FindDirectories", fun (tmpDir : FilePath) => do |
| 109 | +-- -- writeFile "file.txt" "content" |
| 110 | +-- -- createDir "dir1" |
| 111 | +-- -- createDir "dir2" |
| 112 | +-- -- writeFile (tmpDir / "dir1" / "nested.txt") "content" |
| 113 | +-- -- assertEq "findDirectories" #["dir1/", "dir2/"] (← findDirectories)), |
| 114 | +-- -- ("NoMatchesWithoutNoCheck", fun (_tmpDir : FilePath) => do |
| 115 | +-- -- assertIsEmpty "No matches without nocheck" (← glob "*.nonexistent")), |
| 116 | +-- -- ("TestErrFlag", fun (tmpDir : FilePath) => do |
| 117 | +-- -- -- This test remains limited due to portability of permissions. |
| 118 | +-- -- -- It primarily ensures the flag passes and doesn't crash the FFI. |
| 119 | +-- -- let restrictedDir := tmpDir / "restricted" |
| 120 | +-- -- createDir restrictedDir |
| 121 | +-- -- -- One *could* attempt `IO.Process.runCommand` for `chmod` but it's not portable |
| 122 | +-- -- -- across OSes or always reliable for testing specific error conditions. |
| 123 | +-- -- let results ← glob (restrictedDir / "*").toString { GlobFlags.default with err := true } |
| 124 | +-- -- IO.println s!"TestErrFlag: Results: {results}" |
| 125 | +-- -- ) |
| 126 | +-- /- ] -/ |
0 commit comments