MCPcopy
hub / github.com/syncthing/syncthing / TestNormalization

Function TestNormalization

lib/scanner/walk_test.go:207–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func TestNormalization(t *testing.T) {
208 if build.IsDarwin {
209 t.Skip("Normalization test not possible on darwin")
210 return
211 }
212
213 testFs := newTestFs()
214
215 tests := []string{
216 "0-A", // ASCII A -- accepted
217 "1-\xC3\x84", // NFC 'Ä' -- conflicts with the entry below, accepted
218 "1-\x41\xCC\x88", // NFD 'Ä' -- conflicts with the entry above, ignored
219 "2-\xC3\x85", // NFC 'Å' -- accepted
220 "3-\x41\xCC\x83", // NFD 'Ã' -- converted to NFC
221 "4-\xE2\x98\x95", // U+2615 HOT BEVERAGE (☕) -- accepted
222 "5-\xCD\xE2", // EUC-CN "wài" (外) -- ignored (not UTF8)
223 }
224 numInvalid := 2
225
226 numValid := len(tests) - numInvalid
227
228 for _, s1 := range tests {
229 // Create a directory for each of the interesting strings above
230 if err := testFs.MkdirAll(filepath.Join("normalization", s1), 0o755); err != nil {
231 t.Fatal(err)
232 }
233
234 for _, s2 := range tests {
235 // Within each dir, create a file with each of the interesting
236 // file names. Ensure that the file doesn't exist when it's
237 // created. This detects and fails if there's file name
238 // normalization stuff at the filesystem level.
239 if fd, err := testFs.OpenFile(filepath.Join("normalization", s1, s2), os.O_CREATE|os.O_EXCL, 0o644); err != nil {
240 t.Fatal(err)
241 } else {
242 if _, err := fd.Write([]byte("test")); err != nil {
243 t.Fatal(err)
244 }
245 if err := fd.Close(); err != nil {
246 t.Fatal(err)
247 }
248 }
249 }
250 }
251
252 // We can normalize a directory name, but we can't descend into it in the
253 // same pass due to how filepath.Walk works. So we run the scan twice to
254 // make sure it all gets done. In production, things will be correct
255 // eventually...
256
257 walkDir(testFs, "normalization", nil, nil, 0)
258 tmp := walkDir(testFs, "normalization", nil, nil, 0)
259
260 files := fileList(tmp).testfiles()
261
262 // We should have one file per combination, plus the directories
263 // themselves, plus the "testdata/normalization" directory
264

Callers

nothing calls this directly

Calls 9

newTestFsFunction · 0.85
walkDirFunction · 0.85
fileListTypeAlias · 0.85
FatalMethod · 0.80
testfilesMethod · 0.80
MkdirAllMethod · 0.65
OpenFileMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected