Skip to content

Commit

Permalink
Add Ctrl-Q documentation for getline #202 : tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Aug 26, 2023
1 parent a4d95bb commit c7d3cc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/java/intellij_awk/AwkDocumentationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private AwkFile getStdLibFile(Project project) {
int targetOffset) {
if (contextElement instanceof PsiWhiteSpace
|| AwkUtil.isType(contextElement, AwkTypes.LPAREN)
|| AwkUtil.isType(contextElement, AwkTypes.RPAREN)) {
|| AwkUtil.isType(contextElement, AwkTypes.RPAREN)
|| AwkUtil.isType(contextElement, AwkTypes.NEWLINE)
|| AwkUtil.isType(contextElement, AwkTypes.RBRACE)) {
PsiElement parent = contextElement.getParent();
contextElement = contextElement.getPrevSibling();
if (contextElement == null) { // exit<caret>() case
Expand All @@ -205,17 +207,22 @@ private AwkFile getStdLibFile(Project project) {
} else {
PsiElement searchGetline = contextElement;

// why 5? because it can be statement -> simple_statement -> non_unary_expr -> simple_get ->
// why 4? because it can be statement -> simple_statement -> non_unary_expr -> simple_get ->
// getline
for (int i = 0; i < 5; i++) {
for (int i = 0; i < 4; i++) {
searchGetline = searchGetline.getFirstChild();
if (searchGetline == null) {
break;
}
if (AwkUtil.isType(searchGetline, AwkTypes.GETLINE)) {
if ("getline".equals(contextElement.getText())) {
return searchGetline;
}
break;
}
searchGetline = searchGetline.getFirstChild();
if (searchGetline == null) {
} else if (AwkUtil.isType(searchGetline, AwkTypes.EXIT)) {
if ("exit".equals(contextElement.getText())) {
return searchGetline;
}
break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/intellij_awk/AwkDocumentationProviderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public void testStmtExit2() {
public void testStmtExit3() {
testStmtExit("BEGIN { exit<caret>(123) }");
}
public void testStmtExit4() {
testStmtExit("BEGIN { exit<caret>\n}");
}
public void testStmtExit5() {
testStmtExit("BEGIN {exit<caret>}");
}

private void testStmtExit(String code) {
doTest(code, s -> s.contains("The exit statement causes awk to immediately stop executing"));
Expand Down Expand Up @@ -173,6 +179,12 @@ public void testGetline4() {
public void testGetline5() {
testStmtGetline("BEGIN { getline<caret> }");
}
public void testGetline6() {
testStmtGetline("BEGIN { getline<caret>\n}");
}
public void testGetline7() {
testStmtGetline("BEGIN { getline<caret>}");
}

private void testStmtPrintf(String code) {
doTest(
Expand Down

0 comments on commit c7d3cc0

Please sign in to comment.