test info: check file name lengths using 1,2,3,4 byte unicode characters
This commit is contained in:
parent
e57fe14b61
commit
a6ca4b3817
1 changed files with 34 additions and 10 deletions
|
@ -91,7 +91,7 @@ type results struct {
|
|||
mu sync.Mutex
|
||||
stringNeedsEscaping map[string]internal.Position
|
||||
controlResults map[string]internal.ControlResult
|
||||
maxFileLength int
|
||||
maxFileLength [4]int
|
||||
canWriteUnnormalized bool
|
||||
canReadUnnormalized bool
|
||||
canReadRenormalized bool
|
||||
|
@ -125,7 +125,9 @@ func (r *results) Print() {
|
|||
fmt.Printf("}\n")
|
||||
}
|
||||
if checkLength {
|
||||
fmt.Printf("maxFileLength = %d\n", r.maxFileLength)
|
||||
for i := range r.maxFileLength {
|
||||
fmt.Printf("maxFileLength = %d // for %d byte unicode characters\n", r.maxFileLength[i], i+1)
|
||||
}
|
||||
}
|
||||
if checkNormalization {
|
||||
fmt.Printf("canWriteUnnormalized = %v\n", r.canWriteUnnormalized)
|
||||
|
@ -150,7 +152,7 @@ func (r *results) WriteJSON() {
|
|||
report.ControlCharacters = &r.controlResults
|
||||
}
|
||||
if checkLength {
|
||||
report.MaxFileLength = &r.maxFileLength
|
||||
report.MaxFileLength = &r.maxFileLength[0]
|
||||
}
|
||||
if checkNormalization {
|
||||
report.CanWriteUnnormalized = &r.canWriteUnnormalized
|
||||
|
@ -366,11 +368,27 @@ func (r *results) checkControlsList() {
|
|||
}
|
||||
|
||||
// find the max file name size we can use
|
||||
func (r *results) findMaxLength() {
|
||||
func (r *results) findMaxLength(characterLength int) {
|
||||
var character rune
|
||||
switch characterLength {
|
||||
case 1:
|
||||
character = 'a'
|
||||
case 2:
|
||||
character = 'á'
|
||||
case 3:
|
||||
character = '世'
|
||||
case 4:
|
||||
character = '🙂'
|
||||
default:
|
||||
panic("Bad characterLength")
|
||||
}
|
||||
if characterLength != len(string(character)) {
|
||||
panic(fmt.Sprintf("Chose the wrong character length %q is %d not %d", character, len(string(character)), characterLength))
|
||||
}
|
||||
const maxLen = 16 * 1024
|
||||
name := make([]byte, maxLen)
|
||||
name := make([]rune, maxLen)
|
||||
for i := range name {
|
||||
name[i] = 'a'
|
||||
name[i] = character
|
||||
}
|
||||
// Find the first size of filename we can't write
|
||||
i := sort.Search(len(name), func(i int) (fail bool) {
|
||||
|
@ -382,16 +400,20 @@ func (r *results) findMaxLength() {
|
|||
}()
|
||||
|
||||
path := string(name[:i])
|
||||
_, err := r.writeFile(path)
|
||||
o, err := r.writeFile(path)
|
||||
if err != nil {
|
||||
fs.Infof(r.f, "Couldn't write file with name length %d: %v", i, err)
|
||||
return true
|
||||
}
|
||||
fs.Infof(r.f, "Wrote file with name length %d", i)
|
||||
err = o.Remove(context.Background())
|
||||
if err != nil {
|
||||
fs.Errorf(o, "Failed to remove test file")
|
||||
}
|
||||
return false
|
||||
})
|
||||
r.maxFileLength = i - 1
|
||||
fs.Infof(r.f, "Max file length is %d", r.maxFileLength)
|
||||
r.maxFileLength[characterLength-1] = i - 1
|
||||
fs.Infof(r.f, "Max file length is %d when writing %d byte characters %q", r.maxFileLength[characterLength-1], characterLength, character)
|
||||
}
|
||||
|
||||
func (r *results) checkStreaming() {
|
||||
|
@ -447,7 +469,9 @@ func readInfo(ctx context.Context, f fs.Fs) error {
|
|||
r.checkControls()
|
||||
}
|
||||
if checkLength {
|
||||
r.findMaxLength()
|
||||
for i := range r.maxFileLength {
|
||||
r.findMaxLength(i + 1)
|
||||
}
|
||||
}
|
||||
if checkNormalization {
|
||||
r.checkUTF8Normalization()
|
||||
|
|
Loading…
Reference in a new issue