-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansichroma_test.go
80 lines (66 loc) · 1.86 KB
/
ansichroma_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ansichroma_test
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/alecthomas/chroma/lexers"
"github.com/yorukot/ansichroma"
)
func TestAllFilesWithPathInDirectory(t *testing.T) {
testDir := "./testFile"
err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
format := lexers.Match(filepath.Base(path))
if format == nil {
fmt.Printf("\n=======================================\n")
fmt.Print("PASS unsupported Language or not text file\n")
return nil
}
result, err := ansichroma.HighlightFromFile(path, 0, "catppuccin-frappe", "#1e1e2e")
fmt.Printf("\n=======================================\n[%s Test] File: %s\n\n", format.Config().Name, path)
fmt.Println(result)
if err != nil {
t.Errorf("Error while running %s: %s", path, err)
}
return nil
})
if err != nil {
t.Errorf("Error while walking directory: %s", err)
}
}
func TestAllFilesWithStringInDirectory(t *testing.T) {
testDir := "./testFile"
err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
content, err := os.ReadFile(path)
if err != nil {
t.Errorf("Error while read file %s: %s", path, err)
}
format := lexers.Match(filepath.Base(path))
if format == nil {
t.Log("PASS unsupported Language or not text file")
return nil
}
result, err := ansichroma.HightlightString(string(content), format.Config().Name, "catppuccin-frappe", "#1e1e2e")
fmt.Printf("\n=======================================\n[%s Test] File: %s\n\n",format.Config().Name, path)
fmt.Println(result)
if err != nil {
t.Errorf("Error while running %s: %s", path, err)
}
return nil
})
if err != nil {
t.Errorf("Error while walking directory: %s", err)
}
}