Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation and completion improvements #15

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ed0099e
Fix indentation of directives not preceeded by empty line
alexsmith1612 May 10, 2021
7017a94
Indent posting metadata lines an additional level
alexsmith1612 May 10, 2021
fdfa9c2
Align numbers in balance and price directives in addition to postings
alexsmith1612 May 10, 2021
b4f14e4
Align open directive currencies to number alignment + 1
alexsmith1612 May 10, 2021
80a3e8b
Add customizable variable for minimum number alignment separation
alexsmith1612 May 10, 2021
01c5a74
Add customizable variable to enable number alignment with tab-dwim
alexsmith1612 May 10, 2021
013e57a
Add more generic beancount-indent-directive function
alexsmith1612 May 10, 2021
90c54d4
Always call indent-region on TAB if the region is active
alexsmith1612 May 10, 2021
aff0255
Update indentation tests
alexsmith1612 May 10, 2021
c232302
Fix link-at-point-003 unit test
alexsmith1612 May 10, 2021
ee36fcc
Explicitly require imenu in beancount.el
alexsmith1612 May 10, 2021
2489f46
Require org for org-level-x faces
alexsmith1612 May 10, 2021
6df3934
Don't insert space after completions
alexsmith1612 May 10, 2021
7d07c48
Limit non-timestamped directives completions
alexsmith1612 May 10, 2021
2518f70
Allow completion of tags and links not on their own line
alexsmith1612 May 10, 2021
c9725e3
Move posting completions after tag and link completions
alexsmith1612 May 10, 2021
c880cf6
Don't attempt completion inside strings except for options
alexsmith1612 May 10, 2021
4102a12
Don't collect matches inside strings
alexsmith1612 May 10, 2021
a721f15
Add more completion tests
alexsmith1612 May 10, 2021
cc8ea35
Update copyright and author information
alexsmith1612 May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 107 additions & 5 deletions beancount-tests.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; beancount-test.el --- ERT for beancount-mode -*- lexical-binding: t -*-

;; Copyright 2019 Daniele Nicolodi <[email protected]>
;; Copyright 2019 Alex Smith <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2019?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, that was a case of "thinking one thing but typing what I'm looking at". Will fix.


;; This file is not part of GNU Emacs.

Expand Down Expand Up @@ -133,21 +134,71 @@ Return a list of substrings each followed by its face."
:tags '(indent regress)
Copy link
Collaborator

@dnicolodi dnicolodi May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the tests in the same commit that extends the functionality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will change.

(with-temp-buffer
(insert "
2019-01-01 * \"Example\"
2019-01-01 * \"Example\"
transaction: metadata
#foo
^bar
also_transaction: metadata
Expenses:Example 1.00 USD
Assets:Checking 1.00 USD
posting: metadata
also_posting: metadata
Assets:Checking -1.00 USD
second_posting: metadata
")
(beancount-mode)
(forward-line -1)
(beancount-indent-transaction)
(beancount-indent-directive)
(should (equal (buffer-string) "
2019-01-01 * \"Example\"
transaction: metadata
#foo
^bar
also_transaction: metadata
Expenses:Example 1.00 USD
Assets:Checking 1.00 USD
posting: metadata
also_posting: metadata
Assets:Checking -1.00 USD
second_posting: metadata
"))))

(ert-deftest beancount/indent-002 ()
:tags '(indent regress)
(with-temp-buffer
(insert "
2019-01-01 open Assets:Checking USD

2019-01-01 * \"Example\"
transaction: metadata
#foo
^bar
also_transaction: metadata
Expenses:Example 1.00 USD
posting: metadata
also_posting: metadata
Assets:Checking -1.00 USD
second_posting: metadata
2019-01-02 balance Assets:Checking -1.00 USD

2019-01-03 price FOOBAR 123.456 USD
")
(beancount-mode)
(indent-region (point-min) (point-max))
(should (equal (buffer-string) "
2019-01-01 open Assets:Checking USD

2019-01-01 * \"Example\"
transaction: metadata
#foo
^bar
also_transaction: metadata
Expenses:Example 1.00 USD
posting: metadata
also_posting: metadata
Assets:Checking -1.00 USD
second_posting: metadata
2019-01-02 balance Assets:Checking -1.00 USD

2019-01-03 price FOOBAR 123.456 USD
"))))

(ert-deftest beancount/options-001 ()
Expand Down Expand Up @@ -188,6 +239,57 @@ known option nmaes."
"))
(should (equal beancount-accounts '("Assets:Checking" "Expenses:Test")))))

(ert-deftest beancount-completion-002 ()
:tags '(completion regress)
(with-temp-buffer
(insert "
2019-01-01 ope Assets:Checking
")
(beancount-mode)
(search-backward "p")
(completion-at-point)
(should (equal (buffer-string) "
2019-01-01 open Assets:Checking
"))))

(ert-deftest beancount-completion-003 ()
:tags '(completion regress)
(with-temp-buffer
(insert "
option \"operating_ \"USD\"
")
(beancount-mode)
(search-backward "p")
(completion-at-point)
(should (equal (buffer-string) "
option \"operating_currency\" \"USD\"
"))))

(ert-deftest beancount-completion-004 ()
:tags '(completion regress)
(with-temp-buffer
(insert "
2019-01-01 * \"Example ^foo-something-link-like-in-string\" ^foo-link/_.etc ^bar-link #foo-tag.more_/cruft #bar-tag
Expenses:Test 1.00 USD
Assets:Checking

2019-01-01 * \"Example\" ^f #b
")
(beancount-mode)
(goto-char (point-max))
(search-backward "^f")
(completion-at-point)
(goto-char (point-max))
(search-backward "#b")
(completion-at-point)
(should (equal (buffer-string) "
2019-01-01 * \"Example ^foo-something-link-like-in-string\" ^foo-link/_.etc ^bar-link #foo-tag.more_/cruft #bar-tag
Expenses:Test 1.00 USD
Assets:Checking

2019-01-01 * \"Example\" ^foo-link/_.etc #bar-tag
"))))

(ert-deftest beancount/outline-001 ()
:tags '(outline)
(with-temp-buffer
Expand Down Expand Up @@ -322,5 +424,5 @@ known option nmaes."
:tags '(regress thing-at-point)
(with-temp-buffer
(insert "foo ^link baz")
(goto-char 15)
(goto-char 5)
(should (equal (thing-at-point 'beancount-link) "^link"))))
Loading