tests: configuration: Add a test to cover 'unset regression.
[jackhill/guix/guix.git] / tests / read-print.scm
index 70be775..b484e28 100644 (file)
                      read-with-comments)))
          (pretty-print-with-comments port exp args ...))))))
 
+(define-syntax-rule (test-pretty-print/sequence str args ...)
+  "Likewise, but read and print entire sequences rather than individual
+expressions."
+  (test-equal str
+    (call-with-output-string
+      (lambda (port)
+        (let ((lst (call-with-input-string str
+                     read-with-comments/sequence)))
+         (pretty-print-with-comments/splice port lst args ...))))))
+
 \f
 (test-begin "read-print")
 
   (let ((z (+ x y)))
     (* z z)))")
 
+(test-pretty-print "\
+(case x
+  ((1)
+   'one)
+  ((2)
+   'two))")
+
+(test-pretty-print "\
+(cond
+  ((zero? x)
+   'zero)
+  ((odd? x)
+   'odd)
+  (else #f))")
+
 (test-pretty-print "\
 #~(string-append #$coreutils \"/bin/uname\")")
 
@@ -251,6 +276,35 @@ mnopqrstuvwxyz.\")"
   ;; page break above
   end)")
 
+(test-pretty-print/sequence "\
+;;; This is a top-level comment.
+
+\f
+;; Above is a page break.
+(this is an sexp
+      ;; with a comment
+      !!)
+
+;; The end.\n")
+
+(test-pretty-print/sequence "
+;;; Hello!
+;;; Notice that there are three semicolons here.
+
+(define-module (foo bar)
+  #:use-module (guix)
+  #:use-module (gnu))
+
+
+;; And now, the OS.
+(operating-system
+  (host-name \"komputilo\")
+  (locale \"eo_EO.UTF-8\")
+
+  (services
+   (cons (service mcron-service-type) %base-services)))\n"
+                            #:format-comment canonicalize-comment)
+
 (test-equal "pretty-print-with-comments, canonicalize-comment"
   "\
 (list abc
@@ -302,4 +356,18 @@ mnopqrstuvwxyz.\")"
                                     #:format-vertical-space
                                     canonicalize-vertical-space)))))
 
+(test-equal "pretty-print-with-comments, multi-line comment"
+  "\
+(list abc
+      ;; This comment spans
+      ;; two lines.
+      def)"
+  (call-with-output-string
+    (lambda (port)
+      (pretty-print-with-comments port
+                                  `(list abc ,(comment "\
+;; This comment spans\n
+;; two lines.\n")
+                                         def)))))
+
 (test-end)