Skip to content

Commit 90f73f7

Browse files
committed
[FIX] parser/lexer fixed & tests added
1 parent 4b98eb8 commit 90f73f7

File tree

11 files changed

+30
-7
lines changed

11 files changed

+30
-7
lines changed

src/main/java/net/seesharpsoft/intellij/plugins/csv/Csv.bnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
tokens=[
1818
TEXT='regexp:[^ ,;|\t\r\n"\\]+'
19-
ESCAPED_TEXT='regexp:([,;|\t\r\n\\]|""|\\")+'
19+
ESCAPED_TEXT='regexp:[,;|\t\r\n\\]|""|\\"'
2020
COMMA='regexp:[,;|\t]'
2121
QUOTE='"'
2222
CRLF='regexp:\n'

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvLexer.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import java.util.regex.Pattern;
3434
%eof}
3535

3636
TEXT=[^ ,;|\t\r\n\"\\]+
37-
ESCAPED_TEXT=([,;|\t\r\n\\]|\"\"|\\\")+
37+
ESCAPED_TEXT=[,;|\t\r\n\\]|\"\"|\\\"
3838
QUOTE=\"
3939
COMMA=[,;|\t]
4040
EOL=\n

src/test/java/net/seesharpsoft/intellij/plugins/csv/intention/CsvIntentionTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.codeInsight.intention.IntentionAction;
44
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
5+
import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettings;
56

67
public class CsvIntentionTest extends LightPlatformCodeInsightFixtureTestCase {
78

@@ -18,15 +19,27 @@ protected void doTestIntention(String testName, String hint) throws Throwable {
1819
myFixture.launchAction(action);
1920
myFixture.checkResultByFile(testName + "/after.csv");
2021
}
21-
22+
2223
public void testQuoteAllIntention() throws Throwable {
2324
doTestIntention("QuoteAll", "Quote All");
2425
}
2526

27+
public void testQuoteAllBackslashIntention() throws Throwable {
28+
CsvEditorSettings.getInstance().setDefaultEscapeCharacter(CsvEditorSettings.EscapeCharacter.BACKSLASH);
29+
doTestIntention("QuoteAllBackslash", "Quote All");
30+
CsvEditorSettings.getInstance().setDefaultEscapeCharacter(CsvEditorSettings.ESCAPE_CHARACTER_DEFAULT);
31+
}
32+
2633
public void testUnquoteAllIntention() throws Throwable {
2734
doTestIntention("UnquoteAll", "Unquote All");
2835
}
2936

37+
public void testUnquoteAllBackslashIntention() throws Throwable {
38+
CsvEditorSettings.getInstance().setDefaultEscapeCharacter(CsvEditorSettings.EscapeCharacter.BACKSLASH);
39+
doTestIntention("UnquoteAllBackslash", "Unquote All");
40+
CsvEditorSettings.getInstance().setDefaultEscapeCharacter(CsvEditorSettings.ESCAPE_CHARACTER_DEFAULT);
41+
}
42+
3043
public void testQuoteIntention() throws Throwable {
3144
doTestIntention("QuoteValue", "Quote");
3245
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"Header 1", "Header, 2"
2-
"Value 1"," Value 2"
2+
"Value ""1"""," Value 2"
3+
""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Header 1, "Header, 2"
2-
Value 1, Value 2
2+
"Value ""1""", Value 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Header 1", "Header, 2"
2+
"Value \"1\""," Value 2"
3+
""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Header 1, "Header, 2"
2+
"Value \"1\"", Value 2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Header 1, "Header, 2"
2-
Value 1, Value 2
2+
"Value ""1""", Value 2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"Header 1", "Header, 2"
2-
"Value 1", "Value 2"
2+
"Value ""1""", "Value 2"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Header 1, "Header, 2"
2+
"Value \"1\"", Value 2

0 commit comments

Comments
 (0)