Read
Read a byte
Section titled “Read a byte”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”.
Read bytes
Section titled “Read bytes”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”.
Peek a byte
Section titled “Peek a byte”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”.
Peek a byte multiple times
Section titled “Peek a byte multiple times”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”.
Peek and read bytes
Section titled “Peek and read bytes”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”.
Read a character
Section titled “Read a character”Given a file named “main.scm” with:
(import (scheme base))
(write-char (read-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 “A”.
Peek a character
Section titled “Peek a character”Given a file named “main.scm” with:
(import (scheme base))
(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 “A”.
Peek a character multiple times
Section titled “Peek a character multiple times”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”.
Peek and read characters
Section titled “Peek and read characters”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”.
Read a value
Section titled “Read a value”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”.
Examples
Section titled “Examples”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) |
Read from a port
Section titled “Read from a port”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”.
Read a list without a closing parenthesis
Section titled “Read a list without a closing parenthesis”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”.