diff options
| author | 2021-01-23 12:06:57 +0900 | |
|---|---|---|
| committer | 2021-01-23 12:06:57 +0900 | |
| commit | 828925c9c4723a4694345f0e0f0aa090af416925 (patch) | |
| tree | 30f545b9c7fa61977d2a3245e61d1970ebb64cd6 /test | |
| parent | Add formatting test for characters after :root (diff) | |
Use capture-stdout
Diffstat (limited to 'test')
| -rw-r--r-- | test/suite0.janet | 79 |
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) |
