Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect committed Jul 30, 2024
1 parent 666b499 commit b150239
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-yaml_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-yaml_2.12)

This is a small library for parsing [YAML](https://yaml.org) into [circe](https://github.com/circe/circe)'s `Json` AST.
* For parsing YAML 1.1 it uses [SnakeYAML](https://bitbucket.org/snakeyaml/snakeyaml).
* For parsing YAML 1.2 it uses [snakeyaml-engine](https://bitbucket.org/snakeyaml/snakeyaml-engine).
* For parsing YAML on Scala.js or Scala Native (as well as Scala/JVM) it uses [scala-yaml](https://github.com/VirtusLab/scala-yaml).
You can choose from multiple YAML backends:
* `circe-yaml`: For parsing YAML 1.1 it uses [SnakeYAML](https://bitbucket.org/snakeyaml/snakeyaml).
* `circe-yaml-v12`: For parsing YAML 1.2 it uses [snakeyaml-engine](https://bitbucket.org/snakeyaml/snakeyaml-engine).
* `circe-yaml-scalayaml`: For parsing YAML on Scala.js or Scala Native (as well as Scala/JVM) it uses [scala-yaml](https://github.com/VirtusLab/scala-yaml).

## Why?

Expand All @@ -25,11 +26,15 @@ The artifact is hosted by Sonatype, and release versions are synced to Maven Cen

For YAML 1.1
```scala
libraryDependencies += "io.circe" %% "circe-yaml" % "0.14.2"
libraryDependencies += "io.circe" %% "circe-yaml" % "0.15.4"
```
or for YAML 1.2
```scala
libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.14.2"
libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.15.4"
```
or for YAML on Scala.js or Scala Native (as well as Scala/JVM)
```scala
libraryDependencies += "io.circe" %% "circe-yaml-scalayaml" % "0.15.4"
```

Snapshot versions are available by adding the Sonatype Snapshots resolver:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import io.circe.Json
import org.virtuslab.yaml.Node
import org.virtuslab.yaml.NodeOps

import scala.collection.immutable.ListMap

object Printer extends io.circe.yaml.common.Printer {

override def pretty(json: Json): String = {
Expand All @@ -31,7 +33,8 @@ object Printer extends io.circe.yaml.common.Printer {
case Json.JArray(value) =>
Node.SequenceNode(value.map(jsonToNode): _*)
case Json.JObject(value) =>
Node.MappingNode(value.toMap.map { case (key, value) => (Node.ScalarNode(key): Node) -> jsonToNode(value) })
val mappings = value.toList.map { case (key, value) => (Node.ScalarNode(key): Node) -> jsonToNode(value) }
Node.MappingNode(ListMap.from(mappings))
case json =>
Node.ScalarNode(json.toString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PrinterTests extends AnyFreeSpec with Matchers {

"Drop null keys" in {
val json = Json.obj("nullField" -> Json.Null, "nonNullField" -> Json.fromString("foo"))
Printer.pretty(json) shouldEqual "nullField: null\nnonNullField: \"foo\"\n"
Printer.pretty(json) shouldEqual "nullField: !!null\nnonNullField: \"foo\"\n"
}

"Root integer" in {
Expand Down

0 comments on commit b150239

Please sign in to comment.