ui: Factorize package specification parsing.
[jackhill/guix/guix.git] / tests / ui.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19
20 (define-module (test-ui)
21 #:use-module (guix ui)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-19)
24 #:use-module (srfi srfi-64))
25
26 ;; Test the (guix ui) module.
27
28 (define %paragraph
29 "GNU Guile is an implementation of the Scheme programming language, with
30 support for many SRFIs, packaged for use in a wide variety of environments.
31 In addition to implementing the R5RS Scheme standard and a large subset of
32 R6RS, Guile includes a module system, full access to POSIX system calls,
33 networking support, multiple threads, dynamic linking, a foreign function call
34 interface, and powerful string processing.")
35
36 \f
37 (test-begin "ui")
38
39 (test-assert "fill-paragraph"
40 (every (lambda (column)
41 (every (lambda (width)
42 (every (lambda (line)
43 (<= (string-length line) width))
44 (string-split (fill-paragraph %paragraph
45 width column)
46 #\newline)))
47 '(15 30 35 40 45 50 60 70 80 90 100)))
48 '(0 5)))
49
50 (test-assert "fill-paragraph, consecutive newlines"
51 (every (lambda (width)
52 (any (lambda (line)
53 (string-prefix? "When STR" line))
54 (string-split
55 (fill-paragraph (procedure-documentation fill-paragraph)
56 width)
57 #\newline)))
58 '(15 20 25 30 40 50 60)))
59
60 (test-equal "fill-paragraph, large unbreakable word"
61 '("Here is a" "very-very-long-word"
62 "and that's" "it.")
63 (string-split
64 (fill-paragraph "Here is a very-very-long-word and that's it."
65 10)
66 #\newline))
67
68 (test-equal "package-specification->name+version+output"
69 '(("guile" #f "out")
70 ("guile" "2.0.9" "out")
71 ("guile" #f "debug")
72 ("guile" "2.0.9" "debug")
73 ("guile-cairo" "1.4.1" "out"))
74 (map (lambda (spec)
75 (call-with-values
76 (lambda ()
77 (package-specification->name+version+output spec))
78 list))
79 '("guile"
80 "guile-2.0.9"
81 "guile:debug"
82 "guile-2.0.9:debug"
83 "guile-cairo-1.4.1")))
84
85 (test-equal "integer"
86 '(1)
87 (string->generations "1"))
88
89 (test-equal "comma-separated integers"
90 '(3 7 1 4 6)
91 (string->generations "3,7,1,4,6"))
92
93 (test-equal "closed range"
94 '(4 5 6 7 8 9 10 11 12)
95 (string->generations "4..12"))
96
97 (test-equal "closed range, equal endpoints"
98 '(3)
99 (string->generations "3..3"))
100
101 (test-equal "indefinite end range"
102 '(>= 7)
103 (string->generations "7.."))
104
105 (test-equal "indefinite start range"
106 '(<= 42)
107 (string->generations "..42"))
108
109 (test-equal "integer, char"
110 #f
111 (string->generations "a"))
112
113 (test-equal "comma-separated integers, consecutive comma"
114 #f
115 (string->generations "1,,2"))
116
117 (test-equal "comma-separated integers, trailing comma"
118 #f
119 (string->generations "1,2,"))
120
121 (test-equal "comma-separated integers, chars"
122 #f
123 (string->generations "a,b"))
124
125 (test-equal "closed range, start > end"
126 #f
127 (string->generations "9..2"))
128
129 (test-equal "closed range, chars"
130 #f
131 (string->generations "a..b"))
132
133 (test-equal "indefinite end range, char"
134 #f
135 (string->generations "a.."))
136
137 (test-equal "indefinite start range, char"
138 #f
139 (string->generations "..a"))
140
141 (test-equal "duration, 1 day"
142 (make-time time-duration 0 (* 3600 24))
143 (string->duration "1d"))
144
145 (test-equal "duration, 1 week"
146 (make-time time-duration 0 (* 3600 24 7))
147 (string->duration "1w"))
148
149 (test-equal "duration, 1 month"
150 (make-time time-duration 0 (* 3600 24 30))
151 (string->duration "1m"))
152
153 (test-equal "duration, 1 week == 7 days"
154 (string->duration "1w")
155 (string->duration "7d"))
156
157 (test-equal "duration, 1 month == 30 days"
158 (string->duration "1m")
159 (string->duration "30d"))
160
161 (test-equal "duration, integer"
162 #f
163 (string->duration "1"))
164
165 (test-equal "duration, char"
166 #f
167 (string->duration "d"))
168
169 (test-end "ui")
170
171 \f
172 (exit (= (test-runner-fail-count (test-runner-current)) 0))