hledger/tests/query-tag.test

135 lines
2.4 KiB
Plaintext
Raw Normal View History

# 1. we parse metadata tags in transaction and posting comments. Currently,
# - they can be on the same line and/or separate lines
# - they are always printed on separate lines
hledger -f - print
<<<
2010/01/01 ; txntag1: txn val 1
; txntag2: txn val 2
2012-05-07 00:43:48 +04:00
a 1
; posting1tag1: posting 1 val 1
; posting1tag2:
b -1 ; posting-2-tag-1: posting 2 val 1
; posting-2-tag-2:
2012-05-07 00:43:48 +04:00
; non-metadata:
>>>
2010-01-01 ; txntag1: txn val 1
; txntag2: txn val 2
a 1
; posting1tag1: posting 1 val 1
; posting1tag2:
b -1 ; posting-2-tag-1: posting 2 val 1
; posting-2-tag-2:
>>>2
>>>=0
2012-04-09 00:43:48 +04:00
2012-05-28 04:27:55 +04:00
# 2. reports can filter by tag existence
hledger -f - print tag:foo
2012-05-28 04:27:55 +04:00
<<<
2010/01/01 ; foo:bar
2012-05-28 04:27:55 +04:00
a 1
b -1
2012-04-09 00:43:48 +04:00
2010/01/02 ; foo:baz
2012-05-28 04:27:55 +04:00
c 1
d -1
2010/01/03
e 1
f -1
>>>
2010-01-01 ; foo:bar
a 1
b -1
2012-05-28 04:27:55 +04:00
2010-01-02 ; foo:baz
c 1
d -1
2012-05-28 04:27:55 +04:00
>>>2
>>>=0
# 3. or tag value
hledger -f - print tag:foo=bar
2012-05-28 04:27:55 +04:00
<<<
2010/01/01 ; foo:bar
2012-05-28 04:27:55 +04:00
a 1
b -1
2012-05-07 00:43:48 +04:00
2012-05-28 04:27:55 +04:00
2010/01/02
; foo:baz
c 1
d -1
2012-04-09 00:43:48 +04:00
2012-05-28 04:27:55 +04:00
2010/01/03
e 1
f -1
>>>
2010-01-01 ; foo:bar
a 1
b -1
2012-05-07 00:43:48 +04:00
2012-05-28 04:27:55 +04:00
>>>2
>>>=0
2012-05-07 00:43:48 +04:00
2012-05-28 04:27:55 +04:00
# 4. postings inherit their transaction's tags
hledger -f - register tag:foo=bar
2012-05-28 04:27:55 +04:00
<<<
2010/01/01
a 1 ; foo:bar
2012-05-28 04:27:55 +04:00
b -1
2012-05-07 00:43:48 +04:00
2010/01/02 ; foo:baz
2012-05-28 04:27:55 +04:00
c 1
d -1
2012-05-07 00:43:48 +04:00
2010/01/03 ; foo:bar
2012-05-28 04:27:55 +04:00
e 1
f -1
>>>
2010-01-01 a 1 1
2010-01-03 e 1 2
f -1 1
2012-05-28 04:27:55 +04:00
>>>2
>>>=0
2012-05-07 00:43:48 +04:00
# 5. look for transactions without tags
hledger -f - print not:tag:.
<<<
2010/01/01 desc
a 1
b -1
2010/01/02
; foo:some tag
c 2
d -2
2010/01/03
e 3
f -3
2010/01/04 (code)
g 4
h -4
>>>
2010-01-01 desc
a 1
b -1
2010-01-03
e 3
f -3
2010-01-04 (code)
g 4
h -4
>>>=0
# 6. query is not affected by implicit tags
2019-07-27 08:51:15 +03:00
hledger -f ../examples/sample.journal reg tag:d
>>>
>>>2
>>>=0