blob: bfb727786f8032b5dfeb193936cedc1b8bde422e (
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
|
;;; functions.lisp - 2025-02-20
;; Copyright (C) 2025 Aryadev Chavali
;; 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 Version 2 for
;; details.
;; You may distribute and modify this code under the terms of the GNU General
;; Public License Version 2, which you should have received a copy of along with
;; this program. If not, please go to <https://www.gnu.org/licenses/>.
;;; Code:
(defpackage cantedraw/tests/functions
(:use
:cl :parachute :cantedraw.lib.macros
:cantedraw.lib.functions))
(in-package :cantedraw/tests/functions)
(define-test function-test
:depends-on ((cantedraw/tests/macros macro-test)))
(define-test (function-test "parse-integer*")
:compile-at :execute
(is eq 2 (parse-integer* "2"))
(is eq 2048 (parse-integer* "2048abcdef"))
(is eq nil (parse-integer* "a2048abcdef"))
(is eq nil (parse-integer* "garbage"))
(fail (parse-integer* nil)))
(define-test (function-test range)
:compile-at :execute
(fail (range 1 0))
(fail (range nil nil))
(fail (range "a" "b"))
(true (null (range 1 1)))
(is equal '(1 2 3 4) (range 1 5))
(is equal '(-3 -2 -1 0) (range -3 1)))
(define-test (function-test take)
:compile-at :execute
(fail (take nil nil))
(fail (take 100 nil))
(fail (take nil 100))
(true (->> (list 1 2 3 4) (take 0) null))
(is equal "H" (take 1 "Hello"))
(is equal '(1 2) (take 2 '(1 2 3 4 5))))
(define-test (function-test split)
:compile-at :execute
(fail (split nil nil))
(fail (split 100 nil))
(fail (split nil 100))
(is-values (split 0 '(1 2 3 4))
(eq nil)
(equal '(1 2 3 4)))
(is-values (split 1 '(1 2 3 4))
(equal '(1))
(equal '(2 3 4)))
(is-values (split 5 "Hello World")
(string= "Hello")
(string= " World")))
|