From 1dbcb6ee98c241b1fc44c6047626c89070c88ca3 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Thu, 10 Oct 2024 14:45:41 -0700 Subject: [PATCH] Add a test for the broken behavior due to missing grouping parenthesis. PiperOrigin-RevId: 684584755 --- .../bugpatterns/inlineme/InlinerTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java index 983d2f6dd25..4e7084a98d2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java @@ -1471,6 +1471,46 @@ public void doTest() { .doTest(); } + @Test + public void math_b308614050() { + refactoringTestHelper + .addInputLines( + "Client.java", + """ + package com.google.foo; + import com.google.errorprone.annotations.InlineMe; + public final class Client { + @InlineMe(replacement = "x * 2") + public static int timesTwo(int x) { + return x * 2; + } + } + """) + .expectUnchanged() + .addInputLines( + "Caller.java", + """ + import com.google.foo.Client; + public final class Caller { + public void doTest() { + long four = Client.timesTwo(1 + 1); + } + } + """) + // This is a bug since it now evaluates to 3, not 4! + .addOutputLines( + "Caller.java", + """ + import com.google.foo.Client; + public final class Caller { + public void doTest() { + long four = 1 + 1 * 2; + } + } + """) + .doTest(); + } + private BugCheckerRefactoringTestHelper bugCheckerWithPrefixFlag(String prefix) { return BugCheckerRefactoringTestHelper.newInstance(Inliner.class, getClass()) .setArgs("-XepOpt:" + PREFIX_FLAG + "=" + prefix);