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* ((name (string-copy "/tmp/coding-test.XXXXXX"))
24 (port (mkstemp! name)))
25 (let ((res (with-throw-handler
30 (delete-file name)))))
34 (define (scan-coding str)
39 ;; We don't simply seek back and rescan, because the encoding scan
40 ;; relies on the opportunistic filling of the input buffer, which
41 ;; doesn't happen after a seek.
42 (let* ((port (open-input-file name))
43 (res (file-encoding port)))
47 (with-test-prefix "block comments"
49 (pass-if-equal "first line"
51 (scan-coding "#! coding: iso-8859-1 !#"))
53 (pass-if-equal "first line no whitespace"
55 (scan-coding "#!coding:iso-8859-1!#"))
57 (pass-if-equal "second line"
59 (scan-coding "#! \n coding: iso-8859-1 !#"))
61 (pass-if-equal "second line no whitespace"
63 (scan-coding "#!\ncoding:iso-8859-1!#"))
65 (pass-if-equal "third line"
67 (scan-coding "#! \n coding: iso-8859-1 \n !#"))
69 (pass-if-equal "third line no whitespace"
71 (scan-coding "#!\ncoding:iso-8859-1\n!#")))
73 (with-test-prefix "line comment"
74 (pass-if-equal "first line, no whitespace, no nl"
76 (scan-coding ";coding:iso-8859-1"))
78 (pass-if-equal "first line, whitespace, no nl"
80 (scan-coding "; coding: iso-8859-1 "))
82 (pass-if-equal "first line, no whitespace, nl"
84 (scan-coding ";coding:iso-8859-1\n"))
86 (pass-if-equal "first line, whitespace, nl"
88 (scan-coding "; coding: iso-8859-1 \n"))
90 (pass-if-equal "second line, no whitespace, no nl"
92 (scan-coding "\n;coding:iso-8859-1"))
94 (pass-if-equal "second line, whitespace, no nl"
96 (scan-coding "\n; coding: iso-8859-1 "))
98 (pass-if-equal "second line, no whitespace, nl"
100 (scan-coding "\n;coding:iso-8859-1\n"))
102 (pass-if-equal "second line, whitespace, nl"
104 (scan-coding "\n; coding: iso-8859-1 \n"))
106 (pass-if-equal "http://bugs.gnu.org/16463"
107 ;; On Guile <= 2.0.9, this would return "ISO-8".
109 (scan-coding (string-append (make-string 485 #\space)
110 "; coding: ISO-8859-1"))))