Skip to content

Commit

Permalink
Add initial parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer committed Feb 26, 2021
1 parent e7147c1 commit 31d1161
Show file tree
Hide file tree
Showing 31 changed files with 465 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[src/test/testData/**]
insert_final_newline = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/.idea
/build
/.gradle
/.sandbox
*.java~
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ intellij {
}

test {
useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
}
}

tasks {
Expand Down
79 changes: 79 additions & 0 deletions src/test/java/parser/SilverstripeParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package parser;

import com.intellij.lang.ParserDefinition;
import com.intellij.testFramework.ParsingTestCase;
import com.intellij.util.ArrayUtil;
import com.kinglozzer.silverstripe.parser.SilverstripeParserDefinition;
import org.jetbrains.annotations.NotNull;

public class SilverstripeParserTest extends ParsingTestCase {
public SilverstripeParserTest() {
super("parser", "ss", new SilverstripeParserDefinition());
}

public SilverstripeParserTest(ParserDefinition @NotNull ... additionalDefinitions) {
super("parser", "ss", ArrayUtil.prepend(new SilverstripeParserDefinition(), additionalDefinitions));
}

@Override
protected boolean checkAllPsiRoots() {
return false;
}

@Override
protected String getTestDataPath() {
return "src/test/testData";
}

public void testLookup() {
doTest(true);
}

public void testLookupWithArguments() {
doTest(true);
}

public void testLookupWithSteps() {
doTest(true);
}

public void testIfStatement() {
doTest(true);
}

public void testLoopStatement() {
doTest(true);
}

public void testWithStatement() {
doTest(true);
}

public void testInclude() {
doTest(true);
}

public void testIncludeWithNamespace() {
doTest(true);
}

public void testIncludeWithArguments() {
doTest(true);
}

public void testRequire() {
doTest(true);
}

public void testTranslation() {
doTest(true);
}

public void testComment() {
doTest(true);
}

public void testSampleTemplate() {
doTest(true);
}
}
3 changes: 3 additions & 0 deletions src/test/testData/parser/Comment.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%--
some block comment
--%>
6 changes: 6 additions & 0 deletions src/test/testData/parser/Comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_COMMENT_STATEMENT)
PsiElement(SS_COMMENT_START)('<%--')
PsiComment(SS_COMMENT)('\nsome block comment\n')
PsiElement(SS_COMMENT_END)('--%>')
7 changes: 7 additions & 0 deletions src/test/testData/parser/IfStatement.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if $Foo && $FooBar %>
{$Foo}
<% else_if $Bar %>
<% if $Bar.Baz %>
{$Bar.Baz}
<% end_if %>
<% end_if %>
77 changes: 77 additions & 0 deletions src/test/testData/parser/IfStatement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_BLOCK_STATEMENT)
SilverstripePsiElementImpl([Ss] SS_IF_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_IF_KEYWORD)('if')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Foo')
PsiWhiteSpace(' ')
PsiElement(SS_AND_OR_OPERATOR)('&&')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$FooBar')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Foo')
PsiElement(SS_RIGHT_BRACE)('}')
PsiWhiteSpace('\n')
SilverstripePsiElementImpl([Ss] SS_ELSE_IF_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_ELSE_IF_KEYWORD)('else_if')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Bar')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_BLOCK_STATEMENT)
SilverstripePsiElementImpl([Ss] SS_IF_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_IF_KEYWORD)('if')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Bar')
PsiElement(SS_DOT)('.')
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement(SS_IDENTIFIER)('Baz')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Bar')
PsiElement(SS_DOT)('.')
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement(SS_IDENTIFIER)('Baz')
PsiElement(SS_RIGHT_BRACE)('}')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_BLOCK_END_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_END_KEYWORD)('end_if')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n')
SilverstripePsiElementImpl([Ss] SS_BLOCK_END_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_END_KEYWORD)('end_if')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
1 change: 1 addition & 0 deletions src/test/testData/parser/Include.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% include IncludeName %>
10 changes: 10 additions & 0 deletions src/test/testData/parser/Include.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripeIncludeImpl([Ss] SS_INCLUDE_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_KEYWORD)('include')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_FILE)('IncludeName')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
1 change: 1 addition & 0 deletions src/test/testData/parser/IncludeWithArguments.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% include Path\To\IncludeName Arg1=true, Arg2=false %>
19 changes: 19 additions & 0 deletions src/test/testData/parser/IncludeWithArguments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripeIncludeImpl([Ss] SS_INCLUDE_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_KEYWORD)('include')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_FILE)('Path\To\IncludeName')
PsiWhiteSpace(' ')
PsiElement(SS_NAMED_ARGUMENT_NAME)('Arg1')
PsiElement(SS_EQUALS)('=')
PsiElement(SS_PRIMITIVE)('true')
PsiElement(SS_COMMA)(',')
PsiWhiteSpace(' ')
PsiElement(SS_NAMED_ARGUMENT_NAME)('Arg2')
PsiElement(SS_EQUALS)('=')
PsiElement(SS_PRIMITIVE)('false')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
1 change: 1 addition & 0 deletions src/test/testData/parser/IncludeWithNamespace.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% include Path\To\IncludeName %>
10 changes: 10 additions & 0 deletions src/test/testData/parser/IncludeWithNamespace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripeIncludeImpl([Ss] SS_INCLUDE_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_KEYWORD)('include')
PsiWhiteSpace(' ')
PsiElement(SS_INCLUDE_FILE)('Path\To\IncludeName')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
7 changes: 7 additions & 0 deletions src/test/testData/parser/Lookup.Silverstripe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Lookup')
PsiElement(SS_RIGHT_BRACE)('}')
1 change: 1 addition & 0 deletions src/test/testData/parser/Lookup.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$Lookup}
7 changes: 7 additions & 0 deletions src/test/testData/parser/Lookup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Lookup')
PsiElement(SS_RIGHT_BRACE)('}')
1 change: 1 addition & 0 deletions src/test/testData/parser/LookupWithArguments.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$Lookup(true, false, 'string')}
17 changes: 17 additions & 0 deletions src/test/testData/parser/LookupWithArguments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Lookup')
PsiElement(SS_LEFT_PARENTHESIS)('(')
SilverstripePsiElementImpl([Ss] SS_LOOKUP_STEP_ARGS)
PsiElement(SS_PRIMITIVE)('true')
PsiElement(SS_COMMA)(',')
PsiWhiteSpace(' ')
PsiElement(SS_PRIMITIVE)('false')
PsiElement(SS_COMMA)(',')
PsiWhiteSpace(' ')
PsiElement(SS_STRING)(''string'')
PsiElement(SS_RIGHT_PARENTHESIS)(')')
PsiElement(SS_RIGHT_BRACE)('}')
1 change: 1 addition & 0 deletions src/test/testData/parser/LookupWithSteps.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$Lookup.Step1('arg').Step2}
17 changes: 17 additions & 0 deletions src/test/testData/parser/LookupWithSteps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Lookup')
PsiElement(SS_DOT)('.')
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement(SS_IDENTIFIER)('Step1')
PsiElement(SS_LEFT_PARENTHESIS)('(')
SilverstripePsiElementImpl([Ss] SS_LOOKUP_STEP_ARGS)
PsiElement(SS_STRING)(''arg'')
PsiElement(SS_RIGHT_PARENTHESIS)(')')
PsiElement(SS_DOT)('.')
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement(SS_IDENTIFIER)('Step2')
PsiElement(SS_RIGHT_BRACE)('}')
5 changes: 5 additions & 0 deletions src/test/testData/parser/LoopStatement.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% loop $List %>
<% loop $NestedList %>
{$Title}
<% end_loop %>
<% end_loop %>
47 changes: 47 additions & 0 deletions src/test/testData/parser/LoopStatement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_BLOCK_STATEMENT)
SilverstripePsiElementImpl([Ss] SS_BLOCK_START_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_START_KEYWORD)('loop')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$List')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_BLOCK_STATEMENT)
SilverstripePsiElementImpl([Ss] SS_BLOCK_START_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_START_KEYWORD)('loop')
PsiWhiteSpace(' ')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$NestedList')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
PsiElement(SS_LEFT_BRACE)('{')
SilverstripePsiElementImpl([Ss] SS_LOOKUP)
SilverstripeLookupStepImpl([Ss] SS_LOOKUP_STEP)
PsiElement([Ss] SS_LOOKUP)('$Title')
PsiElement(SS_RIGHT_BRACE)('}')
PsiWhiteSpace('\n ')
SilverstripePsiElementImpl([Ss] SS_BLOCK_END_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_END_KEYWORD)('end_loop')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
PsiWhiteSpace('\n')
SilverstripePsiElementImpl([Ss] SS_BLOCK_END_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_END_KEYWORD)('end_loop')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
1 change: 1 addition & 0 deletions src/test/testData/parser/Require.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% require themedCSS('dist/style') %>
14 changes: 14 additions & 0 deletions src/test/testData/parser/Require.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FILE
SilverstripePsiElementImpl([Ss] SS_STATEMENTS)
SilverstripePsiElementImpl([Ss] SS_REQUIRE_STATEMENT)
PsiElement(SS_BLOCK_START)('<%')
PsiWhiteSpace(' ')
PsiElement(SS_REQUIRE_KEYWORD)('require')
PsiWhiteSpace(' ')
PsiElement(SS_REQUIRE_THEMED_CSS)('themedCSS')
PsiElement(SS_LEFT_PARENTHESIS)('(')
SilverstripePsiElementImpl([Ss] SS_LOOKUP_STEP_ARGS)
PsiElement(SS_STRING)(''dist/style'')
PsiElement(SS_RIGHT_PARENTHESIS)(')')
PsiWhiteSpace(' ')
PsiElement(SS_BLOCK_END)('%>')
Loading

0 comments on commit 31d1161

Please sign in to comment.