-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Service
intents
#23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the documentation and examples, I'm pretty confident that Exercise generates the Intent
class for the user by postfixing the annotated class name with Intent
. It would probably be helpful to call that out in the documentation.
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) | ||
|
||
val file = result.getGeneratedFile("NoExtrasServiceExercise.kt") | ||
assertThat(file.readText().trim()).isEqualToKotlin( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind blown. How lenient is isEqualToKotlin
? I imagine it doesn't care about whitespace? Can you change the expected code quite a bit (e.g. refer to a class by full package name without an import
) and that will still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a custom function, so don't get your hopes up. 😆 . I've considered making it more lenient, but I haven't had time to actually implement it. At this point, this is all it is:
/** Wrapper around [AbstractStringAssert.isEqualTo] for Kotlin code literals to syntax highlight in Android Studio. */
fun AbstractStringAssert<*>.isEqualToKotlin(
@Language("kotlin") source: String
): AbstractStringAssert<*> = this.isEqualTo(source.trimIndent())
The comment on there was the real value add of having this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I saw compile
then saw this and my mind went wild on the possibilities.
Still cool custom function but not quite as elaborate as what I unfairly imagined. 😝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #25. I don't think comparing parse trees would handle import changes, but it should at least handle things like whitespace
|
||
@Test | ||
fun `test service generation with no extras`() { | ||
val result = compile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about compile
, this is so cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a really cool tool here, one of those tiny libraries that supports the whole ecosystem. Room, dagger, and moshi all use it to test against kotlin sources.
Closes #18