Augment `.dir-locals.el'.
[jackhill/guix/guix.git] / tests / build-utils.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012 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-build-utils)
21 #:use-module (guix build utils)
22 #:use-module (srfi srfi-64))
23
24 (test-begin "build-utils")
25
26 (test-equal "alist-cons-before"
27 '((a . 1) (x . 42) (b . 2) (c . 3))
28 (alist-cons-before 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
29
30 (test-equal "alist-cons-before, reference not found"
31 '((a . 1) (b . 2) (c . 3) (x . 42))
32 (alist-cons-before 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
33
34 (test-equal "alist-cons-after"
35 '((a . 1) (b . 2) (x . 42) (c . 3))
36 (alist-cons-after 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
37
38 (test-equal "alist-cons-after, reference not found"
39 '((a . 1) (b . 2) (c . 3) (x . 42))
40 (alist-cons-after 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
41
42 (test-equal "alist-replace"
43 '((a . 1) (b . 77) (c . 3))
44 (alist-replace 'b 77 '((a . 1) (b . 2) (c . 3))))
45
46 (test-assert "alist-replace, key not found"
47 (not (false-if-exception
48 (alist-replace 'z 77 '((a . 1) (b . 2) (c . 3))))))
49
50 (test-equal "fold-port-matches"
51 (make-list 3 "Guix")
52 (call-with-input-string "Guix is cool, Guix rocks, and it uses Guile, Guix!"
53 (lambda (port)
54 (fold-port-matches cons '() "Guix" port))))
55
56 (test-equal "fold-port-matches, trickier"
57 (reverse '("Guix" "guix" "Guix" "guiX" "Guix"))
58 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
59 (lambda (port)
60 (fold-port-matches cons '()
61 (list (char-set #\G #\g)
62 (char-set #\u)
63 (char-set #\i)
64 (char-set #\x #\X))
65 port))))
66
67 (test-equal "fold-port-matches, with unmatched chars"
68 '("Guix" #\, #\space
69 "guix" #\, #\space
70 #\G #\u #\i "Guix" "guiX" #\, #\space
71 "Guix")
72 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
73 (lambda (port)
74 (reverse
75 (fold-port-matches cons '()
76 (list (char-set #\G #\g)
77 (char-set #\u)
78 (char-set #\i)
79 (char-set #\x #\X))
80 port
81 cons)))))
82
83 (test-end)
84
85 \f
86 (exit (= (test-runner-fail-count (test-runner-current)) 0))