Comments (4)
Hi @CamilYed,
can you provide a short code example? I'm not sure if I understand your question correctly.
from ast.
fun `some test`() {
Given:
repository.add(Order(id = 1))
When:
val order= repository.find(orderId = 1)
Then:
order != null
}
Like in Spock framework
https://github.com/CamilYed/readable-tests-by-example/blob/master/src/integrationTest/groovy/tech/allegro/blog/vinyl/shop/order/OrderPaymentAcceptanceSpec.groovy
Spock makes some AST modifications.
from ast.
Hi,
if you only want to write tests with given/when/then in kotlin, you can use kotest BehaviorSpec. If you really want to change the ast, you should try to implement a kotlin compiler plugin. I think it is not possible to add a new syntax, because the ast is parsed first and all compiler plugins are invoked after this. I think it is possible to change existing syntax like this:
fun main() {
given@ {
// ...
}
`when`@ {
// ...
}
then@ {
// ...
}
}
Here I have used "when" with grave accent because "when" is a keyword in kotlin and the ast created for the "when" part will be different compared to the ast created for the "given"/"then" parts.
You also have to keep in mind that many developers are puzzled by an unexpected syntax, because without background knowledge you don't understand it directly.
If you really want to try this, you should have a look at https://github.com/google/ksp.
This library here (kotlin-ast) is there to parse the code outline of a kotlin file. The code to parse the body of a function is currently not implemented, because I have no time for this. Therefore, it is not possible to parse your example code. Even when the missing code will be implemented, you can only parse the code, you will get a data class that you can analyse at runtime for a given kotlin file. Currently, there is also no code to transform this data class nor to convert it back into to kotlin file.
Please let me know if you have any questions.
from ast.
Hi,
thank you for clarifying that.
from ast.
Related Issues (20)
- Add a grammar for Kotlin Script
- org.antlr.v4.kotlinruntime.atn.ATNConfig object has a large number of instance counts, OOM
- Need "kts" scripts support
- How to Visit Each Node of an AST? HOT 2
- KotlinGrammarAntlrKotlinParser very slow for files with json-strings HOT 4
- Consider editing repository setings to remove "Packages" section HOT 2
- I am really confused, which dependency should be used? HOT 5
- End-of-line comments not available in summary HOT 2
- Property delegate not available in summary HOT 2
- Argument with unary prefix is incomplete in summary AST HOT 2
- Can I get the specified method code block HOT 3
- Record syntax error messages
- Why column is called row?
- Unsupported ast node functionType when function type used as generic type
- Publish somewhere different than jitpack.io HOT 10
- Is it possible to insert an element? HOT 2
- Add support for @JvmSuppressWildcards/ Annotations for types. HOT 4
- How can I get the specified method code block!Looking forward to answer
- How do I rely on this project on Maven? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ast.