Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cogapp/cogapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def get_code(self):
# If the markers and lines all have the same prefix
# (end-of-line comment chars, for example),
# then remove it from all the lines.
for idx, marker in enumerate(self.markers):
self.markers[idx] = marker.replace(self.options.begin_spec, "").replace(
self.options.end_spec, ""
)
pref_in = common_prefix(self.markers + self.lines)
if pref_in:
self.markers = [line.replace(pref_in, "", 1) for line in self.markers]
Expand Down
24 changes: 24 additions & 0 deletions cogapp/test_cogapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ def test_prefixed_indented_code(self):
infile = reindent_block(infile)
self.assertEqual(Cog().process_string(infile), infile)

def test_markers_overlapping_prefix(self):
infile = """\
// cog-begin
// cog.outl('lorem ipsum')
// cog-middle
// cog-end
"""

outfile = """\
// cog-begin
// cog.outl('lorem ipsum')
// cog-middle
lorem ipsum
// cog-end
"""

infile = reindent_block(infile)
outfile = reindent_block(outfile)
cog = Cog()
cog.options.begin_spec = "cog-begin"
cog.options.end_spec = "cog-middle"
cog.options.end_output = "cog-end"
self.assertEqual(cog.process_string(infile), outfile)

def test_bogus_prefix_match(self):
infile = """\
prologue
Expand Down
Loading