-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocodo-handy-functions-tests.el
101 lines (87 loc) · 3.16 KB
/
ocodo-handy-functions-tests.el
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
;;; ocodo-handy-functions-tests.el -*- lexical-binding: t; -*-
(require 'ocodo-handy-functions)
(require 'ert)
(ert-deftest let1 ()
"Test let1."
(should (equal 2 (let1 a 2 a))))
(ert-deftest csv-to-lists ()
"Test csv-to-lists."
(let ((csv "1,2,3,4,5,Foo
5,4,3,2,1,Bar")
(expected '(("1" "2" "3" "4" "5" "Foo")
("5" "4" "3" "2" "1" "Bar"))))
(csv-to-lists csv)
(should (equal expected (csv-to-lists csv)))))
(ert-deftest decimal-to-hex ()
"Test decimal to hex conversion (editor fn so all numbers are strings)."
(let ((decimal-num "410")
(expected "19A"))
(should (string= expected (decimal-to-hex decimal-num)))))
(ert-deftest int-to-binary-string ()
"Test decimal int to binary string."
(let ((decimal-num 6)
(expected "110"))
(should (string= expected (int-to-binary-string decimal-num)))))
(ert-deftest s-squeeze ()
"Test s-squeeze."
(let ((expected ".Test.")
(str ".....Test...."))
(should (string= expected (s-squeeze "." str)))))
(ert-deftest time-to-seconds ()
"Test time to seconds."
(let ((expected 369)
(time "00:06:09"))
(should (= expected (time-to-seconds time)))))
(ert-deftest generate-markdown-defun-entry ()
"Test markdown generation from defun info."
(let ((expected (format-multiline "|### align-number-right
|
|Align region to equal signs from `begin` to `end`.
|
|<sup>function signature</sup>
|```lisp
|(align-number-right (begin end))
|```
|
|- - -
|"))
(info '(align-number-right (begin end) "Align region to equal signs from BEGIN to END.")))
(should (string= expected (generate-markdown-defun-entry info)))))
(ert-deftest is-markdown-filename-p ()
"Test is-markdown-filename-p"
(let ((expected `(,t ,t ,nil))
(filenames '("test.md"
"test.markdown"
"test.txt")))
(should (equal expected
(--map
(is-markdown-filename-p it)
filenames)))))
(ert-deftest format-multiline ()
"Test multiline format."
(let ((input '("|Line %s
| Line %i
| Line %x : %x : %#X
| Line %.2f
| Line %s
|" "one" 2 3 255 255 4.23 "five"))
(expected "Line one
Line 2
Line 3 : ff : 0XFF
Line 4.23
Line five
"))
(should (equal expected (apply 'format-multiline input)))))
(ert-deftest md-code-to-docstring-arg ()
"Test md-code-to-docstring-arg."
(let ((input "this is a `test`")
(expected "this is a TEST"))
(should (equal
expected
(md-code-to-docstring-arg input)))))
(ert-deftest plist-bind ()
"Test plist-bind."
(let1 result (plist-bind (a c)
'(:a 0 :b 1 :c 2 :d 3)
`(,a ,c))
(should (equal result '(0 2)))))