Skip to content

String

Given a file named “main.scm” with:

(import (scheme base))
(write-string "Hello, world!")

When I successfully run stak main.scm

Then the stdout should contain exactly “Hello, world!”.

Given a file named “main.scm” with:

(import (scheme base))
(write-string (string #\A #\B #\C))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each write-char (string->list "Hello, world!"))

When I successfully run stak main.scm

Then the stdout should contain exactly “Hello, world!”.

Given a file named “main.scm” with:

(import (scheme base))
(write-string (list->string (string->list "Hello, world!")))

When I successfully run stak main.scm

Then the stdout should contain exactly “Hello, world!”.

Given a file named “main.scm” with:

(import (scheme base))
(write-string (string-append <values>))

When I successfully run stak main.scm

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

valuesoutput
""
"foo”foo
”app” “le”apple
”dis” “cov” “ery”discovery

Given a file named “main.scm” with:

(import (scheme base))
(write-char (string-ref "<string>" <index>))

When I successfully run stak main.scm

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

stringindexoutput
a0a
ab0a
ab1b
abc0a
abc1b
abc2c

Given a file named “main.scm” with:

(import (scheme base))
(define xs (string-copy "aaa"))
(string-set! xs <index> #\<character>)
(write-u8 (if (equal? xs "<output>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

indexcharacteroutput
0bbaa
1baba
2baab
0aaaa
indexcharacteroutput
1😄a😄a

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (string-length "<value>") <length>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuelength
0
a1
aa2
aaa3

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (equal? (substring "<value>" <start> <end>) "<output>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuestartendoutput
00
a00
a01a
ab00
ab01a
ab12b
ab02ab
abc00
abc01a
abc12b
abc23c
abc02ab
abc13bc
abc03abc

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (string-length "<value>") <length>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuelength
0
a1
aa2
aaa3

Given a file named “main.scm” with:

(import (scheme base))
(define xs (string-copy "<to>"))
(string-copy! xs <at> "<from>" <start> <end>)
(write-u8 (if (equal? xs "<output>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

toatfromstartendoutput
A0A
ABC0DEFDEF
ABC1DEADE
ABC2DABD
ABCDE1FGHAFGHE
ABCD1EFGH1AFGH
ABCD1EFGH13AFGD

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (string-length (make-string <length>)) <length>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

length
0
1
2
3

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (equal? (make-string <length> <character>) "<output>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

lengthcharacteroutput
0#\A
1#\AA
2#\AAA
3#\AAAA
0#\B
1#\BB
2#\BBB
3#\BBBB

Given a file named “main.scm” with:

(import (scheme base))
(string-for-each write-char "ABC")

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8
(if (equal? (string-map (lambda (x) (integer->char (+ 1 (char->integer x)))) "ABC") "BCD")
65
66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string=? "<value>" "<value>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

value
a
ab
abc

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string=? "<left>" "<right>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “B”.

leftright
a
a
ab
aab
aba
aaab
aaaaa
aaaaa
aaaaab
aabaaa

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<procedure> <strings>) 65 66))

When I successfully run stak main.scm

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

procedurestringsoutput
string<?"" ""B
string<?"" “a”A
string<?“a” “b”A
string<?“a” “b” “c”A
string<?“a” “aa”A
string<?“aa” “aa”B
string<?“aa” “ab”A
string<?“aa” “aaa”A
string<?“aaa” “aab”A
string>?"" ""B
string>?“a” ""A
string>?“a” “a”B
string>?“b” “a”A
string>?“c” “b” “a”A
string>?“aa” “a”A
string>?“aa” “aa”B
string>?“ab” “aa”A
string>?“ba” “aa”A
string>?“ba” “ab”A
string<=?“aa” “aa”A
string<=?“aa” “ab”A
string<=?“ab” “aa”B
string<=?“aa” “aa” “ab”A
string>=?“aa” “aa”A
string>=?“aa” “ab”B
string>=?“ab” “aa”A
string>=?“ab” “aa” “aa”A

Given a file named “main.scm” with:

(import (scheme base) (scheme char))
(write-u8 (if (<procedure> <strings>) 65 66))

When I successfully run stak main.scm

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

procedurestringsoutput
string-ci<?"" ""B
string-ci<?"" “a”A
string-ci<?“a” “B”A
string-ci<?“a” “B” “C”A
string-ci<?“a” “AA”A
string-ci<?”AA” “aa”B
string-ci<?“aa” “AB”A
string-ci<?“aa” “AAA”A
string-ci<?“aaa” “AAB”A
string-ci>?"" ""B
string-ci>?“a” ""A
string-ci>?”A” “a”B
string-ci>?”B” “a”A
string-ci>?”C” “b” “a”A
string-ci>?”AA” “a”A
string-ci>?“aa” “AA”B
string-ci>?”AB” “aa”A
string-ci>?”BA” “aa”A
string-ci>?”BA” “ab”A
string-ci<=?“aa” “AA”A
string-ci<=?“aa” “AB”A
string-ci<=?”AB” “aa”B
string-ci<=?“aa” “AA” “AB”A
string-ci>=?”AA” “aa”A
string-ci>=?“aa” “AB”B
string-ci>=?”AB” “aa”A
string-ci>=?”AB” “aa” “aa”A

Given a file named “main.scm” with:

(import (scheme base))
(write-string (vector->string #(<characters>) <range>))

When I successfully run stak main.scm

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

charactersrangeoutput
#\AA
#\A #\B #\CABC
#\A #\B #\C0ABC
#\A #\B #\C0 2AB
#\A #\B #\C1 3BC
#\A #\B #\C1 2B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (equal? (string->vector "<string>" <range>) #(<characters>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

stringrangecharacters
A#\A
ABC#\A #\B #\C
ABC0#\A #\B #\C
ABC0 2#\A #\B
ABC1 3#\B #\C
ABC1 2#\B

Given a file named “main.scm” with:

(import (scheme base))
(define xs "<string>")
(write-u8 (if (equal? (utf8->string (string->utf8 xs)) xs) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

string
A
ABC
Aあ😄

Given a file named “main.scm” with:

(import (scheme base) (scheme char))
(write-u8 (if (equal? (<predicate> "<input>") "<output>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

predicateinputoutput
string-downcaseAbab
string-foldcaseAbab
string-upcaseAbAB

Given a file named “main.scm” with:

(import (scheme base))
(define xs (string-copy "<string>"))
(string-fill! xs <arguments>)
(write-string xs)

When I successfully run stak main.scm

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

stringargumentsoutput
A#\aa
AB#\a 0aa
AB#\a 1Aa
ABC#\aaaa
ABCD#\a 1 3AaaD