|
| 1 | +package zapx |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestSlowlogEncoder_LongestCommonPrefOffset(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + name string |
| 10 | + input []string |
| 11 | + expected int |
| 12 | + }{ |
| 13 | + { |
| 14 | + name: "empty slice", |
| 15 | + input: []string{}, |
| 16 | + expected: 0, |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "single string", |
| 20 | + input: []string{"test"}, |
| 21 | + expected: 4, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "no common prefix", |
| 25 | + input: []string{"abc", "def", "ghi"}, |
| 26 | + expected: 0, |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "partial common prefix", |
| 30 | + input: []string{"prefix123", "prefix456", "prefix789"}, |
| 31 | + expected: 6, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "full common string", |
| 35 | + input: []string{"same", "same", "same"}, |
| 36 | + expected: 4, |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "mixed length strings with common prefix", |
| 40 | + input: []string{"test123", "test", "test4567"}, |
| 41 | + expected: 4, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "strings with spaces", |
| 45 | + input: []string{"common prefix 1", "common prefix 2", "common prefix 3"}, |
| 46 | + expected: 14, |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + sle := &SlowlogEncoder{} |
| 51 | + for _, tt := range tests { |
| 52 | + t.Run(tt.name, func(t *testing.T) { |
| 53 | + result := sle.longestCommonPrefOffset(tt.input) |
| 54 | + if result != tt.expected { |
| 55 | + t.Errorf("longestCommonPrefOffset() = %v, want %v", result, tt.expected) |
| 56 | + } |
| 57 | + }) |
| 58 | + } |
| 59 | +} |
0 commit comments