test gorup
This commit is contained in:
21
ledger/group.go
Normal file
21
ledger/group.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package ledger
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
type Group func(Delta) Delta
|
||||||
|
|
||||||
|
func GroupDate(pattern string) Group {
|
||||||
|
p := regexp.MustCompile(pattern)
|
||||||
|
return func(d Delta) Delta {
|
||||||
|
d.Date = p.FindString(d.Date)
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GroupName(pattern string) Group {
|
||||||
|
p := regexp.MustCompile(pattern)
|
||||||
|
return func(d Delta) Delta {
|
||||||
|
d.Name = p.FindString(d.Name)
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
13
ledger/group_test.go
Normal file
13
ledger/group_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package ledger
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestGroup(t *testing.T) {
|
||||||
|
if got := GroupDate("^20..")(Delta{Date: "2021-01"}); got.Date != "2021" {
|
||||||
|
t.Error(got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := GroupName("^[^:]*")(Delta{Name: "a:b:c"}); got.Name != "a" {
|
||||||
|
t.Error(got)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user