Skip to content

Commit

Permalink
Allow dashes and underscore in unquoted keys in serializer. (#17)
Browse files Browse the repository at this point in the history
* Bump dependency versions.

* Allow dashes and underscore in unquoted keys in serializer. Fixes #14.
  • Loading branch information
valderman committed Sep 19, 2022
1 parent 652a0c6 commit a2f4619
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
17 changes: 10 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.inputStream

plugins {
kotlin("jvm") version "1.7.0"
id("org.jetbrains.dokka") version "1.7.0"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
kotlin("jvm") version "1.7.20-RC"
id("org.jetbrains.dokka") version "1.7.10"
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("com.github.ben-manes.versions") version "0.42.0"
`maven-publish`
antlr
Expand Down Expand Up @@ -63,8 +63,8 @@ publishing {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
antlr("org.antlr", "antlr4", "4.10.1")
implementation("org.antlr", "antlr4-runtime", "4.10.1")
antlr("org.antlr", "antlr4", "4.11.1")
implementation("org.antlr", "antlr4-runtime", "4.11.1")

testImplementation(kotlin("test"))
}
Expand All @@ -81,8 +81,11 @@ ktlint {
data class DependencyVersion(val module: String, val version: String)

val excludedVersions: Set<Pair<String, String>> = setOf(
"ktlint" to "0.46.0", // Crashes when running any ktlint target
"ktlint" to "0.46.1" // Crashes when running any ktlint target
// Ktlint >=0.46 doesn't work with the ktlint plugin.
"ktlint" to "0.46.0",
"ktlint" to "0.46.1",
"ktlint" to "0.47.0",
"ktlint" to "0.47.1",
)

tasks {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private fun encodeKey(key: String): String = when {
}
}

private val quotesRequiredRegex = Regex("[^a-zA-Z0-9]")
private val quotesRequiredRegex = Regex("[^a-zA-Z0-9_-]")

private enum class QuoteType(val quotes: String) {
Plain("\""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ class BuiltinSerializerTests : UnitTest {
)
}

@Test
fun `serializer should not quote keys because of underscores`() {
assertSerializesTo(
TomlValue.Map("foo_foo" to TomlValue.String("bar")),
"foo_foo = \"bar\""
)
}

@Test
fun `serializer should not quote keys because of dashes`() {
assertSerializesTo(
TomlValue.Map("foo-foo" to TomlValue.String("bar")),
"foo-foo = \"bar\""
)
}

@Test
fun `digit-only keys are ok`() {
assertSerializesTo(
TomlValue.Map("123" to TomlValue.String("bar")),
"123 = \"bar\""
)
}

@Test
fun `can't serialize string with invalid chars`() {
val error = assertFailsWith<TomlException.SerializationError> {
Expand Down

0 comments on commit a2f4619

Please sign in to comment.