/[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.5 - (hide annotations)
Fri Jul 29 21:27:03 2005 UTC (8 years, 8 months ago) by dbueno
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +24 -5 lines
- cli-parser.lisp: pretty-printing for CLI-OPTION, various code cleanups.

- cli-parser-test.lisp: Example option configuration.

- unit-test.lisp: (get-tests): New function.
1 dbueno 1.5 ;;;; $Id: cli-parser-test.lisp,v 1.5 2005/07/29 21:27:03 dbueno Exp $
2 dbueno 1.1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 dbueno 1.5 ;;;; Denis Bueno
4 dbueno 1.1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 dbueno 1.5 ;;;; Thorough test of cli-parser.lisp
6 dbueno 1.1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7    
8     (in-package :cli-parser)
9 dbueno 1.5 (eval-when (:compile-toplevel :load-toplevel :execute)
10     (use-package :lunit))
11 dbueno 1.1
12 dbueno 1.5 (defparameter *option-conf*
13     (list (make-instance 'cli-option
14     :abbr "t"
15     :full "use-threads"
16     :requires-arguments :optional
17     :description "Whether the application should using threads"
18     :example "--use-threads[=5]")
19     (make-instance 'cli-option
20     :abbr nil
21     :full "root-dir"
22     :requires-arguments t
23     :description "The location of the root directory"
24     :example "--root-dir=/tmp")
25     (make-instance 'cli-option
26     :abbr "e"
27     :full "extension-list"
28     :requires-arguments t
29     :description "The list of extensions to include from the root directory (see option root-dir)"
30     :example "--extension-list=txt[,jpg,jpeg,pdf]")))
31 dbueno 1.1
32     (deftest test-opt-p ()
33     (check (opt-p "-o"))
34     (check (opt-p "--an-option"))
35     (check (not (opt-p 'k))))
36    
37     (deftest test-abbr-opt-p ()
38     (check (abbr-opt-p "-o"))
39     (check (abbr-opt-p "-j=123"))
40     (check (abbr-opt-p "-j 123"))
41     (check (abbr-opt-p "-k=opt1 opt2 opt3"))
42     (check (abbr-opt-p "-k opt1 opt2 opt3"))
43     (check (abbr-opt-p "-k=op1,op2"))
44     (check (abbr-opt-p "-k op1,op2"))
45     (check (not (abbr-opt-p "-crazy-cartoon")))
46     (check (not (abbr-opt-p "--kilimanjaro")))
47     (check (not (abbr-opt-p "--opt2=4"))))
48    
49     (deftest test-full-opt-p ()
50     (let ((opt1 "--obloquy")
51     (opt2 "--jthingie=123")
52     (opt3 "--thing=1 2 3")
53     (opt4 "--k"))
54 dbueno 1.2 (check (full-opt-p opt1))
55     (check (full-opt-p opt2))
56     (check (full-opt-p opt3))
57     (check (full-opt-p "--thing 1 2 3"))
58     (check (full-opt-p "--thing 1,2,3"))
59 dbueno 1.4 (check (not (full-opt-p opt4)))
60     (check (not (full-opt-p "-cookycrisp")))
61     (check (not (full-opt-p "-k=3")))
62     (check (not (full-opt-p "-k 3")))))
63 dbueno 1.1
64     (deftest test-end-opt-name ()
65 dbueno 1.3 (check
66     (= 7 (end-opt-name "--crazy"))
67     (= 2 (end-opt-name "-c"))
68     (= 7 (end-opt-name "--happy=25"))
69     (= 7 (end-opt-name "--happy 25"))))
70 dbueno 1.1
71     (deftest test-opt-name ()
72 dbueno 1.3 (check
73     (string="crazy" (opt-name "--crazy"))
74     (string= "o" (opt-name "-o"))
75     (string= "crazy" (opt-name "--crazy=1299"))
76     (string= "o" (opt-name "-o=678"))
77     (string= "crazy" (opt-name "--crazy 1299"))
78     (string= "o" (opt-name "-o 678"))))
79 dbueno 1.1
80     (deftest test-opt-values ()
81 dbueno 1.2 (check
82     (null (opt-values "--some-option"))
83     (equalp '("x" "y" "z") (opt-values "--some-option=x y z "))
84     (equalp '("x" "y" "z") (opt-values "--opt=x,y,z"))
85     (equalp '("x" "y" "z") (opt-values "--opt x,y,z"))
86     (equalp '("x" "y" "z") (opt-values "--opt x y z"))
87     (equalp '("1" "2") (opt-values "-x=1 2"))
88     (equalp '("1") (opt-values "-x=1"))
89     (equalp '("1") (opt-values "-x 1"))
90     (equalp '("1") (opt-values "--stupid 1"))))
91 dbueno 1.1
92     (defparameter *test-cli-opts*
93     (list
94     (make-cli-option :abbr "o" :full "ornithology" :requires-arguments t
95     :description
96     "Pass 1 to this to enable ornithology, 2 to enable it twice"
97     :example "-o 1, --ornithology 1")
98     (make-cli-option :abbr "a" :full "artaxerxes" :requires-arguments nil
99     :description "Here's some ancient king for you"
100     :example "-a, --artaxerxes")))
101    
102     (deftest test-abbr->full-opt-name ()
103 dbueno 1.2 (check
104     (string= "artaxerxes"
105     (abbr->full-opt-name "a" *test-cli-opts*))
106     (string= "ornithology"
107     (abbr->full-opt-name "o" *test-cli-opts*))
108     (string= "ornithology"
109     (abbr->full-opt-name "ornithology" *test-cli-opts*))
110     (string= "k" (abbr->full-opt-name "k" *test-cli-opts*))))
111 dbueno 1.1
112     (deftest test-coalesce-options ()
113 dbueno 1.2 (check
114     (equalp'("--files=1 2 3")
115     (coalesce-options '("--files=1" "2" "3")))
116     (equalp '("--files 1 2 3")
117     (coalesce-options '("--files" "1" "2" "3")))
118     (equalp '("--files 1, 2, 3")
119     (coalesce-options '("--files" "1," "2," "3")))
120     (equalp '("--genre=fatty.xml"
121     "--files=file1 file2 file3"
122     "--some-other-things=1 2 3")
123     (coalesce-options '("--genre=fatty.xml" "--files=file1" "file2"
124     "file3" "--some-other-things=1" "2" "3")))))
125 dbueno 1.1
126     (deftest test-cli-parse-hash ()
127     (let ((test1 (list "--ornithology=x-value" "-a y-value"))
128     (resl1 (make-hash-table :test #'equal)))
129     (setf (gethash "ornithology" resl1) (list"x-value")
130     (gethash "artaxerxes" resl1) (list "y-value"))
131    
132 dbueno 1.3 (check (equalp resl1 (cli-parse-hash test1 *test-cli-opts*)))))
133 dbueno 1.1
134     ;;;; EOF

  ViewVC Help
Powered by ViewVC 1.1.5