summaryrefslogtreecommitdiff
path: root/test/complete-test.el
blob: d5082ce3b431ceac071380f101836a7921f4f2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
;;; complete-test.el --- ERT for ledger-mode  -*- lexical-binding: t; -*-

;; Copyright (C) 2003-2017 John Wiegley <johnw AT gnu DOT org>

;; Author: Thierry <thdox AT free DOT fr>
;; Keywords: languages
;; Homepage: https://github.com/ledger/ledger-mode

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free Software
;; Foundation; either version 2 of the License, or (at your option) any later
;; version.
;;
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
;; details.
;;
;; You should have received a copy of the GNU General Public License along with
;; this program; if not, write to the Free Software Foundation, Inc., 51
;; Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

;;; Commentary:
;;  Regression tests for ledger-complete

;;; Code:
(require 'test-helper)


(ert-deftest ledger-complete/test-001 ()
  "Regress test for Bug 969+582
http://bugs.ledger-cli.org/show_bug.cgi?id=969
http://bugs.ledger-cli.org/show_bug.cgi?id=582"
  :tags '(complete regress)

  (let ((ledger-complete-in-steps t))
    (ledger-tests-with-temp-file
        "2013/05/19 Retrait
    Dépense:Alimentation:Épicerie  35 €  ; Marché
    Dépense:Alimentation:Épicerie  8,1 €  ; Arum café
    Dépense:Liquide
    * Passif:Crédit:BanqueAccord              -60,00 €"
      (forward-line 1)
      (move-end-of-line 1)
      (newline)
      (insert "    Dé")
      (call-interactively #'completion-at-point)
      (should
       (equal (buffer-string)
              "2013/05/19 Retrait
    Dépense:Alimentation:Épicerie  35 €  ; Marché
    Dépense:
    Dépense:Alimentation:Épicerie  8,1 €  ; Arum café
    Dépense:Liquide
    * Passif:Crédit:BanqueAccord              -60,00 €")))))


(ert-deftest ledger-complete/test-002 ()
  "Regress test for Bug 252
http://bugs.ledger-cli.org/show_bug.cgi?id=252"
  :tags '(complete regress)

  (ledger-tests-with-temp-file
      "2010/04/08 payee
    account1                1 €
    account2
"
    (goto-char (point-max))
    (newline)
    (insert "2016/09/01 payee")
    (ledger-fully-complete-xact)
    (should
     (equal (buffer-string)
            "2010/04/08 payee
    account1                1 €
    account2

2016/09/01 payee
    account1                1 €
    account2
"))))

(ert-deftest ledger-complete/test-complete-account-without-amount ()
  "https://github.com/ledger/ledger-mode/issues/141"
  :tags '(complete regress)
  (ledger-tests-with-temp-file
      "2010/04/08 payee
    blah                1 €
    bloop

2010/04/09 payee
    blo"
    (goto-char (point-max))
    (call-interactively 'completion-at-point)
    (should
     (equal (buffer-string)
            "2010/04/08 payee
    blah                1 €
    bloop

2010/04/09 payee
    bloop"))))

(ert-deftest ledger-complete/test-complete-single-payee ()
  "https://github.com/ledger/ledger-mode/issues/181"
  :tags '(complete regress)
  (ledger-tests-with-temp-file
      "2019/06/28 Foobar
    Expenses:Baz                               11.99 CAD
    Assets:Cash

2019/06/20 Foo"
    (goto-char (point-max))
    (call-interactively 'completion-at-point)
    (should
     (equal (buffer-string)
            "2019/06/28 Foobar
    Expenses:Baz                               11.99 CAD
    Assets:Cash

2019/06/20 Foobar"))))

(ert-deftest ledger-complete/test-find-accounts-in-buffer ()
  (let ((ledger "*** Expenses
account Expenses:Accomodation
account Assets:Cash  ; some comment
account Assets:Current
;    alias 1187465S022    -- Ideally this line could be uncommented
commodity EUR
;    format 1,000.00 EUR  -- Ideally this line could be uncommented
tag ofxid
2018/05/07 * Company
    Assets:Current  -38.33 EUR
    ; ofxid: someid
    Expenses:Utilities:Insurance  38.00 EUR
    [Dimensions:Foo]  30.00 EUR
    [Expenses:Accomodation]  8.33 EUR
    [Dimensions:Equity]  -38.33 EUR
    (Something)  43.00 EUR
"))
    (with-temp-buffer
      (insert ledger)
      (should (equal
               (ledger-accounts-list-in-buffer)
               (list
                "Assets:Cash"
                "Assets:Current"
                "Dimensions:Equity"
                "Dimensions:Foo"
                "Expenses:Accomodation"
                "Expenses:Utilities:Insurance"
                "Something"))))))

(ert-deftest ledger-complete/test-find-accounts-with-spaces-in-buffer ()
  (let ((ledger "*** Expenses
account Expenses:The Bakery
"))
    (with-temp-buffer
      (insert ledger)
      (should (equal
               (ledger-accounts-list-in-buffer)
               (list
                "Expenses:The Bakery"))))))

(provide 'complete-test)

;;; complete-test.el ends here