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>”.

bytesoutput
A
65A

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>”.

bytesoutput
A
65A
227 129 130A
240 159 152 132A

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>”.

valuecountoutput
A0
A1A
A2A
ABC2AB
ABC3ABC
ABC4ABC
A😄あ3A😄あ

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")

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 “AAA”.

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”.

bytescount
0
11
12
1 22
1 2 33
1 2 34

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”.

originalinputstartendoutput
011
0101
01011
0 01 21 2
0 01 201 2
0 01 2021 2
0 01 2011 0
0 01 210 1
0 0 0 01 2 3130 1 2 0
0 0 0 01 2 3 410 1 2 3
0 0 0 01 2 3 4140 1 2 3
originalinputstartendoutput
0 01 2031 2
0 0 0 01 2 3 4150 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”.