io: Fix unneeded escaping of forward slash
authorDov Murik <dov.murik@gmail.com>
Tue, 23 Jul 2019 07:21:27 +0000 (10:21 +0300)
committerDov Murik <dov.murik@gmail.com>
Tue, 23 Jul 2019 07:23:11 +0000 (10:23 +0300)
Instead of using Io's `asJson` method which escapes forward slashes,
implement our own string escaping code so it fits the Mal requirements.

The relevant step1 test was modified from soft to hard.

io/MalTypes.io
tests/step1_read_print.mal

index afe0a75..a5b7c0c 100644 (file)
@@ -7,7 +7,9 @@ Number malPrint := method(readable, self asString)
 
 // Io strings are of type Sequence
 Sequence malPrint := method(readable,
-    if(readable, self asString asJson, self asString)
+    if(readable,
+       "\"" .. (self asString asMutable replaceSeq("\\", "\\\\") replaceSeq("\"", "\\\"") replaceSeq("\n", "\\n")) .. "\"",
+       self asString)
 )
 
 MalMeta := Object clone do(
index 913a412..11dc4bf 100644 (file)
@@ -98,6 +98,8 @@ false
 ;=>","
 "-"
 ;=>"-"
+"/"
+;=>"/"
 ":"
 ;=>":"
 ";"
@@ -275,6 +277,3 @@ false
 ;; fantom fails this one
 "!"
 ;=>"!"
-;; io fails this one
-"/"
-;=>"/"