def get_comments_list(self): out = [] for filepath in self.iterate_matching_files(): src_file = open(filepath, 'r') contents = src_file.read() name = os.path.basename(filepath) src_file.close() parser = SCSSCommentParser(contents, name) blocks = parser.blocks() out.extend(blocks) logger.debug("%s: Found %d comment blocks" % (filepath, len(blocks))) return out
def setUp(self): self.source = """ This file is used for generic comment parsing across CSS, SCSS, SASS & LESS. There's single-line comment styles: // This comment block has comment identifiers on every line. // // Fun fact: this is Kyle's favorite comment syntax! There's block comment styles: /* This comment block is a block-style comment syntax. There's only two identifier across multiple lines. */ /* * This is another common multi-line comment style. * * It has stars at the begining of every line. */ Some people do crazy things like mix comment styles: // This comment has a /* comment */ identifier inside of it! /* Look at my //cool// comment art! */ Indented comments: // Indented single-line comment. /* Indented block comment. */""" self.parser = SCSSCommentParser(self.source)
class SCSSCommentParserTest(TestCase): def setUp(self): self.source = """ This file is used for generic comment parsing across CSS, SCSS, SASS & LESS. There's single-line comment styles: // This comment block has comment identifiers on every line. // // Fun fact: this is Kyle's favorite comment syntax! There's block comment styles: /* This comment block is a block-style comment syntax. There's only two identifier across multiple lines. */ /* * This is another common multi-line comment style. * * It has stars at the begining of every line. */ Some people do crazy things like mix comment styles: // This comment has a /* comment */ identifier inside of it! /* Look at my //cool// comment art! */ Indented comments: // Indented single-line comment. /* Indented block comment. */""" self.parser = SCSSCommentParser(self.source) def test_single_line_comment(self): self.assertTrue(self.parser.is_single_line_comment("// yuuuuup")) self.assertFalse(self.parser.is_single_line_comment("nooooope")) def test_start_multi_line_comment(self): self.assertTrue(self.parser.is_start_multi_line_comment("/* yuuuuup")) self.assertFalse(self.parser.is_start_multi_line_comment("nooooope")) def test_end_multi_line_comment(self): self.assertTrue(self.parser.is_end_multi_line_comment("yuuuuup */")) self.assertFalse(self.parser.is_end_multi_line_comment("nooooope")) def test_parse_single_line(self): self.assertEquals(self.parser.parse_single_line("// yuuuuup"), " yuuuuup") def test_parse_multi_line(self): self.assertEquals(self.parser.parse_multi_line("/* yuuuup */"), " yuuuup") def test_finds_single_line_comments(self): blocks = self.parser.blocks() self.assertIn(("This comment block has comment identifiers on every line.\n" "\n" "Fun fact: this is Kyle's favorite comment syntax!"), blocks) def test_finds_block_style_comments(self): blocks = self.parser.blocks() self.assertIn(("This comment block is a block-style comment syntax.\n" "\n" "There's only two identifier across multiple lines."), blocks) def test_finds_block_style_comments(self): blocks = self.parser.blocks() self.assertIn(("This comment block is a block-style comment syntax.\n" "\n" "There's only two identifier across multiple lines."), blocks) self.assertIn(("This is another common multi-line comment style.\n" "\n" "It has stars at the begining of every line."), blocks) def test_handles_mixed_styles(self): blocks = self.parser.blocks() self.assertIn("This comment has a /* comment */ identifier inside of it!", blocks) self.assertIn("Look at my //cool// comment art!", blocks) def test_handles_indented_comments(self): blocks = self.parser.blocks() self.assertIn("Indented single-line comment.", blocks) self.assertIn("Indented block comment.", blocks)
class SCSSCommentParserTest(TestCase): def setUp(self): self.source = """ This file is used for generic comment parsing across CSS, SCSS, SASS & LESS. There's single-line comment styles: // This comment block has comment identifiers on every line. // // Fun fact: this is Kyle's favorite comment syntax! There's block comment styles: /* This comment block is a block-style comment syntax. There's only two identifier across multiple lines. */ /* * This is another common multi-line comment style. * * It has stars at the begining of every line. */ Some people do crazy things like mix comment styles: // This comment has a /* comment */ identifier inside of it! /* Look at my //cool// comment art! */ Indented comments: // Indented single-line comment. /* Indented block comment. */""" self.parser = SCSSCommentParser(self.source) def test_single_line_comment(self): self.assertTrue(self.parser.is_single_line_comment("// yuuuuup")) self.assertFalse(self.parser.is_single_line_comment("nooooope")) def test_start_multi_line_comment(self): self.assertTrue(self.parser.is_start_multi_line_comment("/* yuuuuup")) self.assertFalse(self.parser.is_start_multi_line_comment("nooooope")) def test_end_multi_line_comment(self): self.assertTrue(self.parser.is_end_multi_line_comment("yuuuuup */")) self.assertFalse(self.parser.is_end_multi_line_comment("nooooope")) def test_parse_single_line(self): self.assertEquals(self.parser.parse_single_line("// yuuuuup"), " yuuuuup") def test_parse_multi_line(self): self.assertEquals(self.parser.parse_multi_line("/* yuuuup */"), " yuuuup") def test_finds_single_line_comments(self): blocks = self.parser.blocks() self.assertIn( ("This comment block has comment identifiers on every line.\n" "\n" "Fun fact: this is Kyle's favorite comment syntax!"), blocks) def test_finds_block_style_comments(self): blocks = self.parser.blocks() self.assertIn(("This comment block is a block-style comment syntax.\n" "\n" "There's only two identifier across multiple lines."), blocks) def test_finds_block_style_comments(self): blocks = self.parser.blocks() self.assertIn(("This comment block is a block-style comment syntax.\n" "\n" "There's only two identifier across multiple lines."), blocks) self.assertIn(("This is another common multi-line comment style.\n" "\n" "It has stars at the begining of every line."), blocks) def test_handles_mixed_styles(self): blocks = self.parser.blocks() self.assertIn( "This comment has a /* comment */ identifier inside of it!", blocks) self.assertIn("Look at my //cool// comment art!", blocks) def test_handles_indented_comments(self): blocks = self.parser.blocks() self.assertIn("Indented single-line comment.", blocks) self.assertIn("Indented block comment.", blocks)