Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobetic committed Nov 25, 2023
1 parent c48028b commit 17654b4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/coin/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (cmd *cmdFormat) init() {
}

func (cmd *cmdFormat) execute(f io.Writer) {
if len(cmd.Args()) == 0 {
if len(cmd.Args()) == 0 { // for testing
cmd.writeTransactions(f)
return
}
Expand Down
11 changes: 9 additions & 2 deletions cmd/coin/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func (cmd *cmdModify) init() {
coin.ResolveAccounts()
}

func (cmd *cmdModify) execute(_ io.Writer) {
check.If(cmd.NArg() > 1, "both from and to account must be specified")
func (cmd *cmdModify) execute(f io.Writer) {
if len(cmd.fAccount) > 0 {
cmd.from = coin.MustFindAccount(cmd.fAccount)
}
Expand All @@ -56,6 +55,14 @@ func (cmd *cmdModify) execute(_ io.Writer) {
if len(cmd.fPayee) > 0 {
cmd.payee = regexp.MustCompile(cmd.fPayee)
}
if cmd.NArg() == 0 { // for testing
for _, t := range coin.Transactions {
cmd.modify(t)
t.Write(f, false)
fmt.Fprintln(f)
}
return
}
for _, fn := range cmd.Args() {
coin.LoadFile(fn)
coin.ResolveTransactions(false)
Expand Down
26 changes: 26 additions & 0 deletions tests/cmd/mod/move.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
commodity CAD
format 1.00 CAD

account Assets:Bank
account Income:Salary
account Expenses:Food
account Expenses:Rent

2000 ACME
Bank 1000 CAD
Salary

2000/02 Loeb
Expenses
Bank -20 CAD

test modify -a Expenses -a: Food
2000/01/01 ACME
Assets:Bank 1000.00 CAD
Income:Salary -1000.00 CAD

2000/02/01 Loeb
Expenses:Food 20.00 CAD
Assets:Bank -20.00 CAD

end test
33 changes: 33 additions & 0 deletions tests/cmd/mod/payee.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
commodity CAD
format 1.00 CAD

account Assets:Bank
account Income:Salary
account Expenses:Food

2000 ACME
Bank 1000 CAD
Salary

2000/02 Loeb
Expenses
Bank -20 CAD

2000/03/03 Rent
Expenses 500 CAD
Bank

test modify -a Expenses -p Loeb -a: Food
2000/01/01 ACME
Assets:Bank 1000.00 CAD
Income:Salary -1000.00 CAD

2000/02/01 Loeb
Expenses:Food 20.00 CAD
Assets:Bank -20.00 CAD

2000/03/03 Rent
Expenses 500.00 CAD
Assets:Bank -500.00 CAD

end test

0 comments on commit 17654b4

Please sign in to comment.