restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -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))
}
}