-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
89 lines (78 loc) · 2.23 KB
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2020 by Chris Palmer (https://noncombatant.org)
// SPDX-License-Identifier: GPL-3.0
package main
import (
"testing"
)
type StringToStringExpectation struct {
Input string
Output string
}
func TestExtractDigits(t *testing.T) {
expectations := []StringToStringExpectation{
{"123409", "123409"},
{"Hello 123409", "123409"},
{"Hello 123409goat", "123409"},
{"123409goat", "123409"},
{"hello pumpkins?", ""},
{"ABCDEF", ""},
{"wow 3.14159", "3"},
}
for _, e := range expectations {
r := extractDigits(e.Input)
if e.Output != r {
t.Errorf("%q != ExtractDigits(%q) (%q)\n", e.Output, e.Input, r)
}
}
}
func TestGetBasenameExtension(t *testing.T) {
expectations := []StringToStringExpectation{
{"/usr/bin/goat.leg", ".leg"},
{"/usr/bin/goat.lEg", ".leg"},
{"/usr/bin/goat.BAT", ".bat"},
{"c:\\win32\\goatpad.EXE", ".exe"},
{"zip", ""},
{"~/bin/zip.sh", ".sh"},
{"zip.pdf.sh", ".sh"},
{"/usr/local/goat.beard/thing.stuff.txt", ".txt"},
{".hidden", ".hidden"},
{"~/whatever/.hidden", ".hidden"},
}
for _, e := range expectations {
r := getBasenameExtension(e.Input)
if e.Output != r {
t.Errorf("%q != GetBasenameExtension(%q) (%q)\n", e.Output, e.Input, r)
}
}
}
func TestRemoveBasenameExtension(t *testing.T) {
expectations := []StringToStringExpectation{
{"/usr/bin/goat.leg", "/usr/bin/goat"},
{"/usr/bin/goat.lEg", "/usr/bin/goat"},
{"/usr/BIN/goat.BAT", "/usr/BIN/goat"},
{"c:\\win32\\goatpad.EXE", "c:\\win32\\goatpad"},
{"zip", "zip"},
{"~/bin/zip.sh", "~/bin/zip"},
{"zip.pdf.sh", "zip.pdf"},
{"/usr/local/goat.beard/thing.stuff.txt", "/usr/local/goat.beard/thing.stuff"},
{"/usr/local/goat.beard/thing", "/usr/local/goat.beard/thing"},
}
for _, e := range expectations {
r := removeBasenameExtension(e.Input)
if e.Output != r {
t.Errorf("%q != RemoveBasenameExtension(%q) (%q)\n", e.Output, e.Input, r)
}
}
}
func TestEscapeDoubleQuotes(t *testing.T) {
expectations := []StringToStringExpectation{
{"\"Hello,\" they said. \"Blorp!\"",
"\\\"Hello,\\\" they said. \\\"Blorp!\\\""},
}
for _, e := range expectations {
r := escapeDoubleQuotes(e.Input)
if e.Output != r {
t.Errorf("%q != EscapeDoubleQuotes(%q) (%q)\n", e.Output, e.Input, r)
}
}
}