[TEST] Extract language feature regex pattern to :test-infrastructure-utils
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.test.util
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
val LANGUAGE_FEATURE_PATTERN: Pattern = Pattern.compile("""(\+|-|warn:)(\w+)\s*""")
|
||||
+2
-4
@@ -10,14 +10,12 @@ import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
|
||||
import org.jetbrains.kotlin.test.services.DefaultsDsl
|
||||
import org.jetbrains.kotlin.test.util.LANGUAGE_FEATURE_PATTERN
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@DefaultsDsl
|
||||
class LanguageVersionSettingsBuilder {
|
||||
companion object {
|
||||
private val languageFeaturePattern = Pattern.compile("""(\+|-|warn:)(\w+)\s*""")
|
||||
|
||||
fun fromExistingSettings(builder: LanguageVersionSettingsBuilder): LanguageVersionSettingsBuilder {
|
||||
return LanguageVersionSettingsBuilder().apply {
|
||||
languageVersion = builder.languageVersion
|
||||
@@ -79,7 +77,7 @@ class LanguageVersionSettingsBuilder {
|
||||
}
|
||||
|
||||
private fun parseLanguageFeature(featureString: String) {
|
||||
val matcher = languageFeaturePattern.matcher(featureString)
|
||||
val matcher = LANGUAGE_FEATURE_PATTERN.matcher(featureString)
|
||||
if (!matcher.find()) {
|
||||
error(
|
||||
"""Wrong syntax in the '// !${LanguageSettingsDirectives.LANGUAGE.name}: ...' directive:
|
||||
|
||||
+2
-4
@@ -9,9 +9,9 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.test.Directives
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.LANGUAGE_FEATURE_PATTERN
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
const val LANGUAGE_DIRECTIVE = "LANGUAGE"
|
||||
const val API_VERSION_DIRECTIVE = "API_VERSION"
|
||||
@@ -117,10 +117,8 @@ fun setupLanguageVersionSettingsForCompilerTests(originalFileText: String, envir
|
||||
private fun <T : Any> analysisFlag(flag: AnalysisFlag<T>, value: @kotlin.internal.NoInfer T?): Pair<AnalysisFlag<T>, T>? =
|
||||
value?.let(flag::to)
|
||||
|
||||
private val languagePattern = Pattern.compile("(\\+|\\-|warn:)(\\w+)\\s*")
|
||||
|
||||
private fun collectLanguageFeatureMap(directives: String): Map<LanguageFeature, LanguageFeature.State> {
|
||||
val matcher = languagePattern.matcher(directives)
|
||||
val matcher = LANGUAGE_FEATURE_PATTERN.matcher(directives)
|
||||
if (!matcher.find()) {
|
||||
Assert.fail(
|
||||
"Wrong syntax in the '// !$LANGUAGE_DIRECTIVE: ...' directive:\n" +
|
||||
|
||||
Reference in New Issue
Block a user