aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorMichael Camilleri <mike@inqk.net>2021-01-23 12:06:57 +0900
committerMichael Camilleri <mike@inqk.net>2021-01-23 12:06:57 +0900
commit828925c9c4723a4694345f0e0f0aa090af416925 (patch)
tree30f545b9c7fa61977d2a3245e61d1970ebb64cd6 /test
parentAdd formatting test for characters after :root (diff)
Use capture-stdout
Diffstat (limited to 'test')
-rw-r--r--test/suite0.janet79
1 files changed, 43 insertions, 36 deletions
diff --git a/test/suite0.janet b/test/suite0.janet
index df1d7ef..a7eab5a 100644
--- a/test/suite0.janet
+++ b/test/suite0.janet
@@ -4,43 +4,50 @@
(start-suite 0)
# only testing format-print as other fns are dependent on it
-(def b @"")
-(with-dyns [:out b]
- (fmt/format-print "(\n print\n \"HOHOHO\")"))
-(assert (deep= b @"(print\n \"HOHOHO\")\n") "format-print")
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "(\n print\n \"HOHOHO\")")))
+ (assert (= res [nil "(print\n \"HOHOHO\")\n"]) "format-print"))
# regresion with comment in the collection literals
-(buffer/clear b)
-(with-dyns [:out b]
- (fmt/format-print "{:a 0\n:b 1 # test comment\n}"))
-(assert (deep= b @"{:a 0\n :b 1 # test comment\n}\n") "format-print comment in collection 1")
-
-(buffer/clear b)
-(with-dyns [:out b]
- (fmt/format-print "[:a 0\n:b\n# test comment\n]"))
-(assert (deep= b @"[:a 0\n :b\n # test comment\n]\n") "format-print comment in collection 2")
-
-(buffer/clear b)
-(with-dyns [:out b]
- (fmt/format-print "()"))
-(assert (deep= b @"()\n") "format-print ()")
-
-(buffer/clear b)
-(with-dyns [:out b]
- (fmt/format-print "( )"))
-(assert (deep= b @"()\n") "format-print ( )")
-
-(buffer/clear b)
-(with-dyns [:out b]
- (fmt/format-print "# a comment"))
-(assert (deep= b @"# a comment\n\n") "format-print only comment")
-
-(buffer/clear b)
-(with-dyns [:out b]
- (try
- (fmt/format-print "print )")
- ([err]
- (print "error"))))
-(assert (deep= b @"error\n") "format-print errors with unbalanced parenthesis")
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "{:a 0\n:b 1 # test comment\n}")))
+ (assert (= res [nil "{:a 0\n :b 1 # test comment\n}\n"]) "format-print comment in collection 1"))
+
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "[:a 0\n:b\n# test comment\n]")))
+ (assert (= res [nil "[:a 0\n :b\n # test comment\n]\n"]) "format-print comment in collection 2"))
+
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "()")))
+ (assert (= res [nil "()\n"]) "format-print empty form"))
+
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "( )")))
+ (assert (= [nil "()\n"]) "format-print empty form with whitespace"))
+
+(do
+ (def res
+ (capture-stdout
+ (fmt/format-print "# a comment")))
+ (assert (= [nil "# a comment\n\n"]) "format-print only comment"))
+
+(do
+ (def res
+ (capture-stdout
+ (try
+ (fmt/format-print "print )")
+ ([err]
+ (print "error")))))
+ (assert (= [nil "error\n"]) "format-print errors with unbalanced parenthesis"))
(end-suite)