@@ -198,3 +198,195 @@ func BenchmarkRegexCacheVsCompile(b *testing.B) {
202+func TestIsTextFile(t *testing.T) {
204+ tempDir := t.TempDir()
214+ filename: "test.go",
215+ content: []byte("package main\n\nfunc main() {}\n"),
220+ filename: "config.yaml",
221+ content: []byte("key: value\nlist:\n - item1\n - item2\n"),
226+ filename: "config.yml",
227+ content: []byte("key: value\n"),
232+ filename: "data.json",
233+ content: []byte(`{"key": "value"}`),
237+ name: "javascript file",
238+ filename: "script.js",
239+ content: []byte("console.log('hello');\n"),
243+ name: "typescript file",
244+ filename: "script.ts",
245+ content: []byte("const x: string = 'hello';\n"),
249+ name: "markdown file",
250+ filename: "README.md",
251+ content: []byte("# Title\n\nSome content\n"),
255+ name: "shell script",
256+ filename: "script.sh",
257+ content: []byte("#!/bin/bash\necho 'hello'\n"),
261+ name: "python file",
262+ filename: "script.py",
263+ content: []byte("print('hello')\n"),
268+ filename: "data.xml",
269+ content: []byte("<?xml version=\"1.0\"?>\n<root></root>\n"),
274+ filename: "file.txt",
275+ content: []byte("plain text content\n"),
280+ filename: "style.css",
281+ content: []byte("body { color: red; }\n"),
286+ filename: "style.scss",
287+ content: []byte("$primary: blue;\nbody { color: $primary; }\n"),
292+ filename: "style.sass",
293+ content: []byte("$primary: blue\nbody\n color: $primary\n"),
298+ filename: "main.rs",
299+ content: []byte("fn main() {\n println!(\"Hello, world!\");\n}\n"),
304+ filename: "main.zig",
305+ content: []byte("const std = @import(\"std\");\npub fn main() void {}\n"),
310+ filename: "Main.java",
311+ content: []byte("public class Main {\n public static void main(String[] args) {}\n}\n"),
317+ content: []byte("#include <stdio.h>\nint main() { return 0; }\n"),
322+ filename: "main.cpp",
323+ content: []byte("#include <iostream>\nint main() { return 0; }\n"),
328+ filename: "script.fish",
329+ content: []byte("#!/usr/bin/env fish\necho 'hello'\n"),
333+ name: "powershell file",
334+ filename: "script.ps1",
335+ content: []byte("Write-Host 'Hello, World!'\n"),
339+ name: "cmd batch file",
340+ filename: "script.bat",
341+ content: []byte("@echo off\necho Hello, World!\n"),
346+ filename: "script.cmd",
347+ content: []byte("@echo off\necho Hello, World!\n"),
352+ filename: "binary.exe",
353+ content: []byte{0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00},
358+ filename: "image.png",
359+ content: []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A},
364+ filename: "image.jpg",
365+ content: []byte{0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46},
369+ name: "zip archive",
370+ filename: "archive.zip",
371+ content: []byte{0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x00, 0x00},
376+ filename: "document.pdf",
377+ content: []byte("%PDF-1.4\n%âãÏÓ\n"),
382+ for _, tt := range tests {
383+ t.Run(tt.name, func(t *testing.T) {
385+ filePath := filepath.Join(tempDir, tt.filename)
386+ require.NoError(t, os.WriteFile(filePath, tt.content, 0o644))
388+ got := isTextFile(filePath)
389+ require.Equal(t, tt.wantText, got, "isTextFile(%s) = %v, want %v", tt.filename, got, tt.wantText)