Commits

Anonymous committed a516c30

Corrected the behaviour of \n on tests and on code.

Comments (0)

Files changed (4)

 string_on_html = 'response.write("%s", escape=False)'
 
 def parse_string(text):
-    return text.replace('\\', '\\\\').replace('\n', '\\\\n').replace('"', '\\"')
+    return text.replace('\\', '\\\\').replace('\n', '\\n').replace('"', '\\"')
 
 
 def parse_line(line):

quotes_on.html

-response.write("'''\"\"\"\"'''", escape=False)
-a = 1
-response.write("'''\"\"\"\"'''\"\"\"\\n\"\"\"'''\"\"\"\\n", escape=False)

quotes_on_view.html

-'''""""'''{{a = 1}}'''""""'''"""
-"""'''"""

test_new_template.py

 DEBUG = False
 
 def do_it(self):
-    parsed_template = parse_template(self.input_)
     if DEBUG:
+        print '***** Input: *****'
         print self.input_
-        print '***'
+        print '***** Expected output: *****'
         print self.expected_output
-        print '***'
+        print '***** Returned output: *****'
+        parsed_template = parse_template(self.input_)
         print parsed_template
-        print '--------'
+        print '--------------------------------------'
+    else:
+        parsed_template = parse_template(self.input_)
     self.assertEquals(self.expected_output, parsed_template)
 
 
 it is cool!''')}}"""
         self.expected_output = """response.write("some plain text ", escape=False)
 response.write('''hi''')
-response.write("\\\\n", escape=False)
+response.write("\\n", escape=False)
 response.write(some_function('''testing web2py
 it is cool!'''))"""
         self.do_it()
         self.input_ = '''{
 { bla bla bla }
 }'''
-        self.expected_output = '''response.write("{\\\\n{ bla bla bla }\\\\n}", escape=False)'''
+        self.expected_output = '''response.write("{\\n{ bla bla bla }\\n}", escape=False)'''
         self.do_it()
 
 
     def test_new_line_on_HTML_should_be_backslashed_on_response_write(self):
         self.input_ = """
 """
-        self.expected_output = """response.write("\\\\n", escape=False)"""
+        self.expected_output = """response.write("\\n", escape=False)"""
         self.do_it()
 
 
     def test_all_kind_of_quotes_outside_python_code(self):
-        input_file = open('quotes_on_view.html', 'r')
-        output_file = open('quotes_on.html', 'r')
-        self.input_ = input_file.read()
-        self.expected_output = output_file.read()[:-1] # :-1 removes \n
-        input_file.close()
-        output_file.close()
+        self.input_ = """'''\"\"\"\"'''{{lot_of_quotes = True}}'''\"\"\"\"'''\"\"\"
+\"\"\"'''\"\"\""""
+        self.expected_output = """response.write("'''\\"\\"\\"\\"'''", escape=False)
+lot_of_quotes = True
+response.write("'''\\"\\"\\"\\"'''\\"\\"\\"\\n\\"\\"\\"'''\\"\\"\\"", escape=False)"""
         self.do_it()
 
 
 other HTML
 {{pass}}'''
         self.expected_output = '''if my_string == '}}':
-    response.write("\\\\nbla bla\\\\n", escape=False)
+    response.write("\\nbla bla\\n", escape=False)
 elif other_string == 'extend':
-    response.write("\\\\nother HTML\\\\n", escape=False)'''
+    response.write("\\nother HTML\\n", escape=False)'''
         self.do_it()
 
 
 other HTML
 {{pass}}'''
         self.expected_output = '''if my_string == '}}':
-    response.write("\\\\nbla bla\\\\n", escape=False)
+    response.write("\\nbla bla\\n", escape=False)
     if other_thing:
         a = 2
-        response.write("\\\\nfoo\\\\n", escape=False)
+        response.write("\\nfoo\\n", escape=False)
         for a in b:
-            response.write("\\\\nbar\\\\n", escape=False)
+            response.write("\\nbar\\n", escape=False)
     else:
         a = 2
-        response.write("\\\\nbaz\\\\n", escape=False)
+        response.write("\\nbaz\\n", escape=False)
 elif other_string == 'extend':
-    response.write("\\\\nother HTML\\\\n", escape=False)'''
+    response.write("\\nother HTML\\n", escape=False)'''
         self.do_it()
 
 
 b
 {{pass}}'''
         self.expected_output = '''if something:
-    response.write("\\\\nbla bla bla\\\\n", escape=False)
-response.write("\\\\nsome code\\\\n", escape=False)
+    response.write("\\nbla bla bla\\n", escape=False)
+response.write("\\nsome code\\n", escape=False)
 if a:
-    response.write("\\\\nb\\\\n", escape=False)'''
+    response.write("\\nb\\n", escape=False)'''
         self.do_it()