Commit 58a64553 authored by Ryan Pavlik's avatar Ryan Pavlik

Add C++ line comment filter with tests

parent 52da10d9
...@@ -67,3 +67,13 @@ def do_c_block_comment(s, begin_chars='/*', line_prefix=' * ', end_chars=' */'): ...@@ -67,3 +67,13 @@ def do_c_block_comment(s, begin_chars='/*', line_prefix=' * ', end_chars=' */'):
""" """
return do_prefix_block(s, line_prefix=line_prefix, blank_line_prefix=line_prefix.rstrip(), return do_prefix_block(s, line_prefix=line_prefix, blank_line_prefix=line_prefix.rstrip(),
block_begin=(begin_chars + '\n'), block_end=('\n' + end_chars)) block_begin=(begin_chars + '\n'), block_end=('\n' + end_chars))
def do_cpp_line_comment(s, line_prefix='// '):
"""Makes things like this: (with line_prefix='// ')
// foo
//
// bar
"""
return do_prefix_block(s, line_prefix=line_prefix, blank_line_prefix=line_prefix.rstrip(),
block_begin=None, block_end=None)
\ No newline at end of file
...@@ -97,6 +97,14 @@ block_expected = """/* ...@@ -97,6 +97,14 @@ block_expected = """/*
** See the License for the specific language governing permissions and ** See the License for the specific language governing permissions and
** limitations under the License. ** limitations under the License.
*/""" */"""
line_intext = """Copyright (c) 2018 Collabora, Ltd.
SPDX-License-Identifier: Apache-2.0"""
line_expected = """// Copyright (c) 2018 Collabora, Ltd.
//
// SPDX-License-Identifier: Apache-2.0"""
def test_real_text(): def test_real_text():
eq_( eq_(
do_prefix_block(block_intext, line_prefix='** ', blank_line_prefix='**', block_begin='/*\n', block_end='\n*/'), do_prefix_block(block_intext, line_prefix='** ', blank_line_prefix='**', block_begin='/*\n', block_end='\n*/'),
...@@ -107,6 +115,16 @@ def test_real_text_c_block_comment(): ...@@ -107,6 +115,16 @@ def test_real_text_c_block_comment():
do_c_block_comment(block_intext, line_prefix='** ', begin_chars='/*\n', end_chars='\n*/'), do_c_block_comment(block_intext, line_prefix='** ', begin_chars='/*\n', end_chars='\n*/'),
block_expected) block_expected)
def test_real_text_line():
eq_(
do_prefix_block(line_intext, line_prefix='// ', blank_line_prefix='//', block_begin=None, block_end=None),
line_expected)
def test_real_text_cpp_line_comment():
eq_(
do_cpp_line_comment(line_intext),
line_expected)
def test_identifier(): def test_identifier():
eq_(do_make_identifier('asdf'), 'asdf') eq_(do_make_identifier('asdf'), 'asdf')
eq_(do_make_identifier('as-df'), 'as_df') eq_(do_make_identifier('as-df'), 'as_df')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment