-
Notifications
You must be signed in to change notification settings - Fork 35
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
Upgrade gradle and fix tests #13
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ buildscript { | |
} | ||
|
||
plugins { | ||
id "org.jetbrains.intellij" version "0.4.2" | ||
id "org.jetbrains.intellij" version "1.1.3" | ||
} | ||
|
||
wrapper { | ||
gradleVersion = '5.2.1' | ||
gradleVersion = '7.1.1' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Picked the latest so that it will hopefully keep working for the coming years. |
||
} | ||
|
||
group 'antlr' | ||
|
@@ -27,9 +27,9 @@ compileJava { | |
intellij { | ||
version = ideaVersion | ||
|
||
pluginName 'antlr4-intellij-plugin-sample' | ||
downloadSources true | ||
updateSinceUntilBuild false | ||
pluginName = 'antlr4-intellij-plugin-sample' | ||
downloadSources = true | ||
updateSinceUntilBuild = false | ||
} | ||
|
||
repositories { | ||
|
@@ -41,9 +41,5 @@ dependencies { | |
exclude group:'com.ibm.icu', module:'icu4j' | ||
} | ||
implementation 'org.antlr:antlr4-intellij-adaptor:0.1' | ||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
testImplementation group: 'junit', name: 'junit', version: '4.11' | ||
} | ||
|
||
generateGrammarSource { | ||
arguments += ["-package", "org.antlr.jetbrains.sample.parser", "-Xexact-output-dir"] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Odd stuff. Replaced with a single package header in the grammar (not perfect either) and now the files are generated in the correct package with the correct package statement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a downside to this method, but I can't remember what it is 🤔 . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The upside is that you can open the generated files in an IDE and not get compile errors :-) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ | |
* Generate the parser via "mvn compile" from root dir of project. | ||
*/ | ||
grammar SampleLanguage; | ||
@header {package org.antlr.jetbrains.sample.parser;} | ||
|
||
/** The start rule must be whatever you would normally use, such as script | ||
* or compilationUnit, etc... | ||
*/ | ||
script | ||
: vardef* function* statement* EOF | ||
: (vardef|function|statement)* EOF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes a lot more sense and fixes a few tests. |
||
; | ||
|
||
function | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
package org.antlr.intellij.adaptor.test; | ||
package org.antlr.jetbrains.adaptor.test; | ||
|
||
import com.intellij.lang.Language; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.impl.source.tree.LeafPsiElement; | ||
import com.intellij.testFramework.ParsingTestCase; | ||
import org.antlr.intellij.adaptor.xpath.XPath; | ||
import org.antlr.jetbrains.sample.SampleLanguage; | ||
import org.antlr.jetbrains.sample.SampleParserDefinition; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
public class TestXPath extends ParsingTestCase { | ||
|
||
public static final String TEST_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/test.sample"; | ||
public static final String BUBBLESORT_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/bubblesort.sample"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The testfiles couldn't be found, the paths were all wrong. |
||
|
||
public TestXPath() { | ||
super("", "Sample", new SampleParserDefinition()); | ||
} | ||
|
||
public void testSingleVarDef() throws Exception { | ||
public void testSingleVarDef() { | ||
String code = "var x = 1"; | ||
String output = code; | ||
String xpath = "/script/statement"; | ||
String xpath = "/script"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testMultiVarDef() throws Exception { | ||
public void testMultiVarDef() { | ||
String code = | ||
"var x = 1\n" + | ||
"var y = [1,2,3]\n"; | ||
String output = code; | ||
String xpath = "/script/statement"; | ||
String xpath = "/script"; | ||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testFuncNames() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"f\n"+ | ||
"g\n"+ | ||
|
@@ -43,7 +45,7 @@ public void testFuncNames() throws Exception { | |
} | ||
|
||
public void testAllIDs() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"f\n"+ | ||
"x\n"+ | ||
|
@@ -60,7 +62,7 @@ public void testAllIDs() throws Exception { | |
} | ||
|
||
public void testAnyVarDef() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"var y = x\n"+ | ||
"var z = 9"; | ||
|
@@ -69,7 +71,7 @@ public void testAnyVarDef() throws Exception { | |
} | ||
|
||
public void testVarDefIDs() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"y\n" + | ||
"z"; | ||
|
@@ -78,44 +80,43 @@ public void testVarDefIDs() throws Exception { | |
} | ||
|
||
public void testAllVarDefIDsInScopes() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); | ||
String code = loadFile(BUBBLESORT_SAMPLE); | ||
String output = | ||
"x\n"+ | ||
"i\n"+ | ||
"j\n"+ | ||
"swap\n"+ | ||
"x"; | ||
String xpath = "//block/statement/vardef/ID"; | ||
String xpath = "//block/vardef/ID"; | ||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testTopLevelVarDefIDsInScopes() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); | ||
String code = loadFile(BUBBLESORT_SAMPLE); | ||
String output = | ||
"x\n"+ | ||
"i"; | ||
String xpath = "//function/block/statement/vardef/ID"; | ||
String xpath = "//function/block/vardef/ID"; | ||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testRuleUnderWildcard() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"var y = x\n"+ | ||
"x\n"+ | ||
"[\n"+ | ||
"1\n"+ | ||
"]\n"+ | ||
"=\n"+ | ||
"\"sdflkjsdf\"\n"+ | ||
"return\n"+ | ||
"false;"; | ||
"false"; | ||
String xpath = "//function/*/statement/*"; | ||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testAllNonWhileTokens() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); | ||
String code = loadFile(BUBBLESORT_SAMPLE); | ||
String output = | ||
"(\n"+ | ||
")\n"+ | ||
|
@@ -125,15 +126,15 @@ public void testAllNonWhileTokens() throws Exception { | |
} | ||
|
||
public void testGetNestedIf() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); | ||
String code = loadFile(BUBBLESORT_SAMPLE); | ||
String output = | ||
"if"; | ||
String xpath = "//'if'"; | ||
checkXPathResults(code, xpath, output); | ||
} | ||
|
||
public void testWildcardUnderFuncThenJustTokens() throws Exception { | ||
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); | ||
String code = loadFile(TEST_SAMPLE); | ||
String output = | ||
"func\n"+ | ||
"f\n"+ | ||
|
@@ -165,15 +166,11 @@ public void testWildcardUnderFuncThenJustTokens() throws Exception { | |
|
||
// S U P P O R T | ||
|
||
protected void checkXPathResults(String code, String xpath, String allNodesText) throws IOException { | ||
checkXPathResults(SampleLanguage.INSTANCE, code, xpath, allNodesText); | ||
} | ||
|
||
protected void checkXPathResults(Language language, String code, String xpath, String allNodesText) throws IOException { | ||
protected void checkXPathResults(String code, String xpath, String allNodesText) { | ||
myFile = createPsiFile("a", code); | ||
ensureParsed(myFile); | ||
assertEquals(code, myFile.getText()); | ||
Collection<? extends PsiElement> nodes = XPath.findAll(language, myFile, xpath); | ||
Collection<? extends PsiElement> nodes = XPath.findAll(SampleLanguage.INSTANCE, myFile, xpath); | ||
StringBuilder buf = new StringBuilder(); | ||
for (PsiElement t : nodes) { | ||
buf.append(t.getText()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ func f(x:[]) { | |
|
||
func g(x:int, y:float) { } | ||
|
||
func h() : boolean { return false; } | ||
func h() : boolean { return false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comma isn't allowed there (or is this an implicit test for invalid syntax?) |
||
|
||
var z = 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to go along with the gradle upgrade.