def test_free_form_comment_line(): printer = FCodePrinter({'source_format': 'free'}) lines = ['! This is a long comment on a single line that must be wrapped properly to produce nice output'] expected = [ '! This is a long comment on a single line that must be wrapped properly', '! to produce nice output'] assert printer._wrap_fortran(lines) == expected
def test_free_form_comment_line(): printer = FCodePrinter({'source_format': 'free'}) lines = [ "! This is a long comment on a single line that must be wrapped properly to produce nice output"] expected = [ '! This is a long comment on a single line that must be wrapped properly', '! to produce nice output'] assert printer._wrap_fortran(lines) == expected
def test_wrap_fortran(): # "########################################################################" printer = FCodePrinter() lines = [ "C This is a long comment on a single line that must be wrapped properly to produce nice output", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly", ] wrapped_lines = printer._wrap_fortran(lines) expected_lines = [ "C This is a long comment on a single line that must be wrapped", "C properly to produce nice output", " this = is + a + long + and + nasty + fortran + statement + that *", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that *", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ *must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement +", " @ that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ **must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ **must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement +", " @ that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)", " @ /must + be + wrapped + properly", ] for line in wrapped_lines: assert len(line) <= 72 for w, e in zip(wrapped_lines, expected_lines): assert w == e assert len(wrapped_lines) == len(expected_lines)
def test_wrap_fortran_keep_d0(): printer = FCodePrinter() lines = [ ' this_variable_is_very_long_because_we_try_to_test_line_break=1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break = 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break = 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break = 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break = 10.0d0' ] expected = [ ' this_variable_is_very_long_because_we_try_to_test_line_break=1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =', ' @ 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =', ' @ 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =', ' @ 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =', ' @ 1.0d0', ' this_variable_is_very_long_because_we_try_to_test_line_break =', ' @ 10.0d0' ] assert printer._wrap_fortran(lines) == expected
def test_wrap_fortran(): # "########################################################################" printer = FCodePrinter() lines = [ 'C This is a long comment on a single line that must be wrapped properly to produce nice output', ' this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly', ] wrapped_lines = printer._wrap_fortran(lines) expected_lines = [ 'C This is a long comment on a single line that must be wrapped', 'C properly to produce nice output', ' this = is + a + long + and + nasty + fortran + statement + that *', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that *', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that', ' @ * must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that*', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that', ' @ *must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement +', ' @ that*must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that**', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that', ' @ **must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement + that', ' @ **must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement +', ' @ that**must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement(that)/', ' @ must + be + wrapped + properly', ' this = is + a + long + and + nasty + fortran + statement(that)', ' @ /must + be + wrapped + properly', ] for line in wrapped_lines: assert len(line) <= 72 for w, e in zip(wrapped_lines, expected_lines): assert w == e assert len(wrapped_lines) == len(expected_lines) lines = [ 'C 553253524254653461546154715734516547876868686868687' '86686868668866871376456135451745651 54165175461 5613 5754' '41586585565557575576577657575757576547' ] assert (printer._wrap_fortran(lines) == [ 'C 553253524254653461546154715734516547876868686868687' '866868686688668', 'C 71376456135451745651 54165175461 5613', 'C 575441586585565557575576577657575757576547' ]) lines = [ ' i = ohhohohoerhoheroighokhjhkhkhkhkhjhkhjkhjkhjhjkhjk' 'hhkerhgiheoheohoge + iuirefgiuguieriufgirugfiur + ruhfriehierhi' ] assert (printer._wrap_fortran(lines) == [ ' i =', ' @ ohhohohoerhoheroighokhjhkhkhkhkhjhkhjk' 'hjkhjhjkhjkhhkerhgiheoheoho', ' @ ge + iuirefgiuguieriufgirugfiur + ruhfriehierhi' ])
def test_wrap_fortran(): # "########################################################################" printer = FCodePrinter() lines = [ "C This is a long comment on a single line that must be wrapped properly to produce nice output", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properly", ] wrapped_lines = printer._wrap_fortran(lines) expected_lines = [ "C This is a long comment on a single line that must be wrapped", "C properly to produce nice output", " this = is + a + long + and + nasty + fortran + statement + that *", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that *", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ * must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that*", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ *must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement +", " @ that*must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that**", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ **must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement + that", " @ **must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement +", " @ that**must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)/", " @ must + be + wrapped + properly", " this = is + a + long + and + nasty + fortran + statement(that)", " @ /must + be + wrapped + properly", ] for line in wrapped_lines: assert len(line) <= 72 for w, e in zip(wrapped_lines, expected_lines): assert w == e assert len(wrapped_lines) == len(expected_lines) lines = ["C 553253524254653461546154715734516547876868686868687" "86686868668866871376456135451745651 54165175461 5613 5754" "41586585565557575576577657575757576547"] assert (printer._wrap_fortran(lines) == ['C 553253524254653461546154715734516547876868686868687' '866868686688668', 'C 71376456135451745651 54165175461 5613', 'C 575441586585565557575576577657575757576547']) lines = [" i = ohhohohoerhoheroighokhjhkhkhkhkhjhkhjkhjkhjhjkhjk" "hhkerhgiheoheohoge + iuirefgiuguieriufgirugfiur + ruhfriehierhi"] assert (printer._wrap_fortran(lines) == [' i =', ' @ ohhohohoerhoheroighokhjhkhkhkhkhjhkhjk' 'hjkhjhjkhjkhhkerhgiheoheoho', ' @ ge + iuirefgiuguieriufgirugfiur + ruhfriehierhi'])