Skip to content

Commit

Permalink
Merge pull request #31 from Cleverlance/feature/splitting_to_files
Browse files Browse the repository at this point in the history
Added file splitting
  • Loading branch information
RadekKuzel authored Jun 18, 2024
2 parents c98c2e7 + c34813e commit 2493556
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 356 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ subprojects {
apply<MavenPublishPlugin>()

group = "io.github.cleverlance.linguine"
version = System.getenv("NEXT_VERSION") ?: "0.1.0"
version = System.getenv("NEXT_VERSION") ?: "0.2.0"

mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FileParserTest {

val expectedOutput = mapOf<String, Any>()

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -27,30 +27,30 @@ class FileParserTest {
val fileParser = fileParser(fileContent = mapContent)

val expectedOutput = mapOf(
"singleKey" to "singleKey",
"SingleKey" to mapOf("singleKey" to ("singleKey" to "Single Value")),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}

@Test
fun `generateNestedMapStructure with mixed case keys creates consistent camelCase output`() {
val mapContent = mapOf(
"activation__ForgottenPassword__emailInput" to "Enter your email",
"activation__forgottenPassword__emailInput" to "Enter your email",
)
val fileParser = fileParser(fileContent = mapContent)

val expectedOutput = mapOf(
"Activation" to mapOf(
"ForgottenPassword" to mapOf(
"emailInput" to "activation__ForgottenPassword__emailInput",
),
),
"emailInput" to ("activation__forgottenPassword__emailInput" to "Enter your email")
)
)
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -67,14 +67,14 @@ class FileParserTest {
"" to mapOf(
"ForgottenPassword" to mapOf(
"Email" to mapOf(
"input" to "activation____forgotten_password__email__input",
"input" to ("activation____forgotten_password__email__input" to "Email Input"),
),
),
),
),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -97,34 +97,35 @@ class FileParserTest {
"Activation" to mapOf(
"ForgottenPassword" to mapOf(
"Birthdate" to mapOf(
"cancelButton" to "activation__forgotten_password__birthdate__cancel_button",
"cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to "Cancel"),
),
"emailInput" to "activation__forgotten_password__email_input",
"emailInput" to ("activation__forgotten_password__email_input" to "Enter your email"),
),
),
"Home" to mapOf(
"welcomeMessage" to "home__welcome_message",
"welcomeMessage" to ("home__welcome_message" to "Welcome to our application!"),
),
"Profile" to mapOf(
"Settings" to mapOf(
"Privacy" to mapOf(
"title" to "profile__settings__privacy__title",
"description" to "profile__settings__privacy__description",
"title" to ("profile__settings__privacy__title" to "Privacy Settings"),
"description" to ("profile__settings__privacy__description" to
"Manage your privacy settings here."),
),
),
),
"Checkout" to mapOf(
"Payment" to mapOf(
"CreditCard" to mapOf(
"numberInput" to "checkout__payment__credit_card__number_input",
"expiryDate" to "checkout__payment__credit_card__expiry_date",
"cvv" to "checkout__payment__credit_card__cvv",
"numberInput" to ("checkout__payment__credit_card__number_input" to "Credit Card Number"),
"expiryDate" to ("checkout__payment__credit_card__expiry_date" to "Expiry Date"),
"cvv" to ("checkout__payment__credit_card__cvv" to "CVV"),
),
),
),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -141,16 +142,17 @@ class FileParserTest {
"Profile" to mapOf(
"Settings" to mapOf(
"Privacy" to mapOf(
"privacyPolicy" to ("profile__settings__privacy__privacy_policy" to "Privacy Policy"),
"PrivacyPolicy" to mapOf(
"details" to "profile__settings__privacy__privacy_policy__details",
),
"privacyPolicy" to "profile__settings__privacy__privacy_policy",
"details" to ("profile__settings__privacy__privacy_policy__details" to
"Detailed description")
)
),
),
),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -168,15 +170,15 @@ class FileParserTest {
"Config" to mapOf(
"Database" to mapOf(
"Settings" to mapOf(
"maxConnections" to "system__config__database__settings__max_connections",
"timeout" to "system__config__database__settings__timeout",
"maxConnections" to ("system__config__database__settings__max_connections" to "100"),
"timeout" to ("system__config__database__settings__timeout" to "30"),
),
),
),
),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand All @@ -192,13 +194,13 @@ class FileParserTest {
val expectedOutput = mapOf(
"User" to mapOf(
"Name" to mapOf(
"first name" to "user__name__first name",
"last-name" to "user__name__last-name",
"first name" to ("user__name__first name" to "John"),
"last-name" to ("user__name__last-name" to "Doe"),
),
),
)

val result = fileParser.generateNestedMapStructure()
val result = fileParser.generateGroupedMapStructure()

result shouldBe expectedOutput
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ class LinguinePluginFunctionalTest {
plugins {
id("io.github.cleverlance.linguine")
}
linguineConfig {
inputFilePath = "src/main/resources/string.json"
outputFilePath = "${
testProjectDir.absolutePath.replace(
'\\',
'/',
)
}/presentation"
outputFileName = "Strings.kt"
outputFilePath = "${'$'}{projectDir}/presentation"
}
""".trimIndent(),
)
Expand Down Expand Up @@ -62,17 +56,16 @@ class LinguinePluginFunctionalTest {
testProjectDir.resolve(gradleBuildFileName).apply {
writeText(
"""
plugins {
id("io.github.cleverlance.linguine")
}
linguineConfig {
inputFilePath = "src/main/resources/strings.json"
outputFilePath = "${testProjectDir.absolutePath.replace('\\', '/')}/src/main/kotlin/presentation"
outputFileName = "Strings.kt"
majorDelimiter = "__"
minorDelimiter = "_"
}
plugins {
id("io.github.cleverlance.linguine")
}
linguineConfig {
inputFilePath = "src/main/resources/strings.json"
outputFilePath = "${'$'}{projectDir}/src/main/kotlin/presentation"
majorDelimiter = "__"
minorDelimiter = "_"
}
""".trimIndent(),
)
}
Expand All @@ -81,10 +74,10 @@ class LinguinePluginFunctionalTest {
parentFile.mkdirs()
writeText(
"""
{
"activation__forgotten_password__birthdate__log_in": "Přihlásit se",
"activation__forgotten_password__birthdate__log_out": "%s %d %f %${'$'}s %${'$'}d %${'$'}f"
}
{
"activation__forgotten_password__birthdate__log_in": "Přihlásit se",
"activation__forgotten_password__birthdate__log_out": "%s %d %f %${'$'}s %${'$'}d %${'$'}f"
}
""".trimIndent(),
)
}
Expand All @@ -93,12 +86,17 @@ class LinguinePluginFunctionalTest {
.withProjectDir(testProjectDir)
.withArguments(generateTaskName)
.withPluginClasspath()
.forwardOutput()
.build()

println(result.output)

assertTrue(result.output.contains(buildSuccessOutput), "Build should be successful")

val generatedFile = File(testProjectDir, "src/main/kotlin/presentation/Strings.kt")
val generatedFile =
File(testProjectDir, "src/main/kotlin/presentation/ActivationStrings.kt")
assertTrue(generatedFile.exists(), "Generated file should exist")

val actualContent = generatedFile.readText()
val expectedContent = """
package presentation
Expand All @@ -108,28 +106,26 @@ class LinguinePluginFunctionalTest {
import kotlin.Int
import kotlin.String
public object Strings {
public object Activation {
public object ForgottenPassword {
public object Birthdate {
public val logIn: String =
localise("activation__forgotten_password__birthdate__log_in")
public fun logOut(
param1: String,
param2: Int,
param3: Float,
param4: String,
param5: Int,
param6: Float,
): String = localise("activation__forgotten_password__birthdate__log_out", param1,
param2, param3, param4, param5, param6)
}
public object Activation {
public object ForgottenPassword {
public object Birthdate {
public val logIn: String = localise("activation__forgotten_password__birthdate__log_in")
public fun logOut(
param1: String,
param2: Int,
param3: Float,
param4: String,
param5: Int,
param6: Float,
): String = localise("activation__forgotten_password__birthdate__log_out", param1,
param2, param3, param4, param5, param6)
}
}
}
""".trimIndent()

kotlin.test.assertEquals(
expectedContent,
actualContent,
Expand All @@ -154,7 +150,6 @@ class LinguinePluginFunctionalTest {
linguineConfig {
inputFilePath = "src/main/resources/strings.json"
outputFilePath = "$projectDirPath/presentation"
outputFileName = "Strings.kt"
}
""".trimIndent()

Expand All @@ -181,17 +176,23 @@ class LinguinePluginFunctionalTest {

assertTrue(result.output.contains(buildSuccessOutput), "Build should be successful")

val expectedSuccessMessagePart =
"File ActivationStrings.kt has been successfully created in the directory"
assertTrue(
result.output.contains("File Strings.kt has been successfully created in the directory"),
"Success message was not printed",
result.output.contains(expectedSuccessMessagePart),
"Success message was not printed correctly",
)

val expectedOutputPath =
Paths.get(testProjectDir.path, "presentation", "Strings.kt").toString()
Paths.get(testProjectDir.path, "presentation", "ActivationStrings.kt").toString()
.replace('\\', '/')
assertTrue(File(expectedOutputPath).exists(), "Output file should exist")
assertTrue(
result.output.contains(expectedOutputPath),
"Expected output file path '$expectedOutputPath' was not found in the build output.",
)
val outputPathComponents = expectedOutputPath.split('/')
outputPathComponents.forEach { component ->
assertTrue(
result.output.contains(component),
"Expected output path component '$component' was not found in the build output.",
)
}
}
}
Loading

0 comments on commit 2493556

Please sign in to comment.