1 ;;;; coding.test --- test suite for coding declarations. -*- mode: scheme -*-
3 ;;;; Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (define-module (test-coding)
20 #:use-module (test-suite lib))
22 (define (with-temp-file proc)
23 (let* ((tmpdir (or (getenv "TMPDIR")
26 (name (string-append tmpdir "/coding-test.XXXXXX"))
27 (port (mkstemp! name)))
28 (let ((res (with-throw-handler
33 (delete-file name)))))
37 (define (scan-coding str)
42 ;; We don't simply seek back and rescan, because the encoding scan
43 ;; relies on the opportunistic filling of the input buffer, which
44 ;; doesn't happen after a seek.
45 (let* ((port (open-input-file name))
46 (res (file-encoding port)))
50 (with-test-prefix "block comments"
52 (pass-if-equal "first line"
54 (scan-coding "#! coding: iso-8859-1 !#"))
56 (pass-if-equal "first line no whitespace"
58 (scan-coding "#!coding:iso-8859-1!#"))
60 (pass-if-equal "second line"
62 (scan-coding "#! \n coding: iso-8859-1 !#"))
64 (pass-if-equal "second line no whitespace"
66 (scan-coding "#!\ncoding:iso-8859-1!#"))
68 (pass-if-equal "third line"
70 (scan-coding "#! \n coding: iso-8859-1 \n !#"))
72 (pass-if-equal "third line no whitespace"
74 (scan-coding "#!\ncoding:iso-8859-1\n!#")))
76 (with-test-prefix "line comment"
77 (pass-if-equal "first line, no whitespace, no nl"
79 (scan-coding ";coding:iso-8859-1"))
81 (pass-if-equal "first line, whitespace, no nl"
83 (scan-coding "; coding: iso-8859-1 "))
85 (pass-if-equal "first line, no whitespace, nl"
87 (scan-coding ";coding:iso-8859-1\n"))
89 (pass-if-equal "first line, whitespace, nl"
91 (scan-coding "; coding: iso-8859-1 \n"))
93 (pass-if-equal "second line, no whitespace, no nl"
95 (scan-coding "\n;coding:iso-8859-1"))
97 (pass-if-equal "second line, whitespace, no nl"
99 (scan-coding "\n; coding: iso-8859-1 "))
101 (pass-if-equal "second line, no whitespace, nl"
103 (scan-coding "\n;coding:iso-8859-1\n"))
105 (pass-if-equal "second line, whitespace, nl"
107 (scan-coding "\n; coding: iso-8859-1 \n"))
109 (pass-if-equal "http://bugs.gnu.org/16463"
110 ;; On Guile <= 2.0.9, this would return "ISO-8".
112 (scan-coding (string-append (make-string 485 #\space)
113 "; coding: ISO-8859-1"))))