aboutsummaryrefslogtreecommitdiff
path: root/chksum
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-16 22:48:24 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-16 22:48:24 +0200
commit2fc8e0aeed3b36b20864a9eeba2bf08c806dcd5c (patch)
tree8939d90ca2cda9bc46e3f2f0826a09a3d7e31865 /chksum
parentf85e0d461fe80fe929eb5d82d9fec07eff810a93 (diff)
bikeshadding
Diffstat (limited to 'chksum')
-rw-r--r--chksum/chksum.go11
-rw-r--r--chksum/chksum_test.go2
-rw-r--r--chksum/testdata/mixed (renamed from chksum/testdata/SUM)0
3 files changed, 7 insertions, 6 deletions
diff --git a/chksum/chksum.go b/chksum/chksum.go
index 2eefb52..847ae22 100644
--- a/chksum/chksum.go
+++ b/chksum/chksum.go
@@ -57,12 +57,13 @@ func Parse(data []byte) (Checklist, error) {
return parse(r)
}
+var line = regexp.MustCompile(`(\w+) \(([^)]+)\) = (\w+)`)
+
func parse(r io.Reader) (Checklist, error) {
var checklist Checklist
- re := regexp.MustCompile(`(\w+) \(([^)]+)\) = (\w+)`)
- scanner := bufio.NewScanner(r)
- for scanner.Scan() {
- match := re.FindStringSubmatch(scanner.Text())
+ s := bufio.NewScanner(r)
+ for s.Scan() {
+ match := line.FindStringSubmatch(s.Text())
if len(match) != 4 {
return nil, ErrParse
}
@@ -81,7 +82,7 @@ func parse(r io.Reader) (Checklist, error) {
}
checklist = append(checklist, cs)
}
- return checklist, scanner.Err()
+ return checklist, s.Err()
}
func (c Checksum) Check() error {
diff --git a/chksum/chksum_test.go b/chksum/chksum_test.go
index 3155d23..60a547e 100644
--- a/chksum/chksum_test.go
+++ b/chksum/chksum_test.go
@@ -10,7 +10,7 @@ func TestParseFile(t *testing.T) {
{"testdata/SHA1"},
{"testdata/SHA256"},
{"testdata/SHA512"},
- {"testdata/SUM"},
+ {"testdata/mixed"},
}
for _, tc := range testCases {
t.Run(tc.file, func(t *testing.T) {
diff --git a/chksum/testdata/SUM b/chksum/testdata/mixed
index a5e4ffc..a5e4ffc 100644
--- a/chksum/testdata/SUM
+++ b/chksum/testdata/mixed