From a7a2edb6382a7942c8b915d5e89f58b2b63c4c21 Mon Sep 17 00:00:00 2001 From: Dmitry Kandalov Date: Sun, 27 Aug 2023 16:21:57 +0100 Subject: [PATCH] tidy up --- parser4k/src/main/kotlin/parser4k/associativity.kt | 4 +--- parser4k/src/main/kotlin/parser4k/util-generated.kt | 2 +- .../test/kotlin/parser4k/examples/expression-lang.kt | 5 ++--- .../src/test/kotlin/parser4k/output-cache-tests.kt | 4 ++-- .../kotlin/dev/forkhandles/result4k/petStoreExample.kt | 10 +++++----- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/parser4k/src/main/kotlin/parser4k/associativity.kt b/parser4k/src/main/kotlin/parser4k/associativity.kt index 8cb65e2..de31ce9 100644 --- a/parser4k/src/main/kotlin/parser4k/associativity.kt +++ b/parser4k/src/main/kotlin/parser4k/associativity.kt @@ -31,6 +31,4 @@ fun InOrder.mapLeftAssoc(transform: (List) -> T) = object : Parser } } -private object RightRecursionMarker { - override fun toString() = "RightRecursionMarker" -} +private data object RightRecursionMarker diff --git a/parser4k/src/main/kotlin/parser4k/util-generated.kt b/parser4k/src/main/kotlin/parser4k/util-generated.kt index 600865c..b060384 100644 --- a/parser4k/src/main/kotlin/parser4k/util-generated.kt +++ b/parser4k/src/main/kotlin/parser4k/util-generated.kt @@ -1,4 +1,4 @@ -@file:Suppress("UNCHECKED_CAST", "unused") +@file:Suppress("unused") package parser4k diff --git a/parser4k/src/test/kotlin/parser4k/examples/expression-lang.kt b/parser4k/src/test/kotlin/parser4k/examples/expression-lang.kt index 14ddbd0..3c034b3 100644 --- a/parser4k/src/test/kotlin/parser4k/examples/expression-lang.kt +++ b/parser4k/src/test/kotlin/parser4k/examples/expression-lang.kt @@ -48,7 +48,6 @@ import parser4k.shouldEqual import parser4k.skipWrapper import parser4k.str import parser4k.with -import java.util.Locale private object ExpressionLang { private val cache = OutputCache() @@ -121,8 +120,8 @@ private object ExpressionLang { fun evaluate(s: String): Any = s.parseWith(expr).eval() sealed class Expr { - object True : Expr() - object False : Expr() + data object True : Expr() + data object False : Expr() data class IntLiteral(val value: Int) : Expr() data class StringLiteral(val value: String) : Expr() data class ArrayLiteral(val value: List) : Expr() diff --git a/parser4k/src/test/kotlin/parser4k/output-cache-tests.kt b/parser4k/src/test/kotlin/parser4k/output-cache-tests.kt index bf34b3a..db1fd09 100644 --- a/parser4k/src/test/kotlin/parser4k/output-cache-tests.kt +++ b/parser4k/src/test/kotlin/parser4k/output-cache-tests.kt @@ -22,7 +22,7 @@ class `Parsing log example for cached plus-minus-int grammar` { } @Test - fun `"123" parsing log`() { + fun `log when parsing '123'`() { "123".parseWith(plusMinusGrammar.expr) shouldEqual IntLiteral(123) logEvents.toDebugString() shouldEqual """ @@ -60,7 +60,7 @@ class `Cached parsers are called at most one time at each offset` { } @Test - fun `"123" parsing log`() { + fun `log when parsing '123'`() { "123".parseWith(plusMinusGrammar.expr) logEvents.toDebugString() shouldEqual """ "123" plus:0 diff --git a/result4k/core/src/test/kotlin/dev/forkhandles/result4k/petStoreExample.kt b/result4k/core/src/test/kotlin/dev/forkhandles/result4k/petStoreExample.kt index c025607..66ac726 100644 --- a/result4k/core/src/test/kotlin/dev/forkhandles/result4k/petStoreExample.kt +++ b/result4k/core/src/test/kotlin/dev/forkhandles/result4k/petStoreExample.kt @@ -28,12 +28,12 @@ class PetStoreExample( // perform some pre-validation; explicitly return failure if they fail if (humanId in blacklist) return Failure(PetError.OwnerBlacklisted) if (adoptions.any { it.pet.id == petId }) return Failure(PetError.PetNotForAdoption) + val pet = pets.find { it.id == petId } ?: return Failure(PetError.PetNotFound) - return pets - .find { it.id == petId } - .asResultOr { PetError.PetNotFound } // convert to failure if pet not found - .map { pet -> Adoption(humanId, pet) } // if pet found, convert to Adoption and return - .peek { adoption -> adoptions += adoption } // Perform a side-effect with the success value + val adoption = Adoption(humanId, pet) + adoptions += adoption + + return Success(adoption) } fun brag(adoption: Adoption) {