summaryrefslogtreecommitdiff
path: root/utilities/utilities.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2024-01-03 19:11:10 -0500
committerWill Hawkins <[email protected]>2024-01-04 19:17:06 -0500
commit218f2e6d235c4e947a04a39e4e09acde7675de6a (patch)
tree4642b7deed792e8345ccef86d549c8748a9e0ce8 /utilities/utilities.go
parentf3990f950277c2f61e0e1811b4b8a81fc0219da4 (diff)
[Feature] Reformat test result output.
Diffstat (limited to 'utilities/utilities.go')
-rw-r--r--utilities/utilities.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go
index b976f77..a1ec805 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -220,3 +220,18 @@ type Pair[T1, T2 any] struct {
func PerSecondToInterval(rate int64) time.Duration {
return time.Duration(time.Second.Nanoseconds() / rate)
}
+
+func IndentOutput(output string, depth uint, character string) string {
+ finalNewline := false
+ if strings.LastIndex(output, "\n") == len(output)-1 {
+ finalNewline = true
+ output = strings.TrimSuffix(output, "\n")
+ }
+ indentedOutput := strings.Join(Fmap[string](strings.SplitAfter(output, "\n"), func(line string) string {
+ return strings.Repeat(character, int(depth)) + line
+ }), "")
+ if finalNewline {
+ indentedOutput += "\n"
+ }
+ return indentedOutput
+}