Raymond Toy pushed to branch issue-140-stream-element-type-two-way-stream at cmucl / cmucl

Commits:

2 changed files:

Changes:

  • src/code/stream.lisp
    ... ... @@ -295,8 +295,22 @@
    295 295
         (etypecase stream
    
    296 296
           #+unicode
    
    297 297
           (fd-stream (fd-stream-external-format stream))
    
    298
    -      (synonym-stream (stream-external-format
    
    299
    -		       (symbol-value (synonym-stream-symbol stream)))))
    
    298
    +      (broadcast-stream
    
    299
    +       ;; See http://www.lispworks.com/documentation/HyperSpec/Body/t_broadc.htm
    
    300
    +       :default)
    
    301
    +      (synonym-stream
    
    302
    +       ;; What should happen if (synonym-stream-symbol stream) is unbound?
    
    303
    +       (stream-external-format
    
    304
    +	(symbol-value (synonym-stream-symbol stream))))
    
    305
    +      (two-way-stream
    
    306
    +       ;; Not defined by CLHS, but useful to return the common format
    
    307
    +       ;; of the input and output streams when they're the same;
    
    308
    +       ;; otherwise return :default.
    
    309
    +       (let ((in-format (stream-external-format (two-way-stream-input-stream stream)))
    
    310
    +	     (out-format (stream-external-format (two-way-stream-output-stream stream))))
    
    311
    +	 (if (eql in-format out-format)
    
    312
    +	     in-format
    
    313
    +	     :default))))
    
    300 314
         ;; fundamental-stream
    
    301 315
         :default))
    
    302 316
     
    

  • tests/issues.lisp
    ... ... @@ -670,9 +670,42 @@
    670 670
     		 (err (relerr value answer)))
    
    671 671
     	    (assert-true (<= err eps) base err eps)))))))
    
    672 672
     
    
    673
    -(define-test issue.140
    
    673
    +;;; Test stream-external-format for various types of streams.
    
    674
    +
    
    675
    +;; Test two-way-stream where both streams have the same external
    
    676
    +;; format.
    
    677
    +(define-test issue.140.1
    
    678
    +    (:tag :issues)
    
    679
    +  (with-open-file (in (merge-pathnames "issues.lisp" cmucl-test-runner::*load-path*)
    
    680
    +		      :direction :input
    
    681
    +		      :external-format :utf-8)
    
    682
    +    (with-open-file (out "/tmp/output.tst"
    
    683
    +			 :direction :output
    
    684
    +			 :external-format :utf-8
    
    685
    +			 :if-exists :supersede)
    
    686
    +      (let ((two-way-stream (make-two-way-stream in out)))
    
    687
    +	(assert-equal :utf-8 (stream-external-format two-way-stream))))))
    
    688
    +
    
    689
    +;; Test two-way-stream where the two streams have the different
    
    690
    +;; external formats.
    
    691
    +(define-test issue.140.2
    
    674 692
         (:tag :issues)
    
    675
    -  (with-output-to-string (out)
    
    676
    -    (with-input-from-string (in "abc")
    
    693
    +  (with-open-file (in (merge-pathnames "issues.lisp" cmucl-test-runner::*load-path*)
    
    694
    +		      :direction :input
    
    695
    +		      :external-format :iso8859-1)
    
    696
    +    (with-open-file (out "/tmp/output.tst"
    
    697
    +			 :direction :output
    
    698
    +			 :external-format :utf-8
    
    699
    +			 :if-exists :supersede)
    
    677 700
           (let ((two-way-stream (make-two-way-stream in out)))
    
    678
    -	(assert-error 'type-error (stream-external-format two-way-stream))))))
    701
    +	(assert-equal :default (stream-external-format two-way-stream))))))
    
    702
    +
    
    703
    +;; Test synonym-stream returns the format of the underlying stream.
    
    704
    +(define-test issue.140.3
    
    705
    +    (:tag :issues)
    
    706
    +  (with-open-file (s (merge-pathnames "issues.lisp" cmucl-test-runner::*load-path*)
    
    707
    +		     :direction :input
    
    708
    +		     :external-format :iso8859-1)
    
    709
    +    (let ((syn (make-synonym-stream '*syn-stream*)))
    
    710
    +      (setf syn s)
    
    711
    +      (assert-equal :iso8859-1 (stream-external-format syn)))))