Utility code to find longest common prefix/suffix and to quote strings for various shells

This commit is contained in:
Kovid Goyal
2022-09-18 19:31:24 +05:30
parent 1ff4f2df4f
commit cbbda23e01
3 changed files with 126 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
package utils
import (
"fmt"
"testing"
)
var _ = fmt.Print
func TestLongestCommon(t *testing.T) {
p := func(expected string, items ...string) {
actual := Prefix(items)
if actual != expected {
t.Fatalf("Failed with %#v\nExpected: %#v\nActual: %#v", items, expected, actual)
}
}
p("abc", "abc", "abcd")
p("", "abc", "xy")
}