Skip to content

Read

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (read-u8))

And a file named “input.txt” with:

A

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (read-u8))
(write-u8 (read-u8))
(write-u8 (read-u8))

And a file named “input.txt” with:

ABC

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (peek-u8))

And a file named “input.txt” with:

A

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (peek-u8))
(write-u8 (peek-u8))

And a file named “input.txt” with:

A

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “AA”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (peek-u8))
(write-u8 (read-u8))
(write-u8 (read-u8))

And a file named “input.txt” with:

AB

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “AAB”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (u8-ready? (open-input-bytevector #u8(<bytes>))) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

bytes output
A
65 A

Given a file named “main.scm” with:

(import (scheme base))
(write-char (read-char))

And a file named “input.txt” with:

<value>

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “<value>”.

value
A
a
~
д
😄

Given a file named “main.scm” with:

(import (scheme base))
(write-char (peek-char))

And a file named “input.txt” with:

<value>

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “<value>”.

value
A
a
~
д
😄

Given a file named “main.scm” with:

(import (scheme base))
(write-char (peek-char))
(write-char (peek-char))

And a file named “input.txt” with:

A

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “AA”.

Given a file named “main.scm” with:

(import (scheme base))
(write-char (peek-char))
(write-char (read-char))
(write-char (read-char))

And a file named “input.txt” with:

AB

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “AAB”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (char-ready? (open-input-bytevector #u8(<bytes>))) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

bytes output
A
65 A
227 129 130 A
240 159 152 132 A

Given a file named “main.scm” with:

(import (scheme base))
(write-string (read-string <count>))

And a file named “input.txt” with “<value>”

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “<output>”.

value count output
A 0
A 1 A
A 2 A
ABC 2 AB
ABC 3 ABC
ABC 4 ABC
A😄あ 3 A😄あ

Given a file named “main.scm” with:

(import (scheme base))
(define (check x)
(write-u8 (if (equal? (read-line) x) 65 66)))
(check "foo")
(check "bar")
(check "baz")
(check (eof-object))

And a file named “input.txt” with:

foo
bar
baz

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “AAAA”.

Given a file named “main.scm” with:

(import (scheme base))
(parameterize ((current-input-port (open-input-bytevector #u8(<bytes>))))
(write-u8 (if (equal? (read-bytevector <count>) #u8(<bytes>)) 65 66)))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

bytes count
0
1 1
1 2
1 2 2
1 2 3 3
1 2 3 4

Given a file named “main.scm” with:

(import (scheme base))
(define xs (bytevector <original>))
(read-bytevector! xs (open-input-bytevector #u8(<input>)) <start> <end>)
(write-u8 (if (equal? xs #u8(<output>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

original input start end output
0 1 1
0 1 0 1
0 1 0 1 1
0 0 1 2 1 2
0 0 1 2 0 1 2
0 0 1 2 0 2 1 2
0 0 1 2 0 1 1 0
0 0 1 2 1 0 1
0 0 0 0 1 2 3 1 3 0 1 2 0
0 0 0 0 1 2 3 4 1 0 1 2 3
0 0 0 0 1 2 3 4 1 4 0 1 2 3
original input start end output
0 0 1 2 0 3 1 2
0 0 0 0 1 2 3 4 1 5 0 1 2 3

Given a file named “main.scm” with:

(import (scheme base) (scheme read))
(write-u8 (if (equal? (read) '<value>) 65 66))

And a file named “input.txt” with:

<value>

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “A”.

value
#f
#t
0
1
2
42
-1
-2
-42
a
x
foo
#\A
#\newline
“”
“foo”
“Hello, world!”
“\n\r\t”
()
(1)
(1 2)
(1 2 3)
(1 . 2)
(1 2 . 3)
(foo)
(foo bar)
(foo bar baz)
(foo . bar)
(foo bar . baz)
#(foo)
#(foo bar)
#(foo bar baz)
#u8()
#u8(1)
#u8(1 2)
#u8(1 2 3)

Given a file named “main.scm” with:

(import (scheme base) (scheme read))
(write-u8 (if (equal? (read (current-input-port)) 'foo) 65 66))

And a file named “input.txt” with:

foo

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (scheme read))
(read)

And a file named “input.txt” with:

(foo

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should not be 0

And the stdout should contain exactly “”

And the stderr should contain “) expected”.

Read a list without an opening parenthesis

Section titled “Read a list without an opening parenthesis”

Given a file named “main.scm” with:

(import (scheme base) (scheme read))
(read)

And a file named “input.txt” with:

)

When I run stak main.scm interactively

And I pipe in the file “input.txt”

Then the exit status should not be 0

And the stdout should contain exactly “”

And the stderr should contain “expression expected”.