tool: new program nitunit.nit
[nit.git] / src / literal.nit
index 67f1120..f98c209 100644 (file)
@@ -55,10 +55,8 @@ private class LiteralVisitor
 
        redef fun visit(n)
        do
-               if n != null then
-                       n.accept_literal(self)
-                       n.visit_all(self)
-               end
+               n.accept_literal(self)
+               n.visit_all(self)
        end
 end
 
@@ -104,7 +102,9 @@ redef class AStringFormExpr
        redef fun accept_literal(v)
        do
                var txt = self.n_string.text
-               self.value = txt.substring(1, txt.length-2).unescape_nit
+               var skip = 1
+               if txt[0] == txt[1] and txt.length >= 6 then skip = 3
+               self.value = txt.substring(skip, txt.length-(2*skip)).unescape_nit
        end
 end
 
@@ -113,10 +113,10 @@ redef class String
        #
        # Example:
        #     var s = "\\n"
-       #     print s.length # -> 2
+       #     assert s.length        ==  2
        #     var u = s.unescape_nit
-       #     print s.length # -> 1
-       #     print s[0].ascii # -> 10 (the ASCII value of the "new line" character)
+       #     assert u.length        ==  1
+       #     assert u[0].ascii      ==  10 # (the ASCII value of the "new line" character)
        fun unescape_nit: String
        do
                var res = new Buffer.with_capacity(self.length)