... |
... |
@@ -34,3 +34,59 @@ |
34
|
34
|
(setf s (open *test-file*))
|
35
|
35
|
(file-length s))
|
36
|
36
|
(delete-file *test-file*))))
|
|
37
|
+
|
|
38
|
+(define-test file-position.1
|
|
39
|
+ (:tag :issues)
|
|
40
|
+ ;; Create a short test file
|
|
41
|
+ (let ((test-file (merge-pathnames #p"file-pos.txt" *test-path*)))
|
|
42
|
+ (with-open-file (s test-file
|
|
43
|
+ :direction :output
|
|
44
|
+ :if-exists :supersede)
|
|
45
|
+ (write-string "aaaaaa" s)
|
|
46
|
+ (write-char #\newline s))
|
|
47
|
+ (with-open-file (s test-file)
|
|
48
|
+ (read-line s)
|
|
49
|
+ (assert-true (file-position s 0))
|
|
50
|
+ (assert-equal (file-position s) 0))))
|
|
51
|
+
|
|
52
|
+(define-test file-position.2
|
|
53
|
+ (:tag :issues)
|
|
54
|
+ ;; Create a test file just longer than the internal in-buffer length
|
|
55
|
+ ;; and the first line is more than 512 characters long.
|
|
56
|
+ (let ((test-file (merge-pathnames #p"file-pos.txt" *test-path*)))
|
|
57
|
+ (with-open-file (s test-file
|
|
58
|
+ :direction :output
|
|
59
|
+ :if-exists :supersede)
|
|
60
|
+ (write-string (make-string 512 :initial-element #\a) s)
|
|
61
|
+ (write-char #\newline s)
|
|
62
|
+ (write-string "zzzzz" s)
|
|
63
|
+ (write-char #\newline s))
|
|
64
|
+ (with-open-file (s test-file)
|
|
65
|
+ (read-line s)
|
|
66
|
+ (assert-true (file-position s 0))
|
|
67
|
+ (assert-equal (file-position s) 0))))
|
|
68
|
+
|
|
69
|
+(define-test file-position.3
|
|
70
|
+ (:tag :issues)
|
|
71
|
+ ;; Create a test file just longer than the internal in-buffer
|
|
72
|
+ ;; length. This tests the case where the in-buffer does not have
|
|
73
|
+ ;; enough octets to form a complete character. (See comment in
|
|
74
|
+ ;; fd-stream-file-position.
|
|
75
|
+ (let ((test-file (merge-pathnames #p"file-pos.txt" *test-path*)))
|
|
76
|
+ (with-open-file (s test-file
|
|
77
|
+ :external-format :utf-8
|
|
78
|
+ :direction :output
|
|
79
|
+ :if-exists :supersede)
|
|
80
|
+ (write-char #\a s)
|
|
81
|
+ ;; STR is a string consisting of the single codepoint #x11000
|
|
82
|
+ ;; which is 4 octets when encoded using utf-8.
|
|
83
|
+ (let ((str (lisp::codepoints-string '(#x11000))))
|
|
84
|
+ (dotimes (k 128)
|
|
85
|
+ (write-string str s)))
|
|
86
|
+ (write-char #\newline s)
|
|
87
|
+ (write-string "zzzzz" s)
|
|
88
|
+ (write-char #\newline s))
|
|
89
|
+ (with-open-file (s test-file :external-format :utf-8)
|
|
90
|
+ (read-line s)
|
|
91
|
+ (assert-true (file-position s 0))
|
|
92
|
+ (assert-equal (file-position s) 0)))) |