| 1 |
;; Tests for class `rst-Stn' -*- lexical-binding: t -*- |
| 2 |
|
| 3 |
(add-to-list 'load-path ".") |
| 4 |
(load "init" nil t) |
| 5 |
(init-rst-ert nil) |
| 6 |
|
| 7 |
(ert-deftest rst-Stn-new () |
| 8 |
"Test `rst-Stn-new'." |
| 9 |
(let* (;; " |
| 10 |
;; ===== |
| 11 |
;; Title |
| 12 |
;; ===== |
| 13 |
;; |
| 14 |
;; Header A |
| 15 |
;; ======== |
| 16 |
;; |
| 17 |
;; Header B |
| 18 |
;; ======== |
| 19 |
;; |
| 20 |
;; Subheader B.a |
| 21 |
;; ------------- |
| 22 |
;; |
| 23 |
;; SubSubheader B.a.1 |
| 24 |
;; ~~~~~~~~~~~~~~~~~~ |
| 25 |
;; |
| 26 |
;; Header C |
| 27 |
;; ======== |
| 28 |
;; |
| 29 |
;; Missing node C.a.1 |
| 30 |
;; ~~~~~~~~~~~~~~~~~~ |
| 31 |
;; " |
| 32 |
(ado-T (rst-Ado-new-over-and-under ?=)) |
| 33 |
(ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0 |
| 34 |
"Title")) |
| 35 |
(ado-A (rst-Ado-new-simple ?=)) |
| 36 |
(ttl-A (rst-Ttl--new ado-A '(20 37 nil nil 20 28 29 37) 0 |
| 37 |
"Header A")) |
| 38 |
(ttl-B (rst-Ttl--new ado-A '(39 56 nil nil 39 47 48 56) 0 |
| 39 |
"Header B")) |
| 40 |
(ado-Ba (rst-Ado-new-simple ?-)) |
| 41 |
(ttl-Ba (rst-Ttl--new ado-Ba '(58 85 nil nil 58 71 72 85) 0 |
| 42 |
"Subheader B.a")) |
| 43 |
(ado-Ba1 (rst-Ado-new-simple ?~)) |
| 44 |
(ttl-Ba1 (rst-Ttl--new ado-Ba1 '(87 124 nil nil 87 105 106 124) 0 |
| 45 |
"SubSubheader B.a.1")) |
| 46 |
(ttl-C (rst-Ttl--new ado-A '(126 143 nil nil 126 134 135 143) 0 |
| 47 |
"Header C")) |
| 48 |
(ttl-Ca nil) |
| 49 |
(ttl-Ca1 (rst-Ttl--new ado-Ba1 '(145 182 nil nil 145 163 164 182) 0 |
| 50 |
"Missing node C.a.1"))) |
| 51 |
|
| 52 |
(should-error (rst-Stn-new "" 0 nil) |
| 53 |
:type 'wrong-type-argument) |
| 54 |
(should-error (rst-Stn-new nil "0" nil) |
| 55 |
:type 'wrong-type-argument) |
| 56 |
(should-error (rst-Stn-new nil 0 "") |
| 57 |
:type 'wrong-type-argument) |
| 58 |
(should-error (rst-Stn-new nil 0 '(1)) |
| 59 |
:type 'wrong-type-argument) |
| 60 |
|
| 61 |
(should-error (rst-Stn-new nil 0 nil) |
| 62 |
:type 'args-out-of-range) |
| 63 |
|
| 64 |
(should-error (rst-Stn-new ttl-T -1 nil) |
| 65 |
:type 'args-out-of-range) |
| 66 |
|
| 67 |
(should (rst-Stn-p |
| 68 |
(rst-Stn-new ttl-T 0 nil))) |
| 69 |
(should (rst-Stn-p |
| 70 |
(rst-Stn-new |
| 71 |
ttl-T 0 |
| 72 |
(list (rst-Stn-new ttl-A 1 nil))))) |
| 73 |
(should (rst-Stn-p |
| 74 |
(rst-Stn-new |
| 75 |
ttl-T 0 |
| 76 |
(list (rst-Stn-new ttl-A 1 nil) |
| 77 |
(rst-Stn-new ttl-B 1 nil) |
| 78 |
(rst-Stn-new ttl-C 1 nil))))) |
| 79 |
(should (rst-Stn-p |
| 80 |
(rst-Stn-new |
| 81 |
ttl-T 0 |
| 82 |
(list (rst-Stn-new ttl-A 1 nil) |
| 83 |
(rst-Stn-new |
| 84 |
ttl-B 1 |
| 85 |
(list (rst-Stn-new |
| 86 |
ttl-Ba 2 |
| 87 |
(list (rst-Stn-new ttl-Ba1 3 nil))))) |
| 88 |
(rst-Stn-new |
| 89 |
ttl-C 1 |
| 90 |
(list (rst-Stn-new |
| 91 |
ttl-Ca 2 |
| 92 |
(list (rst-Stn-new ttl-Ca1 3 nil))))))))) |
| 93 |
)) |
| 94 |
|
| 95 |
(ert-deftest rst-Stn-get-title-beginning () |
| 96 |
"Test `rst-Stn-get-title-beginning'." |
| 97 |
(let* (;; " |
| 98 |
;; ===== |
| 99 |
;; Title |
| 100 |
;; ===== |
| 101 |
;; |
| 102 |
;; Header A |
| 103 |
;; ======== |
| 104 |
;; |
| 105 |
;; Header B |
| 106 |
;; ======== |
| 107 |
;; |
| 108 |
;; Subheader B.a |
| 109 |
;; ------------- |
| 110 |
;; |
| 111 |
;; SubSubheader B.a.1 |
| 112 |
;; ~~~~~~~~~~~~~~~~~~ |
| 113 |
;; |
| 114 |
;; Header C |
| 115 |
;; ======== |
| 116 |
;; |
| 117 |
;; Missing node C.a.1 |
| 118 |
;; ~~~~~~~~~~~~~~~~~~ |
| 119 |
;; " |
| 120 |
(ado-T (rst-Ado-new-over-and-under ?=)) |
| 121 |
(ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0 |
| 122 |
"Title")) |
| 123 |
(ado-A (rst-Ado-new-simple ?=)) |
| 124 |
(ttl-A (rst-Ttl--new ado-A '(20 37 nil nil 20 28 29 37) 0 |
| 125 |
"Header A")) |
| 126 |
(ttl-B (rst-Ttl--new ado-A '(39 56 nil nil 39 47 48 56) 0 |
| 127 |
"Header B")) |
| 128 |
(ado-Ba (rst-Ado-new-simple ?-)) |
| 129 |
(ttl-Ba (rst-Ttl--new ado-Ba '(58 85 nil nil 58 71 72 85) 0 |
| 130 |
"Subheader B.a")) |
| 131 |
(ado-Ba1 (rst-Ado-new-simple ?~)) |
| 132 |
(ttl-Ba1 (rst-Ttl--new ado-Ba1 '(87 124 nil nil 87 105 106 124) 0 |
| 133 |
"SubSubheader B.a.1")) |
| 134 |
(ttl-C (rst-Ttl--new ado-A '(126 143 nil nil 126 134 135 143) 0 |
| 135 |
"Header C")) |
| 136 |
(ttl-Ca nil) |
| 137 |
(ttl-Ca1 (rst-Ttl--new ado-Ba1 '(145 182 nil nil 145 163 164 182) 0 |
| 138 |
"Missing node C.a.1"))) |
| 139 |
(let* ((stn-Ca (rst-Stn-new |
| 140 |
ttl-Ca 2 |
| 141 |
(list (rst-Stn-new ttl-Ca1 3 nil)))) |
| 142 |
(stn-C (rst-Stn-new |
| 143 |
ttl-C 1 |
| 144 |
(list stn-Ca))) |
| 145 |
(stn-A (rst-Stn-new ttl-A 1 nil)) |
| 146 |
(stn-B (rst-Stn-new |
| 147 |
ttl-B 1 |
| 148 |
(list (rst-Stn-new |
| 149 |
ttl-Ba 2 |
| 150 |
(list (rst-Stn-new ttl-Ba1 3 nil)))))) |
| 151 |
(stn-T (rst-Stn-new |
| 152 |
ttl-T 0 |
| 153 |
(list stn-A |
| 154 |
stn-B |
| 155 |
stn-C)))) |
| 156 |
(should-error (rst-Stn-get-title-beginning "") |
| 157 |
:type 'wrong-type-argument) |
| 158 |
|
| 159 |
(should (equal (rst-Stn-get-title-beginning stn-T) 7)) |
| 160 |
(should (equal (rst-Stn-get-title-beginning stn-B) 39)) |
| 161 |
(should (equal (rst-Stn-get-title-beginning stn-A) 20)) |
| 162 |
(should (equal (rst-Stn-get-title-beginning stn-C) 126)) |
| 163 |
(should (equal (rst-Stn-get-title-beginning stn-Ca) 145)) |
| 164 |
))) |
| 165 |
|
| 166 |
(ert-deftest rst-Stn-get-text () |
| 167 |
"Test `rst-Stn-get-text'." |
| 168 |
(let* (;; " |
| 169 |
;; ===== |
| 170 |
;; Title |
| 171 |
;; ===== |
| 172 |
;; |
| 173 |
;; Header A |
| 174 |
;; ======== |
| 175 |
;; |
| 176 |
;; Header B |
| 177 |
;; ======== |
| 178 |
;; |
| 179 |
;; Subheader B.a |
| 180 |
;; ------------- |
| 181 |
;; |
| 182 |
;; SubSubheader B.a.1 |
| 183 |
;; ~~~~~~~~~~~~~~~~~~ |
| 184 |
;; |
| 185 |
;; Header C |
| 186 |
;; ======== |
| 187 |
;; |
| 188 |
;; Missing node C.a.1 |
| 189 |
;; ~~~~~~~~~~~~~~~~~~ |
| 190 |
;; " |
| 191 |
(ado-T (rst-Ado-new-over-and-under ?=)) |
| 192 |
(ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0 |
| 193 |
"Title")) |
| 194 |
(ado-A (rst-Ado-new-simple ?=)) |
| 195 |
(ttl-A (rst-Ttl--new ado-A '(20 37 nil nil 20 28 29 37) 0 |
| 196 |
"Header A")) |
| 197 |
(ttl-B (rst-Ttl--new ado-A '(39 56 nil nil 39 47 48 56) 0 |
| 198 |
"Header B")) |
| 199 |
(ado-Ba (rst-Ado-new-simple ?-)) |
| 200 |
(ttl-Ba (rst-Ttl--new ado-Ba '(58 85 nil nil 58 71 72 85) 0 |
| 201 |
"Subheader B.a")) |
| 202 |
(ado-Ba1 (rst-Ado-new-simple ?~)) |
| 203 |
(ttl-Ba1 (rst-Ttl--new ado-Ba1 '(87 124 nil nil 87 105 106 124) 0 |
| 204 |
"SubSubheader B.a.1")) |
| 205 |
(ttl-C (rst-Ttl--new ado-A '(126 143 nil nil 126 134 135 143) 0 |
| 206 |
"Header C")) |
| 207 |
(ttl-Ca nil) |
| 208 |
(ttl-Ca1 (rst-Ttl--new ado-Ba1 '(145 182 nil nil 145 163 164 182) 0 |
| 209 |
"Missing node C.a.1"))) |
| 210 |
(let* ((stn-Ca (rst-Stn-new |
| 211 |
ttl-Ca 2 |
| 212 |
(list (rst-Stn-new ttl-Ca1 3 nil)))) |
| 213 |
(stn-C (rst-Stn-new |
| 214 |
ttl-C 1 |
| 215 |
(list stn-Ca))) |
| 216 |
(stn-A (rst-Stn-new ttl-A 1 nil)) |
| 217 |
(stn-B (rst-Stn-new |
| 218 |
ttl-B 1 |
| 219 |
(list (rst-Stn-new |
| 220 |
ttl-Ba 2 |
| 221 |
(list (rst-Stn-new ttl-Ba1 3 nil)))))) |
| 222 |
(stn-T (rst-Stn-new |
| 223 |
ttl-T 0 |
| 224 |
(list stn-A |
| 225 |
stn-B |
| 226 |
stn-C)))) |
| 227 |
(should-error (rst-Stn-get-text "") |
| 228 |
:type 'wrong-type-argument) |
| 229 |
|
| 230 |
(should (equal (rst-Stn-get-text stn-T) "Title")) |
| 231 |
(should (equal (rst-Stn-get-text stn-B "Default") "Header B")) |
| 232 |
(should (equal (rst-Stn-get-text stn-Ca "Default") "Default")) |
| 233 |
(should (rst-Stn-get-text stn-Ca)) |
| 234 |
))) |
| 235 |
|
| 236 |
(ert-deftest rst-Stn-is-top () |
| 237 |
"Test `rst-Stn-is-top'." |
| 238 |
(let* (;; " |
| 239 |
;; ===== |
| 240 |
;; Title |
| 241 |
;; ===== |
| 242 |
;; " |
| 243 |
(ado-T (rst-Ado-new-over-and-under ?=)) |
| 244 |
(ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0 |
| 245 |
"Title"))) |
| 246 |
(let ((stn-T (rst-Stn-new ttl-T 0 nil))) |
| 247 |
(should-error (rst-Stn-is-top nil) |
| 248 |
:type 'wrong-type-argument) |
| 249 |
(should (rst-Stn-is-top (rst-Stn-new |
| 250 |
nil -1 |
| 251 |
(list stn-T)))) |
| 252 |
(should-not (rst-Stn-is-top stn-T)) |
| 253 |
))) |