Skip to content
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

Merged
merged 4 commits into from
Sep 1, 2020

Conversation

cedrickcooke
Copy link
Collaborator

Closes #18

@cedrickcooke cedrickcooke added this to the 0.8.0 milestone Aug 28, 2020
@cedrickcooke cedrickcooke requested a review from a team August 28, 2020 00:49
Copy link
Member

@twyatt twyatt left a 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(
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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. 😝

Copy link
Collaborator Author

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(
Copy link
Member

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!

Copy link
Collaborator Author

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.

@cedrickcooke cedrickcooke merged commit 8d55c6c into master Sep 1, 2020
@cedrickcooke cedrickcooke deleted the cedrickc/support-for-services branch September 1, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for services
3 participants