This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
process_test.go
150 lines (125 loc) · 3.87 KB
/
process_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"errors"
"testing"
)
var errUnreadable = errors.New("can not read file")
type mockFileSystem struct {
}
func (mockFileSystem) readFile(filename string) ([]byte, error) {
if filename == "unsupported_file.csv" {
return []byte(`this;is;a;nice;csvtr("tr")`), nil
} else if filename == "unreadable_file.tscn" {
return []byte{}, errUnreadable
} else if filename == "single_translatable.gd" {
return []byte(`extends Node
func _ready():
my_function(tr("Hello!"))
`), nil
} else if filename == "single_translatable.tscn" {
return []byte(`[gd_scene load_steps=7 format=2]
[node name="start_button" type="Button" parent="." index="3"]
shortcut = null
group = null
text = "Start game"
flat = false
align = 1`), nil
} else if filename == "empty_msgid.gd" {
return []byte(`extends Node
func _ready():
my_function(tr(""))
`), nil
} else if filename == "duplicate_msgids.gd" {
return []byte(`extends Node
func _ready():
my_function(tr("new game"), tr("new game"))
`), nil
}
return []byte{}, nil
}
func TestProcessNoFilePaths(t *testing.T) {
_, err := process(mockFileSystem{}, []string{})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
}
func TestProcessUnsupportedFile(t *testing.T) {
poFile, err := process(mockFileSystem{}, []string{
"unsupported_file.jpg",
})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
numTranslations := len(poFile.Translations)
if numTranslations > 0 {
t.Fatalf("expected process to skip all unsupported files resulting in no translations, but found %v (%v)", numTranslations, poFile)
}
}
func TestProcessUnreadableFile(t *testing.T) {
_, err := process(mockFileSystem{}, []string{
"unreadable_file.tscn",
})
if err == nil {
t.Fatalf("expected an error to be returned, but got nil")
}
if err != errUnreadable {
t.Fatalf("expected returned error to be '%v', but got '%v'", errUnreadable, err)
}
}
func TestProcessTranslatableInGDScript(t *testing.T) {
poFile, err := process(mockFileSystem{}, []string{
"single_translatable.gd",
})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
numTranslations := len(poFile.Translations)
if numTranslations != 1 {
t.Fatalf("expected process to find 1 translatable, but found %v (%v)", numTranslations, poFile)
}
if _, ok := poFile.Translations["Hello!"]; !ok {
t.Fatalf("expected process to find msgid `Hello!`, but found only %v", poFile.Translations)
}
}
func TestProcessTranslatableInTscn(t *testing.T) {
poFile, err := process(mockFileSystem{}, []string{
"single_translatable.tscn",
})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
numTranslations := len(poFile.Translations)
if numTranslations != 1 {
t.Fatalf("expected process to find 1 translatable, but found %v (%v)", numTranslations, poFile)
}
if _, ok := poFile.Translations["Start game"]; !ok {
t.Fatalf("expected process to find msgid `Start game`, but found only %v", poFile.Translations)
}
}
func TestProcessSkipEmptyMsgId(t *testing.T) {
poFile, err := process(mockFileSystem{}, []string{
"empty_msgid.gd",
})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
numTranslations := len(poFile.Translations)
if numTranslations > 0 {
t.Fatalf("expected process to skip all empty msgids resulting in no translations, but found %v (%v)", numTranslations, poFile)
}
}
func TestProcessDuplicateMsgIds(t *testing.T) {
poFile, err := process(mockFileSystem{}, []string{
"duplicate_msgids.gd",
})
if err != nil {
t.Fatalf("expected error to be nil, got '%v'", err)
}
numTranslations := len(poFile.Translations)
if numTranslations != 1 {
t.Fatalf("expected process to find 1 translatable, but found %v (%v)", numTranslations, poFile)
}
if _, ok := poFile.Translations["new game"]; !ok {
t.Fatalf("expected process to find msgid `new game`, but found only %v", poFile.Translations)
}
}