From e78e73eae7e49acba0b183c357cc00afff60dcf5 Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Thu, 28 Oct 2021 19:26:46 +0300 Subject: [PATCH] lib/encoder: fix benchmarks Some day in the past the Slash encode option was added to Onedrive encoder so it began to encode slashes in file names rather then treat them as path separators. This patch adapts benchmark test cases accordingly. Fixes #5659 --- lib/encoder/encoder_test.go | 103 ++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/lib/encoder/encoder_test.go b/lib/encoder/encoder_test.go index df70b6f33..61f4b73ef 100644 --- a/lib/encoder/encoder_test.go +++ b/lib/encoder/encoder_test.go @@ -266,54 +266,111 @@ const oneDrive = (Standard | EncodeRightPeriod) var benchTests = []struct { - in string - out string + in string + outOld string + outNew string }{ - {"", ""}, - {"abc 123", "abc 123"}, - {`\*<>?:|#%".~`, `\*<>?:|#%".~`}, - {`\*<>?:|#%".~/\*<>?:|#%".~`, `\*<>?:|#%".~/\*<>?:|#%".~`}, - {" leading space", " leading space"}, - {"~leading tilde", "~leading tilde"}, - {"trailing dot.", "trailing dot."}, - {" leading space/ leading space/ leading space", " leading space/ leading space/ leading space"}, - {"~leading tilde/~leading tilde/~leading tilde", "~leading tilde/~leading tilde/~leading tilde"}, - {"leading tilde/~leading tilde", "leading tilde/~leading tilde"}, - {"trailing dot./trailing dot./trailing dot.", "trailing dot./trailing dot./trailing dot."}, + { + "", + "", + "", + }, + { + "abc 123", + "abc 123", + "abc 123", + }, + { + `\*<>?:|#%".~`, + `\*<>?:|#%".~`, + `\*<>?:|#%".~`, + }, + { + `\*<>?:|#%".~/\*<>?:|#%".~`, + `\*<>?:|#%".~/\*<>?:|#%".~`, + `\*<>?:|#%".~/\*<>?:|#%".~`, + }, + { + " leading space", + " leading space", + " leading space", + }, + { + "~leading tilde", + "~leading tilde", + "~leading tilde", + }, + { + "trailing dot.", + "trailing dot.", + "trailing dot.", + }, + { + " leading space/ leading space/ leading space", + " leading space/ leading space/ leading space", + " leading space/ leading space/ leading space", + }, + { + "~leading tilde/~leading tilde/~leading tilde", + "~leading tilde/~leading tilde/~leading tilde", + "~leading tilde/~leading tilde/~leading tilde", + }, + { + "leading tilde/~leading tilde", + "leading tilde/~leading tilde", + "leading tilde/~leading tilde", + }, + { + "trailing dot./trailing dot./trailing dot.", + "trailing dot./trailing dot./trailing dot.", + "trailing dot./trailing dot./trailing dot.", + }, } -func benchReplace(b *testing.B, f func(string) string) { +func benchReplace(b *testing.B, f func(string) string, old bool) { for range make([]struct{}, b.N) { for _, test := range benchTests { got := f(test.in) - if got != test.out { - b.Errorf("Encode(%q) want %q got %q", test.in, test.out, got) + out := test.outNew + if old { + out = test.outOld + } + if got != out { + b.Errorf("Encode(%q) want %q got %q", test.in, out, got) } } } } -func benchRestore(b *testing.B, f func(string) string) { +func benchRestore(b *testing.B, f func(string) string, old bool) { for range make([]struct{}, b.N) { for _, test := range benchTests { - got := f(test.out) + out := test.outNew + if old { + out = test.outOld + } + got := f(out) if got != test.in { - b.Errorf("Decode(%q) want %q got %q", got, test.in, got) + b.Errorf("Decode(%q) want %q got %q", out, test.in, got) } } } } + func BenchmarkOneDriveReplaceNew(b *testing.B) { - benchReplace(b, oneDrive.Encode) + benchReplace(b, oneDrive.Encode, false) } + func BenchmarkOneDriveReplaceOld(b *testing.B) { - benchReplace(b, replaceReservedChars) + benchReplace(b, replaceReservedChars, true) } + func BenchmarkOneDriveRestoreNew(b *testing.B) { - benchRestore(b, oneDrive.Decode) + benchRestore(b, oneDrive.Decode, false) } + func BenchmarkOneDriveRestoreOld(b *testing.B) { - benchRestore(b, restoreReservedChars) + benchRestore(b, restoreReservedChars, true) } var (