-
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 #103 from orangain/node-extra
Now each node has extra information
- Loading branch information
Showing
20 changed files
with
779 additions
and
570 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
24 changes: 0 additions & 24 deletions
24
ast-psi/src/main/kotlin/ktast/ast/psi/ConverterWithMutableExtras.kt
This file was deleted.
Oops, something went wrong.
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,101 @@ | ||
package ktast.ast | ||
|
||
import ktast.ast.psi.Parser | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class DumperTest { | ||
|
||
private val code = """ | ||
val x = { | ||
// x is empty | ||
} | ||
""".trimIndent() | ||
|
||
@Test | ||
fun testWithExtrasAndProperties() { | ||
assertDumpedAs( | ||
code, | ||
""" | ||
Node.KotlinFile | ||
Node.Declaration.PropertyDeclaration | ||
Node.Keyword.Val{text="val"} | ||
Node.Variable | ||
BEFORE: Node.Extra.Whitespace{text=" "} | ||
Node.Expression.NameExpression{text="x"} | ||
AFTER: Node.Extra.Whitespace{text=" "} | ||
BEFORE: Node.Extra.Whitespace{text=" "} | ||
Node.Expression.LambdaExpression | ||
WITHIN: Node.Extra.Whitespace{text="\n "} | ||
WITHIN: Node.Extra.Comment{text="// x is empty"} | ||
WITHIN: Node.Extra.Whitespace{text="\n"} | ||
""".trimIndent(), | ||
withExtras = true, | ||
withProperties = true, | ||
) | ||
} | ||
|
||
@Test | ||
fun testWithExtrasButWithoutProperties() { | ||
assertDumpedAs( | ||
code, | ||
""" | ||
Node.KotlinFile | ||
Node.Declaration.PropertyDeclaration | ||
Node.Keyword.Val | ||
Node.Variable | ||
BEFORE: Node.Extra.Whitespace | ||
Node.Expression.NameExpression | ||
AFTER: Node.Extra.Whitespace | ||
BEFORE: Node.Extra.Whitespace | ||
Node.Expression.LambdaExpression | ||
WITHIN: Node.Extra.Whitespace | ||
WITHIN: Node.Extra.Comment | ||
WITHIN: Node.Extra.Whitespace | ||
""".trimIndent(), | ||
withExtras = true, | ||
withProperties = false, | ||
) | ||
} | ||
|
||
@Test | ||
fun testWithoutExtrasButWithProperties() { | ||
assertDumpedAs( | ||
code, | ||
""" | ||
Node.KotlinFile | ||
Node.Declaration.PropertyDeclaration | ||
Node.Keyword.Val{text="val"} | ||
Node.Variable | ||
Node.Expression.NameExpression{text="x"} | ||
Node.Expression.LambdaExpression | ||
""".trimIndent(), | ||
withExtras = false, | ||
withProperties = true, | ||
) | ||
} | ||
|
||
@Test | ||
fun testWithoutExtrasOrProperties() { | ||
assertDumpedAs( | ||
code, | ||
""" | ||
Node.KotlinFile | ||
Node.Declaration.PropertyDeclaration | ||
Node.Keyword.Val | ||
Node.Variable | ||
Node.Expression.NameExpression | ||
Node.Expression.LambdaExpression | ||
""".trimIndent(), | ||
withExtras = false, | ||
withProperties = false, | ||
) | ||
} | ||
|
||
private fun assertDumpedAs(code: String, expectedDump: String, withExtras: Boolean, withProperties: Boolean) { | ||
val node = Parser.parseFile(code) | ||
val actualDump = Dumper.dump(node, withExtras = withExtras, withProperties = withProperties) | ||
assertEquals(expectedDump.trim(), actualDump.trim()) | ||
} | ||
|
||
} |
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.