]> gitweb.factorcode.org Git - factor.git/blob - basis/interpolate/interpolate-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / basis / interpolate / interpolate-tests.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: interpolate io.streams.string namespaces tools.test locals ;
4 IN: interpolate.tests
5
6 { "A B" } [ "A" "B" "${1} ${0}" interpolate>string ] unit-test
7 { "B A" } [ "A" "B" "${0} ${1}" interpolate>string ] unit-test
8 { "C A" } [ "A" "B" "C" "${0} ${2}" interpolate>string ] unit-test
9 { "C B A" } [ "A" "B" "C" "${} ${1} ${2}" interpolate>string ] unit-test
10
11 { "Hello, Jane." } [
12     "Jane" "name" set
13     "Hello, ${name}." interpolate>string
14 ] unit-test
15
16 { "Mr. John" } [
17     "John" "name" set
18     "Mr." "${0} ${name}" interpolate>string
19 ] unit-test
20
21 { "Hello, Mr. Anderson" } [
22     "Mr." "Anderson"
23     "Hello, ${} ${}" interpolate>string
24 ] unit-test
25
26 { "Mixing named and stack variables... stacks are cool!" } [
27     "cool!" "what" set
28     "named" "stack"
29     "Mixing ${} and ${} variables... ${0}s are ${what}"
30     interpolate>string
31 ] unit-test
32
33 { "Sup Dawg, we heard you liked rims, so we put rims on your rims so you can roll while you roll." } [
34     "Dawg" "name" set
35     "rims" "noun" set
36     "roll" "verb" set
37     "Sup ${name}, we heard you liked ${noun}, so we put ${noun} on your ${noun} so you can ${verb} while you ${verb}." interpolate>string
38 ] unit-test
39
40 { "Oops, I accidentally the whole economy..." } {
41     [let
42         "economy" :> noun
43         "accidentally" [ I[ Oops, I ${0} the whole ${noun}...]I ] with-string-writer
44     }
45 ] unit-test