emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob b230750509d4608bbb24fcebdc8b61fc5a862b30 8012 bytes (raw)

  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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 
;;; test-org-plot.el --- Tests for Org Plot library    -*- lexical-binding: t; -*-

;; Copyright (C) 2020  Mario Frasca

;; Author: Mario Frasca <mario at anche dot no>

;; 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 3 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, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'org-test)
(require 'org-plot)

\f
;; General auxiliaries


(ert-deftest test-org-plot/collect-line-options ()
  "Test `org-plot/collect-line-options' specifications."
  ;; no options specified in table, no defaults
  (should
   (equal nil
          (org-test-with-temp-text
              "| 1 |"
            (org-plot/collect-line-options))))
  ;; no options specified in table, keeps all defaults
  (should
   (equal '(:ind 1 :deps 2 3)
          (org-test-with-temp-text
              "| 1 |"
            (org-plot/collect-line-options '(:ind 1 :deps 2 3)))))
  ;; the independent column
  (should
   (equal '(:ind 1)
          (org-test-with-temp-text
              "#+PLOT: ind:1\n| 1 |"
            (org-plot/collect-line-options))))
  ;; overruling default
  (should
   (equal '(:ind 2)
          (org-test-with-temp-text
              "#+PLOT: ind:2\n| 1 | 2 |"
            (org-plot/collect-line-options '(:ind 1)))))
  ;; appends to already collected
  (should
   (equal '(:deps (1 3) :ind 2 )
          (org-test-with-temp-text
              "#+PLOT: ind:2\n| 1 | 2 | 3 |"
            (org-plot/collect-line-options '(:deps (1 3))))))
  ;; appends to already collected
  (should
   (equal '(:ind 2 :deps (1 3) )
          (org-test-with-temp-text
              "#+PLOT: ind:2\n| 1 | 2 | 3 |"
            (org-plot/collect-line-options '(:ind 1 :deps (1 3))))))
  ;; multiple options from single line
  (should  ; `op' in add-options-to-plist defines order of options
   (equal '(:plot-type 2d :title "example table" :ind 1 :deps (2 3) :with (lines points))
          (org-test-with-temp-text
              "#+PLOT: title:\"example table\" ind:1 deps:(2 3) type:2d with:(lines points)"
            (org-plot/collect-line-options))))
  ;; with, as a single string
  (should
   (equal '(:with lines)
          (org-test-with-temp-text
              "#+PLOT: with:lines\n| 1 | 2 | 3 |"
            (org-plot/collect-line-options))))
  ;; with, as a list
  (should
   (equal '(:with (lines hist))
          (org-test-with-temp-text
              "#+PLOT: with:(lines hist)\n| 1 | 2 | 3 |"
            (org-plot/collect-line-options)))))


(ert-deftest test-org-plot/collect-table-options ()
  "Test `org-plot/collect-table-options' specifications."
  ;; all options on a single lines
  (should  ; `op' in add-options-to-plist defines order of options
   (equal '(:plot-type 2d :title "example table" :ind 1 :deps (2 3) :with (lines points))
          (org-test-with-temp-text
              "#+PLOT: title:\"example table\" ind:1 deps:(2 3) type:2d with:(lines points)\n"
	    (goto-char (point-max))  ; point must be on line after last options line
            (org-plot/collect-table-options))))
  ;; multiple options from multiple lines
  (should  ; `op' in add-options-to-plist defines order of options
   (equal '(:plot-type 2d :with (lines points) :title "example table" :ind 1 :deps (2 3))
          (org-test-with-temp-text
              "#+PLOT: title:\"example table\" ind:1 deps:(2 3)\n#+PLOT: type:2d with:(lines points)\n"
	    (goto-char (point-max))  ; point must be on line after last options line
            (org-plot/collect-table-options))))
  ;; one option per line, several lines (collected going up)
  (should
   (equal '(:with (lines points) :plot-type 2d :deps (2 3) :ind 1 :title "example table")
          (org-test-with-temp-text
              "#+PLOT: title:\"example table\"\n#+PLOT: ind:1\n#+PLOT: deps:(2 3)\n#+PLOT: type:2d\n#+PLOT: with:(lines points)\n"
	    (goto-char (point-max))  ; point must be on line after last options line
            (org-plot/collect-table-options)))))


(ert-deftest test-org-plot/goto-nearest-table ()
  "Test `org-plot/goto-nearest-table' specifications."
  ;; at table beginning stays put
  (should
   (= 1
      (org-test-with-temp-text
       "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |"
       (org-plot/goto-nearest-table))))
  ;; anywhere within the table moves back to table beginning
  (should
   (= 1
      (org-test-with-temp-text
       "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |"
       (goto-char 4)
       (org-plot/goto-nearest-table))))
  ;; on newline at end of table, goes back to table beginning
  (should
   (= 1
      (org-test-with-temp-text
       "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n"
       (goto-char (point-max))
       (org-plot/goto-nearest-table))))
  ;; farther away than newline at end of last table, moves to end of buffer
  (should
   (= 44
      (org-test-with-temp-text
       "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n\n"
       (goto-char (point-max))
       (org-plot/goto-nearest-table))))
  ;; moves to beginning of data, not metadata
  (should
   (= 26
      (org-test-with-temp-text
       "#+PLOT: ind:1 deps:(2 3)\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |"
       (org-plot/goto-nearest-table))))
  ;; in case there's two tables
  (should
   (= 30
      (org-test-with-temp-text
       "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n\n| 1 | 2 | 3 |"
       (goto-char (point-max))
       (org-plot/goto-nearest-table)))))


(ert-deftest test-org-plot/gnuplot-script ()
  "Regression Test for `org-plot/gnuplot-script'."
  (should
   (equal "reset
set datafile separator \"\\t\"
plot FILENAME using 1:2 with points title '2',\\
    FILENAME using 1:3 with points title '3'"
          (org-test-with-temp-text
           "| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |"
           (let ((data-file (make-temp-file "org-plot"))
                 (table (org-table-to-lisp))
                 (params '(:ind 1 :deps (2 3) :plot-type 2d :with points)))
             (org-plot/gnuplot-to-data table data-file params)
             (org-plot/gnuplot-script data-file 3 params t)
             (replace-regexp-in-string (concat "'" (regexp-quote data-file) "'")
                                       "FILENAME"
                                       (org-plot/gnuplot-script data-file 3 params)
                                       nil 'LITERAL)))))
  (should
   (equal "reset
set title 'example table'
set datafile separator \"\\t\"
plot FILENAME using 1:2 with lines title 'ylab',\\
    FILENAME using 1:3 with lines title 'zlab'"
          (org-test-with-temp-text
	   "\
#+PLOT: title:\"example table\" ind:1 deps:(2 3) type:2d with:lines
#+PLOT: labels:(\"xlab\" \"ylab\" \"zlab\")
#+TBLNAME:org-plot-example-1
|   x |    y |    z |
|-----+------+------|
| 0.1 | 0.42 | 0.37 |
| 0.2 | 0.31 | 0.33 |
| 0.3 | 0.24 | 0.28 |
| 0.4 | 0.27 | 0.23 |
"
           (org-plot/goto-nearest-table)
           (let ((data-file (make-temp-file "org-plot"))
                 (table (org-table-to-lisp))
                 params)
	     (setq params (org-plot/collect-table-options params))
             (org-plot/gnuplot-to-data table data-file params)
             (org-plot/gnuplot-script data-file 3 params t)
             (replace-regexp-in-string (concat "'" (regexp-quote data-file) "'")
                                       "FILENAME"
                                       (org-plot/gnuplot-script data-file 3 params)
                                       nil 'LITERAL))))))
\f
(provide 'test-org-plot)
;;; test-org-plot.el end here

debug log:

solving b23075050 ...
found b23075050 in https://list.orgmode.org/orgmode/2abe19ad-2237-991d-5325-82b3f870485e@gmail.com/ ||
	https://list.orgmode.org/orgmode/3a1d33dd-edec-1a7f-9115-10691442a877@gmail.com/

applying [1/1] https://list.orgmode.org/orgmode/2abe19ad-2237-991d-5325-82b3f870485e@gmail.com/
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 000000000..b23075050

1:7: trailing whitespace.
;;; test-org-plot.el --- Tests for Org Plot library -*- 
error: corrupt patch at line 8

git apply error:; exit status=128
trying https://list.orgmode.org/orgmode/3a1d33dd-edec-1a7f-9115-10691442a877@gmail.com/

applying [2/1] https://list.orgmode.org/orgmode/3a1d33dd-edec-1a7f-9115-10691442a877@gmail.com/
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 000000000..b23075050

Checking patch testing/lisp/test-org-plot.el...
Applied patch testing/lisp/test-org-plot.el cleanly.

index at:
100644 b230750509d4608bbb24fcebdc8b61fc5a862b30	testing/lisp/test-org-plot.el

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).