Skip to content

Commit

Permalink
Unify naming of generated functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiSikora committed Oct 8, 2020
1 parent 6fab079 commit 62e8919
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ enum class PowerPlant(override val isFallbackValue: Boolean = false) : Feature<P

// Generated by 'generateSourcedFeatureStorage'

internal fun FeatureStorage.Companion.generatedSourced(
internal fun FeatureStorage.Companion.sourcedGenerated(
localSource: FeatureStorage,
firebaseSource: FeatureStorage,
awsSource: FeatureStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class SourcedFeatureStorageGenerator(

private val infixTo = MemberName("kotlin", "to")

private val storageExtension = FunSpec.builder("generatedSourced")
private val storageExtension = FunSpec.builder("sourcedGenerated")
.addModifiers(storage.visibility.modifier)
.receiver(FeatureStorage.Companion::class)
.returns(FeatureStorage::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SourcedFeatureStorageModel private constructor(
internal val packageName: String,
internal val sourceNames: List<String>,
) {
internal val name = "GeneratedSourcedFeatureStorage"
internal val name = "sourcedGeneratedFeatureStorage"
internal val fqcn = if (packageName.isEmpty()) name else "$packageName.$name"

fun build(): Either<GenerationFailure, SourcedFeatureStorageModel> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SourcedFeatureStorageSpec : DescribeSpec({
|import kotlin.collections.mapOf
|import kotlin.to
|
|internal fun FeatureStorage.Companion.generatedSourced(
|internal fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| firebaseSource: FeatureStorage,
| s3Source: FeatureStorage
Expand Down Expand Up @@ -106,7 +106,7 @@ class SourcedFeatureStorageSpec : DescribeSpec({
|import kotlin.collections.mapOf
|import kotlin.to
|
|fun FeatureStorage.Companion.generatedSourced(
|fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| firebaseSource: FeatureStorage,
| s3Source: FeatureStorage
Expand Down Expand Up @@ -138,7 +138,7 @@ class SourcedFeatureStorageSpec : DescribeSpec({
|import kotlin.collections.mapOf
|import kotlin.to
|
|fun FeatureStorage.Companion.generatedSourced(
|fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| fooSource: FeatureStorage,
| barSource: FeatureStorage,
Expand Down Expand Up @@ -181,7 +181,7 @@ class SourcedFeatureStorageSpec : DescribeSpec({
|import kotlin.collections.mapOf
|import kotlin.to
|
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage,
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage,
| fooSource: FeatureStorage): FeatureStorage = sourced(
| localSource,
| mapOf(
Expand All @@ -208,7 +208,7 @@ class SourcedFeatureStorageSpec : DescribeSpec({
|import io.mehow.laboratory.FeatureStorage.Companion.sourced
|import kotlin.collections.emptyMap
|
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage): FeatureStorage =
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage): FeatureStorage =
| sourced(
| localSource,
| emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage): FeatureStorage
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage): FeatureStorage
| = sourced(
| localSource,
| emptyMap()
Expand All @@ -57,11 +57,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(
|fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| remoteASource: FeatureStorage,
| remoteBSource: FeatureStorage
Expand All @@ -80,7 +80,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

gradleRunner.withProjectDir(fixture).build()

val factory = fixture.sourcedStorageFile("io.mehow.implicit.GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("io.mehow.implicit.sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain "package io.mehow.implicit"
Expand All @@ -91,7 +91,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

gradleRunner.withProjectDir(fixture).build()

val factory = fixture.sourcedStorageFile("io.mehow.explicit.GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("io.mehow.explicit.sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain "package io.mehow.explicit"
Expand All @@ -102,7 +102,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

gradleRunner.withProjectDir(fixture).build()

val factory = fixture.sourcedStorageFile("io.mehow.explicit.GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("io.mehow.explicit.sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain "package io.mehow.explicit"
Expand All @@ -113,25 +113,25 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

gradleRunner.withProjectDir(fixture).build()

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain "internal fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage)"
factory.readText() shouldContain "internal fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage)"
}

"generates public storage" {
val fixture = "sourced-storage-generate-public".toFixture()

gradleRunner.withProjectDir(fixture).build()

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

// Ensure public by checking a new line before enum declaration.
// Change after https://github.com/square/kotlinpoet/pull/933
factory.readText() shouldContain """
|
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage)
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage)
""".trimMargin("|")
}

Expand All @@ -141,9 +141,9 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
val result = gradleRunner.withProjectDir(fixture).buildAndFail()

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain InvalidPackageName("!!!.GeneratedSourcedFeatureStorage").message
result.output shouldContain InvalidPackageName("!!!.sourcedGeneratedFeatureStorage").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -155,7 +155,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain NoFeatureValues("Feature").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -167,7 +167,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain FeatureValuesCollision("First".nel(), "Feature").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -179,7 +179,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain InvalidFeatureValues(NonEmptyList("!!!, ???"), "Feature").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -191,7 +191,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain InvalidFeatureName("!!!", "!!!").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -203,7 +203,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain InvalidPackageName("!!!.Feature").message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -215,7 +215,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain FeaturesCollision("io.mehow.Feature".nel()).message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -226,11 +226,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(
|fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| remoteSource: FeatureStorage,
| remoteASource: FeatureStorage,
Expand All @@ -253,11 +253,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(
|fun FeatureStorage.Companion.sourcedGenerated(
| localSource: FeatureStorage,
| remoteSource: FeatureStorage,
| remoteBSource: FeatureStorage
Expand All @@ -279,7 +279,7 @@ class GenerateSourcedStorageTaskSpec : StringSpec({
result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe FAILED
result.output shouldContain FeaturesCollision("Feature".nel()).message

val feature = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val feature = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
feature.shouldNotExist()
}

Expand All @@ -290,11 +290,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage): FeatureStorage
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage): FeatureStorage
| = sourced(
| localSource,
| emptyMap()
Expand All @@ -309,11 +309,11 @@ class GenerateSourcedStorageTaskSpec : StringSpec({

result.task(":generateSourcedFeatureStorage")!!.outcome shouldBe SUCCESS

val factory = fixture.sourcedStorageFile("GeneratedSourcedFeatureStorage")
val factory = fixture.sourcedStorageFile("sourcedGeneratedFeatureStorage")
factory.shouldExist()

factory.readText() shouldContain """
|fun FeatureStorage.Companion.generatedSourced(localSource: FeatureStorage): FeatureStorage
|fun FeatureStorage.Companion.sourcedGenerated(localSource: FeatureStorage): FeatureStorage
| = sourced(
| localSource,
| emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SampleApplication : Application() {
val awsStorage = SharedPreferencesFeatureStorage(
getSharedPreferences("awsFeatures", MODE_PRIVATE)
)
val sourcedStorage = FeatureStorage.generatedSourced(
val sourcedStorage = FeatureStorage.sourcedGenerated(
localSource = localStorage,
firebaseSource = firebaseStorage,
awsSource = awsStorage,
Expand Down

0 comments on commit 62e8919

Please sign in to comment.