Skip to content

Commit 8529978

Browse files
committed
Updates
1 parent ffa324a commit 8529978

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/external/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<jdk.min.version>1.8</jdk.min.version>
15-
<grammars>grammars-v4/tsql</grammars>
15+
<grammars>.</grammars>
1616
<grammars.out.dir>tsql</grammars.out.dir>
1717
<grammars.package>org.antlr.sql.dialects.tsql</grammars.package>
1818
</properties>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.sonar.plugins.sql.fillers;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import org.antlr.sql.dialects.Dialects;
10+
import org.antlr.sql.models.AntlrContext;
11+
import org.antlr.sql.tools.PrettyPrinter;
12+
import org.apache.commons.io.FileUtils;
13+
import org.junit.Assert;
14+
import org.junit.Rule;
15+
import org.junit.Test;
16+
import org.junit.rules.TemporaryFolder;
17+
import org.junit.runner.RunWith;
18+
import org.junit.runners.Parameterized;
19+
import org.junit.runners.Parameterized.Parameters;
20+
import org.sonar.api.batch.fs.internal.DefaultInputFile;
21+
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
22+
import org.sonar.api.batch.sensor.internal.SensorContextTester;
23+
import org.sonar.api.measures.CoreMetrics;
24+
import org.sonar.api.utils.internal.JUnitTempFolder;
25+
import org.sonar.plugins.sql.Constants;
26+
27+
@RunWith(Parameterized.class)
28+
public class HighlightingFillerTest {
29+
30+
HighlighterFiller filler = new HighlighterFiller();
31+
32+
@Parameters(name = "{0} ({index})")
33+
public static Iterable<Object[]> data() throws Throwable {
34+
35+
List<Object[]> data = new ArrayList<>();
36+
/*
37+
* data.add(new Object[] { Dialects.MYSQL, 17 }); data.add(new Object[] {
38+
* Dialects.PSSQL, 7 }); data.add(new Object[] { Dialects.TSQL, 9 });
39+
*/
40+
data.add(new Object[] { Dialects.VSQL, 9 });
41+
return data;
42+
}
43+
44+
@Rule
45+
public TemporaryFolder folder = new TemporaryFolder();
46+
47+
@org.junit.Rule
48+
public JUnitTempFolder temp = new JUnitTempFolder();
49+
50+
private Dialects dialect;
51+
52+
private int expected;
53+
54+
public HighlightingFillerTest(Dialects dialect, int expected) {
55+
this.dialect = dialect;
56+
this.expected = expected;
57+
}
58+
59+
@Test
60+
public void testComplexity() throws IOException {
61+
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
62+
ctxTester.fileSystem().setWorkDir(folder.getRoot().toPath());
63+
64+
File baseFile = folder.newFile("test.sql");
65+
66+
FileUtils.copyURLToFile(getClass().getResource("/tsql/sample1.sql"), baseFile);
67+
String contents = new String(Files.readAllBytes(baseFile.toPath()));
68+
69+
DefaultInputFile ti = new TestInputFileBuilder("test", folder.getRoot(), baseFile).initMetadata(contents)
70+
.setLanguage(Constants.languageKey).setContents(contents).setProjectBaseDir(folder.getRoot().toPath())
71+
.build();
72+
ctxTester.fileSystem().add(ti);
73+
74+
AntlrContext antlrContext = dialect.parse("SELECT * From facts.test where x = 4;\r\n");
75+
76+
PrettyPrinter.print(antlrContext.root, 0, antlrContext.stream);
77+
78+
filler.fill(ti, ctxTester, antlrContext);
79+
antlrContext.getAllTokens().forEach(x-> {
80+
81+
// antlrContext.lexer.getVocabulary().
82+
// System.out.println(x.getText()+" " +x.getType()+" "+antlrContext.lexer.getVocabulary().getDisplayName(x.getType())+" "+antlrContext.lexer.getVocabulary().getLiteralName(x.getType())+" "+antlrContext.lexer.getVocabulary().getSymbolicName(x.getType())+" "+antlrContext.lexer.getVocabulary().getSymbolicName(x.getType()));
83+
});
84+
85+
}
86+
87+
}

0 commit comments

Comments
 (0)