edward

An extensible POSIX-compatible implementation of the ed(1) text editor

git clone https://git.8pit.net/edward.git

 1(import (edward util)
 2        (only (srfi 1) iota)
 3        (only (chicken file posix) port->fileno))
 4
 5(test-group "ports->lines"
 6  (test "multiple"
 7        '(("foo" "bar" "baz") . 12)
 8        (let ((port (open-input-string "foo\nbar\nbaz\n")))
 9          (port->lines port)))
10
11  (test "empty"
12        '(() . 0)
13        (let ((port (open-input-string "")))
14          (port->lines port))))
15
16(test-group "count-bytes"
17  (test "ascii string" 6 (count-bytes "foobar"))
18  (test "multibyte string" 2 (count-bytes "λ")))
19
20(test-group "path-join"
21  (test "empty" "" (path-join))
22  (test "single" "foo" (path-join "foo"))
23  (test "multiple" "foo/bar/baz" (path-join "foo" "bar" "baz")))
24
25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
27(define (call-with-input-fileno path proc)
28  (call-with-input-file
29    path
30    (lambda (port)
31      (proc (port->fileno port)))))
32
33(test-group "file-read-char"
34  (test "read single ascii character"
35        #\f
36        (call-with-input-fileno "testdata/ascii.txt"
37          (lambda (fileno)
38            (file-read-char fileno))))
39  (test "read end-of-file"
40        #f
41        (call-with-input-fileno "testdata/empty.txt"
42          (lambda (fileno)
43            (file-read-char fileno))))
44  ;; TODO: Test reading past EOF.
45  (test "read multiple characters"
46        (list #\f #\o #\o #\newline #f)
47        (call-with-input-fileno "testdata/ascii.txt"
48          (lambda (fileno)
49            (map (lambda (n)
50                   (file-read-char fileno))
51                   (iota 5)))))
52  (test "read multibyte sequence"
53        #\λ
54        (call-with-input-fileno "testdata/lambda.txt"
55          (lambda (fileno)
56            (file-read-char fileno))))
57  (test-error "invalid multibyte sequence"
58              (call-with-input-fileno "testdata/invalid-utf8-multibyte.txt"
59                (lambda (fileno)
60                  (file-read-char fileno)))))