Skip to content

Commit

Permalink
Merge pull request #48 from meteokid/cstylefix
Browse files Browse the repository at this point in the history
Fix multi line --enable-replacements --c-relations
  • Loading branch information
pseewald authored Jun 21, 2019
2 parents ebba129 + 6fb9180 commit 0207147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
24 changes: 12 additions & 12 deletions fprettify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,19 @@ def replace_relational_single_fline(f_line, cstyle):
if not STR_OPEN_RE.match(part):
# also exclude / if we see a namelist and data statement
if cstyle:
part = re.sub(r"\s*\.LT\.\s*", "<", part, flags=RE_FLAGS)
part = re.sub(r"\s*\.LE\.\s*", "<=", part, flags=RE_FLAGS)
part = re.sub(r"\s*\.GT\.\s*", ">", part, flags=RE_FLAGS)
part = re.sub(r"\s*\.GE\.\s*", ">=", part, flags=RE_FLAGS)
part = re.sub(r"\s*\.EQ\.\s*", "==", part, flags=RE_FLAGS)
part = re.sub(r"\s*\.NE\.\s*", "/=", part, flags=RE_FLAGS)
part = re.sub(r"\.LT\.", "< ", part, flags=RE_FLAGS)
part = re.sub(r"\.LE\.", "<= ", part, flags=RE_FLAGS)
part = re.sub(r"\.GT\.", "> ", part, flags=RE_FLAGS)
part = re.sub(r"\.GE\.", ">= ", part, flags=RE_FLAGS)
part = re.sub(r"\.EQ\.", "== ", part, flags=RE_FLAGS)
part = re.sub(r"\.NE\.", "/= ", part, flags=RE_FLAGS)
else:
part = re.sub(r"\s*<=\s*", ".le.", part, flags=RE_FLAGS)
part = re.sub(r"\s*<\s*", ".lt.", part, flags=RE_FLAGS)
part = re.sub(r"\s*>=\s*", ".ge.", part, flags=RE_FLAGS)
part = re.sub(r"\s*>\s*", ".gt.", part, flags=RE_FLAGS)
part = re.sub(r"\s*==\s*", ".eq.", part, flags=RE_FLAGS)
part = re.sub(r"\s*\/=\s*", ".ne.", part, flags=RE_FLAGS)
part = re.sub(r"<=", ".le.", part, flags=RE_FLAGS)
part = re.sub(r"<", ".lt.", part, flags=RE_FLAGS)
part = re.sub(r">=", ".ge.", part, flags=RE_FLAGS)
part = re.sub(r">", ".gt.", part, flags=RE_FLAGS)
part = re.sub(r"==", ".eq.", part, flags=RE_FLAGS)
part = re.sub(r"\/=", ".ne.", part, flags=RE_FLAGS)

line_parts[pos] = part

Expand Down
10 changes: 6 additions & 4 deletions fprettify/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ def test_relation_replacement(self):
"if( min <= max .and. min .le. thres)",
"'==== heading",
"if (vtk%my_rank .eq. 0) write (vtk%filehandle_par, '(\"<DataArray",
"'(\"</Collection>\","]
"'(\"</Collection>\",",
"if (abc(1) .lt. -bca .or. &\n qwe .gt. ewq) then"]
f_outstring = ["if (min .lt. max .and. min .lt. thres)",
"if (min .gt. max .and. min .gt. thres)",
"if (min .eq. max .and. min .eq. thres)",
Expand All @@ -377,7 +378,8 @@ def test_relation_replacement(self):
"if (min .le. max .and. min .le. thres)",
"'==== heading",
"if (vtk%my_rank .eq. 0) write (vtk%filehandle_par, '(\"<DataArray",
"'(\"</Collection>\","]
"'(\"</Collection>\",",
"if (abc(1) .lt. -bca .or. &\n qwe .gt. ewq) then"]
c_outstring = ["if (min < max .and. min < thres)",
"if (min > max .and. min > thres)",
"if (min == max .and. min == thres)",
Expand All @@ -386,8 +388,8 @@ def test_relation_replacement(self):
"if (min <= max .and. min <= thres)",
"'==== heading",
"if (vtk%my_rank == 0) write (vtk%filehandle_par, '(\"<DataArray",
"'(\"</Collection>\","]

"'(\"</Collection>\",",
"if (abc(1) < -bca .or. &\n qwe > ewq) then"]
for i in range(0, len(instring)):
self.assert_fprettify_result(['--enable-replacements', '--c-relations'], instring[i], c_outstring[i])
self.assert_fprettify_result(['--enable-replacements'], instring[i], f_outstring[i])
Expand Down

0 comments on commit 0207147

Please sign in to comment.