-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from orangain/heuristic-whitespaces
Heuristic whitespaces and semicolons
- Loading branch information
Showing
11 changed files
with
332 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
ast-psi/src/test/kotlin/ktast/ast/psi/CorpusParseAndWriteHeuristicTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ktast.ast.psi | ||
|
||
import ktast.ast.Dumper | ||
import ktast.ast.Writer | ||
import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtilRt | ||
import org.junit.Assume | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(Parameterized::class) | ||
class CorpusParseAndWriteHeuristicTest(private val unit: Corpus.Unit) { | ||
|
||
@Test | ||
fun testParseAndWriteHeuristic() { | ||
// In order to test, we parse the test code (failing and validating errors if present), | ||
// convert to our AST, write out our AST, re-parse what we wrote, re-convert, and compare | ||
try { | ||
val origCode = StringUtilRt.convertLineSeparators(unit.read()) | ||
println("----ORIG CODE----\n$origCode\n------------") | ||
val origFile = Parser.parseFile(origCode) | ||
val origDump = Dumper.dump(origFile) | ||
println("----ORIG AST----\n$origDump\n------------") | ||
|
||
val newCode = Writer.write(origFile) | ||
println("----NEW CODE----\n$newCode\n-----------") | ||
val newFile = Parser.parseFile(newCode) | ||
val newDump = Dumper.dump(newFile) | ||
|
||
assertEquals(origDump, newDump) | ||
assertEquals(origFile, newFile) | ||
} catch (e: Converter.Unsupported) { | ||
Assume.assumeNoException(e.message, e) | ||
} catch (e: Parser.ParseError) { | ||
if (unit.errorMessages.isEmpty()) throw e | ||
assertEquals(unit.errorMessages.toSet(), e.errors.map { it.errorDescription }.toSet()) | ||
Assume.assumeTrue("Partial parsing not supported (expected parse errors: ${unit.errorMessages})", false) | ||
} | ||
} | ||
|
||
companion object { | ||
const val debug = false | ||
|
||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun data() = Corpus.default | ||
// Uncomment to test a specific file | ||
//.filter { it.relativePath.toString().endsWith("list\\basic.kt") } | ||
|
||
// Good for quick testing | ||
// @JvmStatic @Parameterized.Parameters(name = "{0}") | ||
// fun data() = listOf(Corpus.Unit.FromString("temp", """ | ||
// val lambdaType: (@A() (() -> C)) | ||
// """)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum class Color(val rgb : Int) { | ||
RED(0xFF000), | ||
GREEN(0x00FF00), | ||
BLUE(0x0000FF), | ||
; | ||
fun draw() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.