diff options
author | uzhas <uzhas@ydb.tech> | 2023-08-24 17:35:21 +0300 |
---|---|---|
committer | uzhas <uzhas@ydb.tech> | 2023-08-24 17:53:39 +0300 |
commit | de6e39881d059d67cbcc978d076d9e3e5e9732fc (patch) | |
tree | cdf4e77c0156fe7f192d644883954f302fc56c01 /library/go/test | |
parent | b890c9f4f00efbc099a862b70c1dbc4c7db3dd2f (diff) | |
download | ydb-de6e39881d059d67cbcc978d076d9e3e5e9732fc.tar.gz |
move yql connector to ydb
move code
Diffstat (limited to 'library/go/test')
-rw-r--r-- | library/go/test/testhelpers/recurse.go | 12 | ||||
-rw-r--r-- | library/go/test/testhelpers/remove_lines.go | 47 | ||||
-rw-r--r-- | library/go/test/testhelpers/ya.make | 12 |
3 files changed, 71 insertions, 0 deletions
diff --git a/library/go/test/testhelpers/recurse.go b/library/go/test/testhelpers/recurse.go new file mode 100644 index 0000000000..1239d39e01 --- /dev/null +++ b/library/go/test/testhelpers/recurse.go @@ -0,0 +1,12 @@ +package testhelpers + +// Recurse calls itself 'depth' times then executes 'f'. Useful for testing things where stack size matters. +func Recurse(depth int, f func()) { + if depth > 0 { + depth-- + Recurse(depth, f) + return + } + + f() +} diff --git a/library/go/test/testhelpers/remove_lines.go b/library/go/test/testhelpers/remove_lines.go new file mode 100644 index 0000000000..214a2627a8 --- /dev/null +++ b/library/go/test/testhelpers/remove_lines.go @@ -0,0 +1,47 @@ +package testhelpers + +import ( + "fmt" + "sort" + "strings" +) + +func RemoveLines(str string, lines ...int) (string, error) { + if len(lines) == 0 { + return str, nil + } + + sort.Ints(lines) + + var b strings.Builder + b.Grow(len(str)) + + var count int + var start int + var lineID int + for i, s := range str { + if s != '\n' { + continue + } + + if lines[lineID] != count { + b.WriteString(str[start:i]) + b.WriteString("\n") + } else { + lineID++ + if len(lines) <= lineID { + b.WriteString(str[i+1:]) + break + } + } + + count++ + start = i + 1 + } + + if len(lines) > lineID { + return str, fmt.Errorf("not all lines were removed: processed line ids before %d for lines %d", lineID, lines) + } + + return b.String(), nil +} diff --git a/library/go/test/testhelpers/ya.make b/library/go/test/testhelpers/ya.make new file mode 100644 index 0000000000..267b73b0dc --- /dev/null +++ b/library/go/test/testhelpers/ya.make @@ -0,0 +1,12 @@ +GO_LIBRARY() + +SRCS( + recurse.go + remove_lines.go +) + +GO_TEST_SRCS(remove_lines_test.go) + +END() + +RECURSE(gotest) |