]> gitweb.factorcode.org Git - factor.git/blob - basis/interpolate/interpolate-tests.factor
interpolate: allow mixing of named variables and stack arguments.
[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" "${0} ${1}" interpolate ] unit-test
7 { "B A" } [ "A" "B" "${1} ${0}" interpolate ] unit-test
8 { "C A" } [ "A" "B" "C" "${2} ${0}" interpolate ] unit-test
9
10 { "Hello, Jane." } [
11     "Jane" "name" set
12     "Hello, ${name}." interpolate
13 ] unit-test
14
15 { "Mr. John" } [
16     "John" "name" set
17     "Mr." "${0} ${name}" interpolate
18 ] unit-test
19
20 { "Sup Dawg, we heard you liked rims, so we put rims on your rims so you can roll while you roll." } [
21     "Dawg" "name" set
22     "rims" "noun" set
23     "roll" "verb" set
24     "Sup ${name}, we heard you liked ${noun}, so we put ${noun} on your ${noun} so you can ${verb} while you ${verb}." interpolate
25 ] unit-test
26
27 { "Oops, I accidentally the whole economy..." } [
28     [let
29         "economy" :> noun
30         "accidentally" [ I[ Oops, I ${0} the whole ${noun}...]I ] with-string-writer
31     ]
32 ] unit-test