-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Truncate long title to not exceed fs length limits
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestFileNameTruncation(t *testing.T) { | ||
names := []string{ | ||
"我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我", // 255 x Chinese wo3 (我) | ||
"我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我", // 256 x Chinese wo3 (我) | ||
"我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我我", // 32 x Chinese wo3 (我) | ||
"short"} // should not get truncated | ||
|
||
for _, name := range names { | ||
shortened := truncateString(name, maxFileNameLength) | ||
if len(name) < maxFileNameLength { | ||
if name != shortened { | ||
t.Errorf("Filename should not be altered, but it was. Original was %s", name) | ||
} | ||
} else { | ||
if len(shortened) > maxFileNameLength { | ||
t.Errorf("Filename was too long - should have been truncated. Length was %d", len(name)) | ||
} | ||
} | ||
} | ||
} |