Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复watch 构造方法的问题 #2939

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
Expand Down Expand Up @@ -100,11 +101,20 @@ private static List<CliToken> adjustTokensForSpecialSymbols(List<CliToken> token
return separateLeadingAndTailingSymbol(tokens, PIPE, REDIRECT_APPEND, REDIRECT);
}

private static boolean isQuotedTokenValue(String raw, String value) {
return Objects.equals(raw, "\"" + value + "\"")
|| Objects.equals(raw, "'" + value + "'");
}

private static List<CliToken> separateLeadingAndTailingSymbol(List<CliToken> tokens, String... symbols) {
List<CliToken> adjustedTokens = new ArrayList<>();
for (CliToken token : tokens) {
String value = token.value();
String raw = token.raw();
if (isQuotedTokenValue(raw, value) || "<init>".equals(value) || "<clinit>".equals(value)) {
adjustedTokens.add(token);
continue;
}
boolean handled = false;
for (String symbol : symbols) {
if (value.equals(symbol)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,38 @@ public void testSeparateRedirect() {

}

@Test
public void testSeparateRedirect2() {
String[] expectedTextTokenValue = new String[]{"watch", "demo.MathGame", "<init>"};
String cmd = "watch demo.MathGame \"<init>\"";
List<CliToken> actualTokens = CliTokenImpl.tokenize(cmd);
assertEqualsIgnoreBlank(expectedTextTokenValue, actualTokens);
Assert.assertEquals(cmd, concatRaw(actualTokens));

expectedTextTokenValue = new String[]{"watch", "demo.MathGame", "<init>"};
cmd = "watch demo.MathGame <init>";
actualTokens = CliTokenImpl.tokenize(cmd);
assertEqualsIgnoreBlank(expectedTextTokenValue, actualTokens);
Assert.assertEquals(cmd, concatRaw(actualTokens));

expectedTextTokenValue = new String[]{"watch", "demo.MathGame", "<clinit>"};
cmd = "watch demo.MathGame '<clinit>'";
actualTokens = CliTokenImpl.tokenize(cmd);
assertEqualsIgnoreBlank(expectedTextTokenValue, actualTokens);
Assert.assertEquals(cmd, concatRaw(actualTokens));

expectedTextTokenValue = new String[]{"watch", "demo.MathGame", "<clinit>", "#cost> 100"};
cmd = "watch demo.MathGame <clinit> '#cost> 100'";
actualTokens = CliTokenImpl.tokenize(cmd);
assertEqualsIgnoreBlank(expectedTextTokenValue, actualTokens);
Assert.assertEquals(cmd, concatRaw(actualTokens));
expectedTextTokenValue = new String[]{"watch", "demo.MathGame", "<clinit>", "> 100"};
cmd = "watch demo.MathGame <clinit> '> 100'";
actualTokens = CliTokenImpl.tokenize(cmd);
assertEqualsIgnoreBlank(expectedTextTokenValue, actualTokens);
Assert.assertEquals(cmd, concatRaw(actualTokens));
}

@Test
public void testSeparateRedirectAppend() {
String[] expectedTextTokenValue = new String[]{"jad", "aaa", ">>", "bbb"};
Expand Down
Loading