This repository was archived by the owner on Apr 4, 2024. It is now read-only.
forked from diffplug/selfie
-
Notifications
You must be signed in to change notification settings - Fork 1
This repository was archived by the owner on Apr 4, 2024. It is now read-only.
LiteralBoolean and LiteralFormat #36
Copy link
Copy link
Closed
Description
Epic: inline Snapshot #8
Implementations: https://github.com/diffplug/selfie-python-wip/blob/main/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/Literals.kt
selfie-python-wip/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/Literals.kt
Lines 47 to 54 in eb4560c
| abstract class LiteralFormat<T : Any> { | |
| internal abstract fun encode( | |
| value: T, | |
| language: Language, | |
| encodingPolicy: EscapeLeadingWhitespace | |
| ): String | |
| internal abstract fun parse(str: String, language: Language): T | |
| } |
selfie-python-wip/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/Literals.kt
Lines 350 to 361 in eb4560c
| internal object LiteralBoolean : LiteralFormat<Boolean>() { | |
| override fun encode( | |
| value: Boolean, | |
| language: Language, | |
| encodingPolicy: EscapeLeadingWhitespace | |
| ): String { | |
| return value.toString() | |
| } | |
| override fun parse(str: String, language: Language): Boolean { | |
| return str.toBooleanStrict() | |
| } | |
| } |
Lines 16 to 41 in eb4560c
| package com.diffplug.selfie.guts | |
| import io.kotest.matchers.shouldBe | |
| import kotlin.test.Test | |
| class LiteralBooleanTest { | |
| @Test | |
| fun encode() { | |
| encode(true, "true") | |
| encode(false, "false") | |
| } | |
| private fun encode(value: Boolean, expected: String) { | |
| val actual = LiteralBoolean.encode(value, Language.JAVA, EscapeLeadingWhitespace.ALWAYS) | |
| actual shouldBe expected | |
| } | |
| @Test | |
| fun decode() { | |
| decode("true", true) | |
| decode("false", false) | |
| } | |
| private fun decode(value: String, expected: Boolean) { | |
| val actual = LiteralBoolean.parse(value, Language.JAVA) | |
| actual shouldBe expected | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
No labels