/[cl-cli-parser]/cl-cli-parser/cli-parser-test.lisp
ViewVC logotype

Contents of /cl-cli-parser/cli-parser-test.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sat Mar 19 23:08:23 2005 UTC (9 years, 1 month ago) by dbueno
Branch: MAIN
Changes since 1.3: +6 -6 lines
Fix up a test which was failing because it wasn't coded up correctly in the
first place.
1 ;;; $Id: cli-parser-test.lisp,v 1.4 2005/03/19 23:08:23 dbueno Exp $
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; AGNS - Automatic (G-something) N-gram Spelling Corrector
4 ;;; Denis Bueno
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;;; Thorough test of cli-parser.lisp
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
9 (in-package :cli-parser)
10 #.(use-package :lunit)
11
12
13 (deftest test-opt-p ()
14 (check (opt-p "-o"))
15 (check (opt-p "--an-option"))
16 (check (not (opt-p 'k))))
17
18 (deftest test-abbr-opt-p ()
19 (check (abbr-opt-p "-o"))
20 (check (abbr-opt-p "-j=123"))
21 (check (abbr-opt-p "-j 123"))
22 (check (abbr-opt-p "-k=opt1 opt2 opt3"))
23 (check (abbr-opt-p "-k opt1 opt2 opt3"))
24 (check (abbr-opt-p "-k=op1,op2"))
25 (check (abbr-opt-p "-k op1,op2"))
26 (check (not (abbr-opt-p "-crazy-cartoon")))
27 (check (not (abbr-opt-p "--kilimanjaro")))
28 (check (not (abbr-opt-p "--opt2=4"))))
29
30 (deftest test-full-opt-p ()
31 (let ((opt1 "--obloquy")
32 (opt2 "--jthingie=123")
33 (opt3 "--thing=1 2 3")
34 (opt4 "--k"))
35 (check (full-opt-p opt1))
36 (check (full-opt-p opt2))
37 (check (full-opt-p opt3))
38 (check (full-opt-p "--thing 1 2 3"))
39 (check (full-opt-p "--thing 1,2,3"))
40 (check (not (full-opt-p opt4)))
41 (check (not (full-opt-p "-cookycrisp")))
42 (check (not (full-opt-p "-k=3")))
43 (check (not (full-opt-p "-k 3")))))
44
45 (deftest test-end-opt-name ()
46 (check
47 (= 7 (end-opt-name "--crazy"))
48 (= 2 (end-opt-name "-c"))
49 (= 7 (end-opt-name "--happy=25"))
50 (= 7 (end-opt-name "--happy 25"))))
51
52 (deftest test-opt-name ()
53 (check
54 (string="crazy" (opt-name "--crazy"))
55 (string= "o" (opt-name "-o"))
56 (string= "crazy" (opt-name "--crazy=1299"))
57 (string= "o" (opt-name "-o=678"))
58 (string= "crazy" (opt-name "--crazy 1299"))
59 (string= "o" (opt-name "-o 678"))))
60
61 (deftest test-opt-values ()
62 (check
63 (null (opt-values "--some-option"))
64 (equalp '("x" "y" "z") (opt-values "--some-option=x y z "))
65 (equalp '("x" "y" "z") (opt-values "--opt=x,y,z"))
66 (equalp '("x" "y" "z") (opt-values "--opt x,y,z"))
67 (equalp '("x" "y" "z") (opt-values "--opt x y z"))
68 (equalp '("1" "2") (opt-values "-x=1 2"))
69 (equalp '("1") (opt-values "-x=1"))
70 (equalp '("1") (opt-values "-x 1"))
71 (equalp '("1") (opt-values "--stupid 1"))))
72
73 (defparameter *test-cli-opts*
74 (list
75 (make-cli-option :abbr "o" :full "ornithology" :requires-arguments t
76 :description
77 "Pass 1 to this to enable ornithology, 2 to enable it twice"
78 :example "-o 1, --ornithology 1")
79 (make-cli-option :abbr "a" :full "artaxerxes" :requires-arguments nil
80 :description "Here's some ancient king for you"
81 :example "-a, --artaxerxes")))
82
83 (deftest test-abbr->full-opt-name ()
84 (check
85 (string= "artaxerxes"
86 (abbr->full-opt-name "a" *test-cli-opts*))
87 (string= "ornithology"
88 (abbr->full-opt-name "o" *test-cli-opts*))
89 (string= "ornithology"
90 (abbr->full-opt-name "ornithology" *test-cli-opts*))
91 (string= "k" (abbr->full-opt-name "k" *test-cli-opts*))))
92
93 (deftest test-coalesce-options ()
94 (check
95 (equalp'("--files=1 2 3")
96 (coalesce-options '("--files=1" "2" "3")))
97 (equalp '("--files 1 2 3")
98 (coalesce-options '("--files" "1" "2" "3")))
99 (equalp '("--files 1, 2, 3")
100 (coalesce-options '("--files" "1," "2," "3")))
101 (equalp '("--genre=fatty.xml"
102 "--files=file1 file2 file3"
103 "--some-other-things=1 2 3")
104 (coalesce-options '("--genre=fatty.xml" "--files=file1" "file2"
105 "file3" "--some-other-things=1" "2" "3")))))
106
107 (deftest test-cli-parse-hash ()
108 (let ((test1 (list "--ornithology=x-value" "-a y-value"))
109 (resl1 (make-hash-table :test #'equal)))
110 (setf (gethash "ornithology" resl1) (list"x-value")
111 (gethash "artaxerxes" resl1) (list "y-value"))
112
113 (check (equalp resl1 (cli-parse-hash test1 *test-cli-opts*)))))
114
115 ;;;; EOF

  ViewVC Help
Powered by ViewVC 1.1.5