-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Methods for parsing a full snapshot (#8)
- Loading branch information
Showing
3 changed files
with
252 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
selfie-lib/src/jvmTest/kotlin/com/diffplug/selfie/SnapshotFileTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2023 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.selfie | ||
|
||
import io.kotest.matchers.shouldBe | ||
import kotlin.test.Test | ||
|
||
class SnapshotFileTest { | ||
@Test | ||
fun readWithMetadata() { | ||
val file = | ||
SnapshotFile.parse( | ||
SnapshotValueReader.of( | ||
""" | ||
╔═ 📷 com.acme.AcmeTest ═╗ | ||
{"header":"data"} | ||
╔═ Apple ═╗ | ||
Granny Smith | ||
╔═ Apple[color] ═╗ | ||
green | ||
╔═ Apple[crisp] ═╗ | ||
yes | ||
╔═ Orange ═╗ | ||
Orange | ||
""" | ||
.trimIndent())) | ||
file.metadata shouldBe entry("com.acme.AcmeTest", """{"header":"data"}""") | ||
file.snapshots.keys shouldBe setOf("Apple", "Orange") | ||
} | ||
|
||
@Test | ||
fun readWithoutMetadata() { | ||
val file = | ||
SnapshotFile.parse( | ||
SnapshotValueReader.of( | ||
""" | ||
╔═ Apple ═╗ | ||
Apple | ||
╔═ Apple[color] ═╗ | ||
green | ||
╔═ Apple[crisp] ═╗ | ||
yes | ||
╔═ Orange ═╗ | ||
Orange | ||
""" | ||
.trimIndent())) | ||
file.metadata shouldBe null | ||
file.snapshots.keys shouldBe setOf("Apple", "Orange") | ||
} | ||
|
||
@Test | ||
fun write() { | ||
val underTest = SnapshotFile() | ||
underTest.metadata = entry("com.acme.AcmeTest", """{"header":"data"}""") | ||
underTest.snapshots = | ||
underTest.snapshots.plus( | ||
"Apple", Snapshot.of("Granny Smith").lens("color", "green").lens("crisp", "yes")) | ||
underTest.snapshots = underTest.snapshots.plus("Orange", Snapshot.of("Orange")) | ||
val buffer = StringBuffer() | ||
underTest.serialize { line -> buffer.append(line) } | ||
buffer.toString() shouldBe | ||
""" | ||
╔═ 📷 com.acme.AcmeTest ═╗ | ||
{"header":"data"} | ||
╔═ Apple ═╗ | ||
Granny Smith | ||
╔═ Apple[color] ═╗ | ||
green | ||
╔═ Apple[crisp] ═╗ | ||
yes | ||
╔═ Orange ═╗ | ||
Orange | ||
""" | ||
.trimIndent() | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
selfie-lib/src/jvmTest/kotlin/com/diffplug/selfie/SnapshotReaderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2023 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.selfie | ||
|
||
import io.kotest.matchers.shouldBe | ||
import kotlin.test.Test | ||
|
||
class SnapshotReaderTest { | ||
@Test | ||
fun lens() { | ||
val reader = | ||
SnapshotReader( | ||
SnapshotValueReader.of( | ||
""" | ||
╔═ Apple ═╗ | ||
Apple | ||
╔═ Apple[color] ═╗ | ||
green | ||
╔═ Apple[crisp] ═╗ | ||
yes | ||
╔═ Orange ═╗ | ||
Orange | ||
""" | ||
.trimIndent())) | ||
reader.peekKey() shouldBe "Apple" | ||
reader.peekKey() shouldBe "Apple" | ||
reader.nextSnapshot() shouldBe Snapshot.of("Apple").lens("color", "green").lens("crisp", "yes") | ||
reader.peekKey() shouldBe "Orange" | ||
reader.peekKey() shouldBe "Orange" | ||
reader.nextSnapshot() shouldBe Snapshot.of("Orange") | ||
reader.peekKey() shouldBe null | ||
} | ||
} |