restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct TerminalContextMenuTests {
|
||||
private func labels(_ target: ContextTarget) -> [String] {
|
||||
ContextActions.entries(for: target).compactMap { entry in
|
||||
guard case let .action(_, label) = entry else { return nil }
|
||||
return label
|
||||
}
|
||||
}
|
||||
|
||||
@Test func copyAppearsOnlyWithASelection() {
|
||||
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste"])
|
||||
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
|
||||
}
|
||||
|
||||
@Test func theActionsNameTheirPane() {
|
||||
#expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [
|
||||
.action(.copyTerminalSelection(.shell), label: "Copy"),
|
||||
.action(.pasteIntoTerminal(.shell), label: "Paste"),
|
||||
])
|
||||
}
|
||||
|
||||
@Test func theMenuHasNoHeader() {
|
||||
#expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct FileLimitsTests {
|
||||
@Test("a NUL byte in the first 8000 bytes marks a file binary")
|
||||
func binary() {
|
||||
#expect(FileLimits.looksBinary(Data([0x00, 0x01, 0x02])))
|
||||
#expect(!FileLimits.looksBinary(Data("plain text".utf8)))
|
||||
#expect(!FileLimits.looksBinary(Data(repeating: 0x41, count: 8000) + Data([0x00])))
|
||||
}
|
||||
|
||||
@Test("ripgrep gets the base ignores, the configured excludes and --no-ignore")
|
||||
func ripgrepArguments() {
|
||||
var files = HelderConfig.Files()
|
||||
files.exclude = ["*.log", ""]
|
||||
let args = IgnoreRules.ripgrepArguments(files: files, base: ["node_modules"])
|
||||
#expect(args == ["--glob", "!node_modules", "--glob", "!*.log", "--no-ignore"])
|
||||
files.exclude = []
|
||||
files.followGitignore = true
|
||||
let following = IgnoreRules.ripgrepArguments(files: files, base: [])
|
||||
#expect(following.isEmpty)
|
||||
}
|
||||
|
||||
@Test("symbol searches index vendor declarations but skip vendor references")
|
||||
func symbolIgnores() {
|
||||
#expect(!IgnoreRules.symbolDeclarationIgnore.contains("vendor"))
|
||||
#expect(IgnoreRules.symbolReferenceIgnore.contains("vendor"))
|
||||
}
|
||||
|
||||
@Test("the watcher drops events inside ignored folders")
|
||||
func watchIgnored() {
|
||||
#expect(IgnoreRules.isWatchIgnored("node_modules/x/y.js"))
|
||||
#expect(IgnoreRules.isWatchIgnored("a/.git/HEAD"))
|
||||
#expect(!IgnoreRules.isWatchIgnored("src/gitlike/x"))
|
||||
#expect(IgnoreRules.isWalkIgnored(".DS_Store"))
|
||||
}
|
||||
|
||||
@Test("the watcher drops framework caches and the configured excludes")
|
||||
func watchIgnoredWithExcludes() {
|
||||
#expect(IgnoreRules.isWatchIgnored("storage/framework/views/abc.php", exclude: []))
|
||||
#expect(IgnoreRules.isWatchIgnored("bootstrap/cache/packages.php", exclude: []))
|
||||
#expect(IgnoreRules.isWatchIgnored(".phpunit.result.cache", exclude: []))
|
||||
#expect(IgnoreRules.isWatchIgnored("node_modules/x.js", exclude: []))
|
||||
#expect(!IgnoreRules.isWatchIgnored("storage/logs/laravel.log", exclude: []))
|
||||
#expect(IgnoreRules.isWatchIgnored("storage/logs/laravel.log", exclude: ["*.log"]))
|
||||
#expect(IgnoreRules.isWatchIgnored("public/hot/x.js", exclude: ["public/hot"]))
|
||||
#expect(!IgnoreRules.isWatchIgnored("app/Models/User.php", exclude: ["*.log", ""]))
|
||||
}
|
||||
|
||||
@Test("glob matching follows ripgrep's --glob rules", arguments: [
|
||||
("*.log", "debug.log", true),
|
||||
("*.log", "logs/deep/debug.log", true),
|
||||
("*.log", "debug.log.txt", false),
|
||||
("node_modules", "node_modules", true),
|
||||
("node_modules", "a/node_modules/pkg/index.js", true),
|
||||
("node_modules", "node_modules_extra/x", false),
|
||||
("src/*.ts", "src/a.ts", true),
|
||||
("src/*.ts", "src/deep/a.ts", false),
|
||||
("src/*.ts", "lib/src/a.ts", false),
|
||||
("/build", "build/x.js", true),
|
||||
("/build", "app/build/x.js", false),
|
||||
("docs/", "docs/readme.md", true),
|
||||
("**/fixtures/*.json", "fixtures/a.json", true),
|
||||
("**/fixtures/*.json", "tests/unit/fixtures/a.json", true),
|
||||
("a/**/b", "a/b", true),
|
||||
("a/**/b", "a/x/y/b", true),
|
||||
("storage/**", "storage/logs/x.log", true),
|
||||
("file?.txt", "file1.txt", true),
|
||||
("file?.txt", "file10.txt", false),
|
||||
("[abc].md", "b.md", true),
|
||||
("[!abc].md", "b.md", false),
|
||||
("[a-c]x", "cx", true),
|
||||
("*.{js,ts}", "x.ts", true),
|
||||
("*.{js,ts}", "x.css", false),
|
||||
("", "a", false),
|
||||
("*.min.*", "dist-like/app.min.js", true),
|
||||
])
|
||||
func glob(pattern: String, path: String, matches: Bool) {
|
||||
#expect(IgnoreRules.globMatches(pattern, path: path) == matches)
|
||||
}
|
||||
|
||||
@Test("a pathological glob still answers quickly")
|
||||
func pathologicalGlob() {
|
||||
let path = String(repeating: "a", count: 200)
|
||||
#expect(!IgnoreRules.globMatches("*a*a*a*a*a*a*a*a*b", path: path))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct FileNodeTests {
|
||||
private func names(_ node: FileNode?) -> [String] {
|
||||
(node?.children ?? []).map(\.name)
|
||||
}
|
||||
|
||||
@Test("folders come before files, each sorted by name")
|
||||
func foldersFirst() {
|
||||
let tree = FileTree.build(rootName: "proj", paths: ["README.md", "src/a.ts", "logo.bin", "app/x.php"])
|
||||
#expect(tree.name == "proj")
|
||||
#expect(tree.path == "")
|
||||
#expect(names(tree) == ["app", "src", "logo.bin", "README.md"])
|
||||
}
|
||||
|
||||
@Test("sorting ignores case, like localeCompare")
|
||||
func caseInsensitiveSort() {
|
||||
let tree = FileTree.build(rootName: "p", paths: ["b.txt", "A.txt", "a.md", "C.txt"])
|
||||
#expect(names(tree) == ["a.md", "A.txt", "b.txt", "C.txt"])
|
||||
}
|
||||
|
||||
@Test("nested paths build nested folders with full relative paths")
|
||||
func nesting() {
|
||||
let tree = FileTree.build(rootName: "p", paths: ["a/b/c.txt", "a/d.txt"])
|
||||
let b = FileTree.find("a/b", in: tree)
|
||||
#expect(b?.kind == .directory)
|
||||
#expect(names(b) == ["c.txt"])
|
||||
#expect(FileTree.find("a/b/c.txt", in: tree)?.kind == .file)
|
||||
#expect(FileTree.find("a/b/c.txt", in: tree)?.children == nil)
|
||||
}
|
||||
|
||||
@Test("empty folders that rg cannot list are forced into the tree")
|
||||
func emptyFolders() {
|
||||
let tree = FileTree.build(rootName: "p", paths: ["src/a.ts"], emptyDirs: ["empty", "src/nested/deep"])
|
||||
#expect(names(tree) == ["empty", "src"])
|
||||
#expect(FileTree.find("empty", in: tree)?.children == [])
|
||||
#expect(names(FileTree.find("src/nested", in: tree)) == ["deep"])
|
||||
}
|
||||
|
||||
@Test("duplicate and malformed paths do not duplicate nodes")
|
||||
func duplicates() {
|
||||
let tree = FileTree.build(rootName: "p", paths: ["a.txt", "a.txt", "", "/b.txt", "c//d.txt"], emptyDirs: ["", "c"])
|
||||
#expect(names(tree) == ["c", "a.txt", "b.txt"])
|
||||
#expect(names(FileTree.find("c", in: tree)) == ["d.txt"])
|
||||
}
|
||||
|
||||
@Test("an empty listing is an empty root")
|
||||
func emptyListing() {
|
||||
#expect(FileTree.build(rootName: "p", paths: []) == FileNode(name: "p", kind: .directory, path: "", children: []))
|
||||
}
|
||||
|
||||
@Test("visible rows honour expanded folders and hidden files")
|
||||
func visibleRows() {
|
||||
let tree = FileTree.build(rootName: "p", paths: [".env", "src/a.ts", "src/.hidden", "b.txt"])
|
||||
#expect(FileTree.visibleRows(tree, expanded: [], showHidden: false).map(\.path) == ["src", "b.txt"])
|
||||
let open = FileTree.visibleRows(tree, expanded: ["src"], showHidden: true)
|
||||
#expect(open.map(\.path) == ["src", "src/.hidden", "src/a.ts", ".env", "b.txt"])
|
||||
#expect(open.map(\.depth) == [0, 1, 1, 0, 0])
|
||||
}
|
||||
|
||||
@Test("replacing a folder's children leaves the rest of the tree alone")
|
||||
func replacingChildren() {
|
||||
let tree = FileTree.build(rootName: "p", paths: ["src/a.ts", "lib/b.ts"])
|
||||
let fresh = FileNode(name: "z.ts", kind: .file, path: "src/z.ts")
|
||||
let updated = FileTree.replacingChildren(of: "src", with: [fresh], in: tree)
|
||||
#expect(names(FileTree.find("src", in: updated)) == ["z.ts"])
|
||||
#expect(names(FileTree.find("lib", in: updated)) == ["b.ts"])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct FileTypeTests {
|
||||
@Test func badgesFollowTheOldTable() {
|
||||
#expect(FileType.badge(for: "src/A.php") == FileBadge("php", .purple))
|
||||
#expect(FileType.badge(for: "package.json") == FileBadge("json", .amber))
|
||||
#expect(FileType.badge(for: "composer.json") == FileBadge("json", .purple))
|
||||
#expect(FileType.badge(for: ".env.local") == FileBadge("env", .teal))
|
||||
#expect(FileType.badge(for: "Makefile") == FileBadge("·", .grey))
|
||||
}
|
||||
|
||||
@Test func languagesAndLabels() {
|
||||
#expect(FileType.language(for: "a.tsx") == .tsx)
|
||||
#expect(FileType.languageLabel(for: "a.yml") == "YAML")
|
||||
#expect(FileType.languageLabel(for: "a.rs") == "RS")
|
||||
#expect(FileType.isImage("logo.PNG"))
|
||||
}
|
||||
|
||||
@Test func ripgrepArgumentsHonourTheConfig() {
|
||||
var files = HelderConfig.Files()
|
||||
files.exclude = ["*.log"]
|
||||
let args = IgnoreRules.ripgrepArguments(files: files, base: ["node_modules"])
|
||||
#expect(args == ["--glob", "!node_modules", "--glob", "!*.log", "--no-ignore"])
|
||||
}
|
||||
|
||||
@Test func pathHelpers() {
|
||||
#expect(PathUtils.ancestors("a/b/c.txt") == ["a", "a/b"])
|
||||
#expect(PathUtils.remap("a/b/c.txt", from: "a/b", to: "a/x", isDirectory: true) == "a/x/c.txt")
|
||||
#expect(PathUtils.validatedName(" ../ ") == nil)
|
||||
#expect(PathUtils.validatedName("new.md/") == "new.md")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user