Add lexer test runner and whitespace characters tests
Whitespace characters for the tests are U+000B, U+000C, U+000D, U+0085, U+2028, U+2029
This commit is contained in:
@@ -29,7 +29,8 @@ import org.jetbrains.kotlin.ir.AbstractIrSourceRangesTestCase
|
||||
import org.jetbrains.kotlin.ir.AbstractIrTextTestCase
|
||||
import org.jetbrains.kotlin.jvm.compiler.*
|
||||
import org.jetbrains.kotlin.jvm.compiler.javac.AbstractLoadJavaUsingJavacTest
|
||||
import org.jetbrains.kotlin.kdoc.AbstractKDocLexerTest
|
||||
import org.jetbrains.kotlin.lexer.kdoc.AbstractKDocLexerTest
|
||||
import org.jetbrains.kotlin.lexer.kotlin.AbstractKotlinLexerTest
|
||||
import org.jetbrains.kotlin.modules.xml.AbstractModuleXmlParserTest
|
||||
import org.jetbrains.kotlin.multiplatform.AbstractMultiPlatformIntegrationTest
|
||||
import org.jetbrains.kotlin.parsing.AbstractParsingTest
|
||||
@@ -350,7 +351,11 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
testClass<AbstractKDocLexerTest> {
|
||||
model("kdoc/lexer")
|
||||
model("lexer/kdoc")
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinLexerTest> {
|
||||
model("lexer/kotlin")
|
||||
}
|
||||
|
||||
testClass<AbstractIrBlackBoxCodegenTest> {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.kdoc
|
||||
|
||||
import com.intellij.lang.TokenWrapper
|
||||
import com.intellij.lexer.Lexer
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocLexer
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKDocLexerTest : TestCase() {
|
||||
protected fun doTest(fileName: String) {
|
||||
val text = File(fileName).readText()
|
||||
val lexerResult = printTokens(StringUtil.convertLineSeparators(text), 0, KDocLexer())
|
||||
KtUsefulTestCase.assertSameLinesWithFile(fileName.replaceAfterLast(".", "txt"), lexerResult)
|
||||
}
|
||||
|
||||
fun printTokens(text: CharSequence, start: Int, lexer: Lexer): String {
|
||||
lexer.start(text, start, text.length)
|
||||
var result = ""
|
||||
while (true) {
|
||||
val tokenType = lexer.tokenType ?: break
|
||||
val tokenText = getTokenText(lexer)
|
||||
val tokenTypeName = tokenType.toString()
|
||||
val line = "$tokenTypeName ('$tokenText')\n"
|
||||
result += line
|
||||
lexer.advance()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getTokenText(lexer: Lexer): String {
|
||||
val tokenType = lexer.tokenType
|
||||
if (tokenType is TokenWrapper) {
|
||||
return tokenType.value
|
||||
}
|
||||
|
||||
var text = lexer.bufferSequence.subSequence(lexer.tokenStart, lexer.tokenEnd).toString()
|
||||
text = StringUtil.replace(text, "\n", "\\n")
|
||||
return text
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lexer
|
||||
|
||||
import com.intellij.lang.TokenWrapper
|
||||
import com.intellij.lexer.Lexer
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractLexerTest(private val lexer: Lexer) : TestCase() {
|
||||
protected fun doTest(fileName: String) {
|
||||
val text = File(fileName).readText()
|
||||
val lexerResult = printTokens(StringUtil.convertLineSeparators(text), 0, lexer)
|
||||
|
||||
KtUsefulTestCase.assertSameLinesWithFile(fileName.replaceAfterLast(".", "txt"), lexerResult)
|
||||
}
|
||||
|
||||
private fun printTokens(text: CharSequence, start: Int, lexer: Lexer): String {
|
||||
lexer.start(text, start, text.length)
|
||||
|
||||
return buildString {
|
||||
while (true) {
|
||||
val tokenType = lexer.tokenType ?: break
|
||||
append("$tokenType ('${getTokenText(lexer)}')\n")
|
||||
lexer.advance()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTokenText(lexer: Lexer): String {
|
||||
val tokenType = lexer.tokenType
|
||||
|
||||
if (tokenType is TokenWrapper)
|
||||
return tokenType.value
|
||||
|
||||
val result = lexer.bufferSequence.subSequence(lexer.tokenStart, lexer.tokenEnd).toString()
|
||||
|
||||
return StringUtil.replace(result, "\n", "\\n")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lexer.kdoc
|
||||
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocLexer
|
||||
import org.jetbrains.kotlin.lexer.AbstractLexerTest
|
||||
|
||||
abstract class AbstractKDocLexerTest : AbstractLexerTest(KDocLexer())
|
||||
+10
-5
@@ -3,7 +3,7 @@
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.kdoc;
|
||||
package org.jetbrains.kotlin.lexer.kdoc;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
@@ -17,7 +17,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/kdoc/lexer")
|
||||
@TestMetadata("compiler/testData/lexer/kdoc")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KDocLexerTestGenerated extends AbstractKDocLexerTest {
|
||||
@@ -25,12 +25,17 @@ public class KDocLexerTestGenerated extends AbstractKDocLexerTest {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLexer() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/kdoc/lexer"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
public void testAllFilesPresentInKdoc() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kdoc"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("codeBlocks.kt")
|
||||
public void testCodeBlocks() throws Exception {
|
||||
runTest("compiler/testData/kdoc/lexer/codeBlocks.kt");
|
||||
runTest("compiler/testData/lexer/kdoc/codeBlocks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("codeBlocksWithVerticalTabs.kt")
|
||||
public void testCodeBlocksWithVerticalTabs() throws Exception {
|
||||
runTest("compiler/testData/lexer/kdoc/codeBlocksWithVerticalTabs.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lexer.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.lexer.AbstractLexerTest
|
||||
import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||
|
||||
|
||||
abstract class AbstractKotlinLexerTest : AbstractLexerTest(KotlinLexer())
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lexer.kotlin;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/lexer/kotlin")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinLexerTestGenerated extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlin() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class WhitespaceCharacters extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInWhitespaceCharacters() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/carriageReturn")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class CarriageReturn extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInCarriageReturn() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/carriageReturn"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("carriageReturn.kt")
|
||||
public void testCarriageReturn() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/carriageReturn/carriageReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("carriageReturnInComments.kt")
|
||||
public void testCarriageReturnInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/carriageReturn/carriageReturnInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("carriageReturnInStringLiterals.kt")
|
||||
public void testCarriageReturnInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/carriageReturn/carriageReturnInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/lineSeparator")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class LineSeparator extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLineSeparator() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/lineSeparator"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("lineSeparator.kt")
|
||||
public void testLineSeparator() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/lineSeparator/lineSeparator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lineSeparatorInComments.kt")
|
||||
public void testLineSeparatorInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/lineSeparator/lineSeparatorInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lineSeparatorInStringLiterals.kt")
|
||||
public void testLineSeparatorInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/lineSeparator/lineSeparatorInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/nextLine")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class NextLine extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNextLine() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/nextLine"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("nextLine.kt")
|
||||
public void testNextLine() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/nextLine/nextLine.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nextLineInComments.kt")
|
||||
public void testNextLineInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/nextLine/nextLineInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nextLineInStringLiterals.kt")
|
||||
public void testNextLineInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/nextLine/nextLineInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/pageBreak")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class PageBreak extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPageBreak() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/pageBreak"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("pageBreak.kt")
|
||||
public void testPageBreak() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/pageBreak/pageBreak.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("pageBreakInComments.kt")
|
||||
public void testPageBreakInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/pageBreak/pageBreakInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("pageBreakInStringLiterals.kt")
|
||||
public void testPageBreakInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/pageBreak/pageBreakInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/paragraphSeparator")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ParagraphSeparator extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInParagraphSeparator() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/paragraphSeparator"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("paragraphSeparator.kt")
|
||||
public void testParagraphSeparator() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/paragraphSeparator/paragraphSeparator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("paragraphSeparatorInComments.kt")
|
||||
public void testParagraphSeparatorInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/paragraphSeparator/paragraphSeparatorInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("paragraphSeparatorInStringLiterals.kt")
|
||||
public void testParagraphSeparatorInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/paragraphSeparator/paragraphSeparatorInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/lexer/kotlin/whitespaceCharacters/verticalTab")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class VerticalTab extends AbstractKotlinLexerTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInVerticalTab() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lexer/kotlin/whitespaceCharacters/verticalTab"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("verticalTab.kt")
|
||||
public void testVerticalTab() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/verticalTab/verticalTab.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("verticalTabInComments.kt")
|
||||
public void testVerticalTabInComments() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/verticalTab/verticalTabInComments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("verticalTabInStringLiterals.kt")
|
||||
public void testVerticalTabInStringLiterals() throws Exception {
|
||||
runTest("compiler/testData/lexer/kotlin/whitespaceCharacters/verticalTab/verticalTabInStringLiterals.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user