2010-11-16 18:59:12 +03:00
|
|
|
##############################################################################
|
|
|
|
# data validation
|
|
|
|
#
|
2011-01-19 15:32:18 +03:00
|
|
|
# 1. should prompt again for a bad date
|
2012-10-21 22:23:23 +04:00
|
|
|
hledgerdev -f $$-add.j add; rm -f $$-add.j
|
2010-11-16 18:59:12 +03:00
|
|
|
<<<
|
|
|
|
2009/1/32
|
2013-02-23 04:57:16 +04:00
|
|
|
>>> /date .*: date .*/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 2. should accept a blank date
|
2012-10-21 22:23:23 +04:00
|
|
|
hledgerdev -f $$-add.j add; rm -f $$-add.j
|
2010-11-16 18:59:12 +03:00
|
|
|
<<<
|
|
|
|
|
2013-02-23 04:57:16 +04:00
|
|
|
>>> /date .*: description /
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2010-11-16 18:59:12 +03:00
|
|
|
##############################################################################
|
|
|
|
# precision and commodity handling
|
|
|
|
#
|
2011-01-19 15:32:18 +03:00
|
|
|
# 3. simple add with no existing journal, no commodity entered
|
2012-10-21 22:23:23 +04:00
|
|
|
hledgerdev -f $$-add.j add; rm -f $$-add.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
1000.0
|
|
|
|
b
|
|
|
|
|
|
|
|
.
|
2013-04-13 01:57:39 +04:00
|
|
|
>>> /^date.*: description.*: account 1.*: amount 1.*: account 2.*: amount 2.*: account 3.*or \. to complete.*: Accept.*: $/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 4. default commodity with greater precision
|
2012-10-21 22:23:23 +04:00
|
|
|
printf 'D $1000.00\n' >t$$.j; hledgerdev -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
$1000.0
|
|
|
|
b
|
|
|
|
|
|
|
|
.
|
2013-04-13 01:57:39 +04:00
|
|
|
|
2010-11-16 18:08:06 +03:00
|
|
|
>>> /a +\$1000\.0/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 5. default commodity with less precision
|
2012-10-21 22:23:23 +04:00
|
|
|
printf 'D $1000.0\n' >t$$.j; hledgerdev -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
$1000.00
|
|
|
|
b
|
|
|
|
|
|
|
|
.
|
2013-04-13 01:57:39 +04:00
|
|
|
|
2010-11-16 18:08:06 +03:00
|
|
|
>>> /a +\$1000\.00/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 6. existing commodity with greater precision
|
2012-10-21 22:23:23 +04:00
|
|
|
printf '2010/1/1\n a $1000.00\n b\n' >t$$.j; hledgerdev -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
$1000.0
|
|
|
|
b
|
|
|
|
|
|
|
|
.
|
|
|
|
>>> /a +\$1000\.0/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 7. existing commodity with less precision
|
2012-10-21 22:23:23 +04:00
|
|
|
printf '2010/1/1\n a $1000.0\n b\n' >t$$.j; hledgerdev -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
$1000.00
|
|
|
|
b
|
|
|
|
|
|
|
|
.
|
2013-04-13 01:57:39 +04:00
|
|
|
|
2010-11-16 18:08:06 +03:00
|
|
|
>>> /a +\$1000\.00/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 8. no commodity entered, the (most recent) default commodity should be applied
|
2012-03-28 22:17:05 +04:00
|
|
|
# (and a non-ascii commodity symbol should work)
|
2012-10-21 22:23:23 +04:00
|
|
|
printf 'D $1000.0\nD £1,000.00\n' >t$$.j; hledgerdev -f t$$.j add; cat t$$.j; rm -f t$$.j
|
2010-11-16 18:08:06 +03:00
|
|
|
<<<
|
|
|
|
2010/1/1
|
2010-11-13 18:11:45 +03:00
|
|
|
|
2010-11-16 18:08:06 +03:00
|
|
|
a
|
|
|
|
1000
|
|
|
|
b
|
2010-11-13 18:11:45 +03:00
|
|
|
|
2010-11-16 18:08:06 +03:00
|
|
|
.
|
2013-04-13 01:57:39 +04:00
|
|
|
|
2011-01-20 03:17:32 +03:00
|
|
|
>>> /a +£1,000.00/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
|
|
|
|
2011-01-19 15:32:18 +03:00
|
|
|
# 9. default amounts should not fail to balance due to precision
|
2012-10-21 22:23:23 +04:00
|
|
|
rm -f nosuch.journal; hledgerdev -f nosuch.journal add; rm -f nosuch.journal
|
2010-11-16 18:59:12 +03:00
|
|
|
<<<
|
|
|
|
2010/1/1
|
|
|
|
x
|
|
|
|
a
|
|
|
|
0.25
|
|
|
|
b
|
|
|
|
0.5
|
|
|
|
c
|
2013-02-23 04:57:16 +04:00
|
|
|
>>> /amount 3 \? \[-0.75\]/
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
2012-01-30 21:18:46 +04:00
|
|
|
|
|
|
|
## 10. shouldn't add decimals if there aren't any
|
2012-10-21 22:23:23 +04:00
|
|
|
## printf '\n\na\n1\nb\n' | hledgerdev -f /dev/null add
|
|
|
|
# hledgerdev -f /dev/null add
|
2012-01-30 21:18:46 +04:00
|
|
|
# <<<
|
|
|
|
|
|
|
|
|
|
|
|
# a
|
|
|
|
# 1
|
|
|
|
# b
|
|
|
|
# >>> /amount 2 \[-1\]/
|
|
|
|
# >>>=0
|
|
|
|
|