From 58a64553f68fe4fcef820266fc10f6d7f1ae91be Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 27 Jul 2018 10:09:23 -0500 Subject: [PATCH] Add C++ line comment filter with tests --- file_boilerplate/filters.py | 12 +++++++++++- tests/test_filters.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/file_boilerplate/filters.py b/file_boilerplate/filters.py index 9d4b753..b5e0368 100644 --- a/file_boilerplate/filters.py +++ b/file_boilerplate/filters.py @@ -66,4 +66,14 @@ 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(), - block_begin=(begin_chars + '\n'), block_end=('\n' + end_chars)) \ No newline at end of file + 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 diff --git a/tests/test_filters.py b/tests/test_filters.py index 46e44d7..d46dc48 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -97,6 +97,14 @@ block_expected = """/* ** See the License for the specific language governing permissions and ** 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(): eq_( 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(): do_c_block_comment(block_intext, line_prefix='** ', begin_chars='/*\n', end_chars='\n*/'), 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(): eq_(do_make_identifier('asdf'), 'asdf') eq_(do_make_identifier('as-df'), 'as_df') -- GitLab