1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-28 16:00:22 +02:00
guile/test-suite/tests/coding.test
Mark H Weaver 9a334eb3ab Do not scan for coding declarations in open-file.
* libguile/fports.c (scm_open_file): Do not scan for coding
  declarations.  Replace 'use_encoding' local variable with
  'binary'.  Update documentation string.

* module/ice-9/psyntax.scm (include): Add the same file-encoding
  logic that's used in compile-file and scm_primitive_load.

* module/ice-9/psyntax-pp.scm: Regenerate.

* doc/ref/api-io.texi (File Ports): Update docs.

* test-suite/tests/ports.test: Change "open-file HONORS file coding
  declarations" test to "open-file IGNORES file coding declaration".

* test-suite/tests/coding.test (scan-coding): Use 'file-encoding' to
  scan for the encoding, since 'open-input-file' no longer does so.
2013-04-07 10:11:41 -04:00

104 lines
3.4 KiB
Scheme

;;;; coding.test --- test suite for coding declarations. -*- mode: scheme -*-
;;;;
;;;; Copyright (C) 2011, 2013 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(define-module (test-coding)
#:use-module (test-suite lib))
(define (with-temp-file proc)
(let* ((name (string-copy "/tmp/coding-test.XXXXXX"))
(port (mkstemp! name)))
(let ((res (with-throw-handler
#t
(lambda ()
(proc name port))
(lambda _
(delete-file name)))))
(delete-file name)
res)))
(define (scan-coding str)
(with-temp-file
(lambda (name port)
(display str port)
(close port)
;; We don't simply seek back and rescan, because the encoding scan
;; relies on the opportunistic filling of the input buffer, which
;; doesn't happen after a seek.
(let* ((port (open-input-file name))
(res (file-encoding port)))
(close-port port)
res))))
(with-test-prefix "block comments"
(pass-if "first line"
(equal? (scan-coding "#! coding: iso-8859-1 !#")
"ISO-8859-1"))
(pass-if "first line no whitespace"
(equal? (scan-coding "#!coding:iso-8859-1!#")
"ISO-8859-1"))
(pass-if "second line"
(equal? (scan-coding "#! \n coding: iso-8859-1 !#")
"ISO-8859-1"))
(pass-if "second line no whitespace"
(equal? (scan-coding "#!\ncoding:iso-8859-1!#")
"ISO-8859-1"))
(pass-if "third line"
(equal? (scan-coding "#! \n coding: iso-8859-1 \n !#")
"ISO-8859-1"))
(pass-if "third line no whitespace"
(equal? (scan-coding "#!\ncoding:iso-8859-1\n!#")
"ISO-8859-1")))
(with-test-prefix "line comments"
(pass-if "first line, no whitespace, no nl"
(equal? (scan-coding ";coding:iso-8859-1")
"ISO-8859-1"))
(pass-if "first line, whitespace, no nl"
(equal? (scan-coding "; coding: iso-8859-1 ")
"ISO-8859-1"))
(pass-if "first line, no whitespace, nl"
(equal? (scan-coding ";coding:iso-8859-1\n")
"ISO-8859-1"))
(pass-if "first line, whitespace, nl"
(equal? (scan-coding "; coding: iso-8859-1 \n")
"ISO-8859-1"))
(pass-if "second line, no whitespace, no nl"
(equal? (scan-coding "\n;coding:iso-8859-1")
"ISO-8859-1"))
(pass-if "second line, whitespace, no nl"
(equal? (scan-coding "\n; coding: iso-8859-1 ")
"ISO-8859-1"))
(pass-if "second line, no whitespace, nl"
(equal? (scan-coding "\n;coding:iso-8859-1\n")
"ISO-8859-1"))
(pass-if "second line, whitespace, nl"
(equal? (scan-coding "\n; coding: iso-8859-1 \n")
"ISO-8859-1")))