-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
67 lines (56 loc) · 1.41 KB
/
main_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
package main
import (
"os"
"path/filepath"
"testing"
)
func TestToPascalCase(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"my-icon_name", "MyIconName"},
{"hello_world", "HelloWorld"},
{"test-case", "TestCase"},
{"singleword", "Singleword"},
{"", ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
result := toPascalCase(tt.input)
if result != tt.expected {
t.Errorf("For input '%s', expected '%s' but got '%s'", tt.input, tt.expected, result)
}
})
}
}
func TestConvertSVGToTSX(t *testing.T) {
inputDir := "./test_input"
outputDir := "./test_output"
os.RemoveAll(inputDir)
os.RemoveAll(outputDir)
err := os.MkdirAll(inputDir, 0755)
if err != nil {
t.Fatalf("Failed to create input directory: %v", err)
}
err = os.MkdirAll(outputDir, 0755)
if err != nil {
t.Fatalf("Failed to create output directory: %v", err)
}
svgContent := "<svg>...</svg>"
err = os.WriteFile(filepath.Join(inputDir, "sample.svg"), []byte(svgContent), 0644)
if err != nil {
t.Fatalf("Failed to create SVG file: %v", err)
}
err = convertSVGToTSX(inputDir, outputDir)
if err != nil {
t.Fatalf("Error converting SVG to TSX: %v", err)
}
outputFile := filepath.Join(outputDir, "SampleIcon.tsx")
_, err = os.ReadFile(outputFile)
if err != nil {
t.Fatalf("Failed to read output TSX file: %v", err)
}
os.RemoveAll(inputDir)
os.RemoveAll(outputDir)
}