Skip to content

Commit

Permalink
Merge pull request #449 from russellbanks/flatten-yaml-null-test
Browse files Browse the repository at this point in the history
Flatten Yaml Null Test
  • Loading branch information
charleskorn authored Jul 30, 2023
2 parents 7461bb1 + 2023ba3 commit a9313dd
Showing 1 changed file with 42 additions and 68 deletions.
110 changes: 42 additions & 68 deletions src/commonTest/kotlin/com/charleskorn/kaml/YamlNullTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,49 @@

package com.charleskorn.kaml

import io.kotest.core.spec.style.DescribeSpec
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class YamlNullTest : DescribeSpec({
describe("a YAML null value") {
describe("testing equivalence") {
val nullValue = YamlNull(YamlPath.root)

context("comparing it to the same instance") {
it("indicates that they are equivalent") {
nullValue.equivalentContentTo(nullValue) shouldBe true
}
}

context("comparing it to another null value with the same path") {
it("indicates that they are equivalent") {
nullValue.equivalentContentTo(YamlNull(nullValue.path)) shouldBe true
}
}

context("comparing it to another null with a different path") {
val path = YamlPath.root.withListEntry(0, Location(2, 4))

it("indicates that they are equivalent") {
nullValue.equivalentContentTo(YamlNull(path)) shouldBe true
}
}

context("comparing it to a scalar value") {
it("indicates that they are not equivalent") {
nullValue.equivalentContentTo(YamlScalar("some content", nullValue.path)) shouldBe false
}
}

context("comparing it to a list") {
it("indicates that they are not equivalent") {
nullValue.equivalentContentTo(YamlList(emptyList(), nullValue.path)) shouldBe false
}
}

context("comparing it to a map") {
it("indicates that they are not equivalent") {
nullValue.equivalentContentTo(YamlMap(emptyMap(), nullValue.path)) shouldBe false
}
}
}

describe("converting the content to a human-readable string") {
it("always returns the value 'null'") {
YamlNull(YamlPath.root).contentToString() shouldBe "null"
}
}

describe("replacing its path") {
val original = YamlNull(YamlPath.root)
val newPath = YamlPath.forAliasDefinition("blah", Location(2, 3))

it("returns a null value with the provided path") {
original.withPath(newPath) shouldBe YamlNull(newPath)
}
}

describe("converting it to a string") {
val path = YamlPath.root.withListEntry(2, Location(3, 4))
val value = YamlNull(path)

it("returns a human-readable description of itself") {
value.toString() shouldBe "null @ $path"
}
}
class YamlNullTest : FunSpec({
val nullValue = YamlNull(YamlPath.root)
val path = YamlPath.root.withListEntry(0, Location(2, 4))
val original = YamlNull(YamlPath.root)
val newPath = YamlPath.forAliasDefinition("blah", Location(2, 3))
val value = YamlNull(path)

test("Null value should be equivalent to same instance") {
nullValue.equivalentContentTo(nullValue) shouldBe true
}

test("Null value should be equivalent to another null value with same path") {
nullValue.equivalentContentTo(YamlNull(nullValue.path)) shouldBe true
}

test("Null value should be equivalent to another null value with different path") {
nullValue.equivalentContentTo(YamlNull(path)) shouldBe true
}

test("Null value should not be equivalent to a scalar value") {
nullValue.equivalentContentTo(YamlScalar("some content", nullValue.path)) shouldBe false
}

test("Null value should not be equivalent to a list") {
nullValue.equivalentContentTo(YamlList(emptyList(), nullValue.path)) shouldBe false
}

test("Null value should not be equivalent to a map") {
nullValue.equivalentContentTo(YamlMap(emptyMap(), nullValue.path)) shouldBe false
}

test("Converting content to human-readable string should return 'null'") {
YamlNull(YamlPath.root).contentToString() shouldBe "null"
}

test("Replacing its path should return null value with the provided path") {
original.withPath(newPath) shouldBe YamlNull(newPath)
}

test("Converting to string should return a human-readable description") {
value.toString() shouldBe "null @ $path"
}
})

0 comments on commit a9313dd

Please sign in to comment.