def testCantRemoveSlashSlashInsideRegex(self): input = """ function a() { //a comment var x = /^\/\//; }""" output = minifyme.remove_line_comments(input) self.assertEqual(4, output.count('/')) self.assertTrue(output.find('/^\/\//;') > 0)
def testRemovingSlashSlashComments(self): input = """ //my wonderful comment function a() { //i'm inside my wonderful function var x = 1; }""" output = minifyme.remove_line_comments(input) self.assertEqual(0, output.count('/'))
def testCantRemoveSlashSlashInsideStrings(self): input = """ function a() { //a comment var x = "//foo" //bar; }""" output = minifyme.remove_line_comments(input) self.assertEqual(2, output.count('/')) self.assertTrue(output.find("//bar") < 0) self.assertTrue(output.find("//foo") > 0)
def test_removing_line_comments(self): input = r''' //first comment function a() { //second comment var x = 1; }''' output = minifyme.remove_line_comments(input) self.assertEqual(0, output.count('/')) self.assertTrue(output.find('first comment') < 0) self.assertTrue(output.find('second comment') < 0)
def test_cant_remove_multiline_comment_when_removing_line_comments(self): input = r'/* test*/' output = minifyme.remove_line_comments(input) self.assertTrue(output.find(r'/* test*/') >= 0)
def test_scapes_are_interpreted_inside_strings(self): input = r'var a = "bla\"test//!";' output = minifyme.remove_line_comments(input) self.assertTrue(output.find(r"a\"test//") > 0)
def test_cant_remove_double_slash_inside_regex(self): input = r'var x = /^\/\//;' output = minifyme.remove_line_comments(input) self.assertEqual(4, output.count(r'/')) self.assertTrue(output.find(r'/^\/\//;') > 0)
def test_cant_remove_double_slash_inside_strings(self): input = r'var x = "//foo" //bar;' output = minifyme.remove_line_comments(input) self.assertEqual(2, output.count(r'/')) self.assertTrue(output.find(r"//bar") < 0) self.assertTrue(output.find(r"//foo") > 0)