-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: bring in strings.Cut to build on go1.17
- Loading branch information
Showing
6 changed files
with
47 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//go:build go1.18 | ||
|
||
package ledger | ||
|
||
import ( | ||
"bytes" | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
func FuzzParseLedger(f *testing.F) { | ||
for _, tc := range testCases { | ||
if tc.err == nil { | ||
f.Add(tc.data) | ||
} | ||
} | ||
f.Fuzz(func(t *testing.T, s string) { | ||
b := bytes.NewBufferString(s) | ||
trans, _ := ParseLedger(b) | ||
overall := new(big.Rat) | ||
for _, t := range trans { | ||
for _, p := range t.AccountChanges { | ||
overall.Add(overall, p.Balance) | ||
} | ||
} | ||
if overall.Cmp(new(big.Rat)) != 0 { | ||
t.Error("Bad balance") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ledger | ||
|
||
import "strings" | ||
|
||
// Cut slices s around the first instance of sep, | ||
// returning the text before and after sep. | ||
// The found result reports whether sep appears in s. | ||
// If sep does not appear in s, cut returns s, "", false. | ||
func stringsCut(s, sep string) (before, after string, found bool) { | ||
if i := strings.Index(s, sep); i >= 0 { | ||
return s[:i], s[i+len(sep):], true | ||
} | ||
return s, "", false | ||
} |