Skip to content

Commit 58bb61c

Browse files
authored
String formatting function tests (#403)
1 parent 69aab7f commit 58bb61c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/basilisp/core_macros_test.lpy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@
330330
(:a x)
331331
(inc x)))))
332332

333+
(deftest with-in-str-test
334+
(is (= "Hi I'm a string" (with-in-str "\"Hi I'm a string\"" (read)))))
335+
336+
(deftest with-out-str-test
337+
(is (= "Hello, Chris!"
338+
(with-out-str
339+
(printf "Hello, %s!" "Chris"))))
340+
(is (= "Hello, Chris and Rich!"
341+
(with-out-str
342+
(printf "Hello, %s and %s!" "Chris" "Rich"))))
343+
(is (= "Hello, Chris and Rich!"
344+
(with-out-str
345+
(printf "Hello, %(first)s and %(second)s!"
346+
{"first" "Chris" "second" "Rich"})))))
347+
333348
(deftest fn-sequential-destructuring
334349
(testing "destructuring first"
335350
(let [v [:a :b :c :d]

tests/basilisp/core_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,16 @@ def test_shuffle(self, coll):
12791279
assert set(coll) == set(core.shuffle(coll))
12801280

12811281

1282+
def test_string_format():
1283+
assert "Hello, Chris!" == core.format_("Hello, %s!", "Chris")
1284+
assert "Hello, Chris and Rich!" == core.format_(
1285+
"Hello, %s and %s!", "Chris", "Rich"
1286+
)
1287+
assert "Hello, Chris and Rich!" == core.format_(
1288+
"Hello, %(first)s and %(second)s!", {"first": "Chris", "second": "Rich"}
1289+
)
1290+
1291+
12821292
def test_merge():
12831293
assert None is core.merge()
12841294
assert lmap.Map.empty() == core.merge(lmap.Map.empty())

0 commit comments

Comments
 (0)