Skip to content

Commit

Permalink
another TernaryPushdownStrings bug fix (issue #236)
Browse files Browse the repository at this point in the history
  • Loading branch information
NivShalmon committed Sep 20, 2016
1 parent d029060 commit 3be8271
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -76,7 +76,7 @@ private static int lastDifference(final String s1, final String s2) {
for (int ¢ = 0; ¢ < s1.length(); ++¢) {
if (!Character.isAlphabetic(last(s1, ¢)) && !Character.isAlphabetic(last(s2, ¢))
|| ¢ == s1.length() - 1 && !Character.isAlphabetic(last(s2, ¢)))
$ = ¢ + 1;
$ = last(s1, ¢) != last(s2, ¢) ? ¢ : ¢ + 1;
if (last(s1, ¢) != last(s2, ¢))
return $;
}
Expand Down Expand Up @@ -139,10 +139,7 @@ private static Expression simplify(final Expression condition, final InfixExpres
}

private static Expression simplify(final Expression condition, final String then, final String elze) {
return simplify(condition, then, elze, firstDifference(then, elze));
}

private static Expression simplify(final Expression condition, final String then, final String elze, final int commonPrefixIndex) {
final int commonPrefixIndex = firstDifference(then, elze);
if (commonPrefixIndex != 0)
return replacementPrefix(then, elze, commonPrefixIndex, condition);
final int commonSuffixLength = lastDifference(then, elze);
Expand Down
Expand Up @@ -29,4 +29,12 @@ public class Issue236Test {
.gives("\"something\" + (b? \"\" : \" else\")").stays();
}

@Test public void issue236_03() {
trimmingOf("isIncrement(¢) ? \"++\" : \"--\"").stays();
}

@Test public void issue236_04() {
trimmingOf("isIncrement(¢) ? \"++x\" : \"--x\"").gives("(isIncrement(¢) ? \"++\" : \"--\")+\"x\"").stays();
}

}

0 comments on commit 3be8271

Please sign in to comment.