From 48a90e36e82bd97457dae87e86efe423dcd3bb40 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Thu, 18 Jan 2024 08:08:41 +0100 Subject: [PATCH] fixes #141. Version 2.1.1 --- CHANGELOG.md | 6 ++++++ flake.nix | 2 +- test/tnative.nim | 10 +++++----- yaml.nimble | 2 +- yaml/native.nim | 8 ++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c3afa3..1d17dcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.1.1 + +Bugfixes: + + * Fixed a bug that prevented float values to be serialized (#141) + ## 2.1.0 Features: diff --git a/flake.nix b/flake.nix index e41b54e..b2c99e3 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,7 @@ }; outputs = { self, nixpkgs, utils, nix-filter }: let - version = "2.1.0"; + version = "2.1.1"; systemDependent = with utils.lib; eachSystem allSystems (system: let pkgs = nixpkgs.legacyPackages.${system}; diff --git a/test/tnative.nim b/test/tnative.nim index 839b77a..f7a6b71 100644 --- a/test/tnative.nim +++ b/test/tnative.nim @@ -35,7 +35,7 @@ type name: string case kind: AnimalKind of akCat: - purringIntensity: int + purringIntensity: float of akDog: barkometer: int DumbEnum = enum @@ -488,26 +488,26 @@ suite "Serialization": dualTest "Load custom variant object": let input = - "---\n- - name: Bastet\n - kind: akCat\n - purringIntensity: 7\n" & + "---\n- - name: Bastet\n - kind: akCat\n - purringIntensity: 7.2\n" & "- - name: Anubis\n - kind: akDog\n - barkometer: 13" var result: seq[Animal] load(input, result) assert result.len == 2 assert result[0].name == "Bastet" assert result[0].kind == akCat - assert result[0].purringIntensity == 7 + assert abs(result[0].purringIntensity - 7.2) < 1E-7 assert result[1].name == "Anubis" assert result[1].kind == akDog assert result[1].barkometer == 13 test "Dump custom variant object": - let input = @[Animal(name: "Bastet", kind: akCat, purringIntensity: 7), + let input = @[Animal(name: "Bastet", kind: akCat, purringIntensity: 7.2), Animal(name: "Anubis", kind: akDog, barkometer: 13)] var output = blockOnlyDumper().dump(input) assertStringEqual "" & "- - name: Bastet\n" & " - kind: akCat\n" & - " - purringIntensity: 7\n" & + " - purringIntensity: 7.2\n" & "- - name: Anubis\n" & " - kind: akDog\n" & " - barkometer: 13\n", output diff --git a/yaml.nimble b/yaml.nimble index 4830b9d..a0f6429 100644 --- a/yaml.nimble +++ b/yaml.nimble @@ -1,6 +1,6 @@ # Package -version = "2.1.0" +version = "2.1.1" author = "Felix Krause" description = "YAML 1.2 implementation for Nim" license = "MIT" diff --git a/yaml/native.nim b/yaml/native.nim index c7db846..3d935a5 100644 --- a/yaml/native.nim +++ b/yaml/native.nim @@ -451,10 +451,10 @@ proc representObject*[T: float|float32|float64]( ) {.raises: [].} = ## represents a float value as YAML scalar case value - of Inf: ctx.put(scalarEvent(".inf", tag, ctx.scalarStyleFor(T))) - of NegInf: ctx.put(scalarEvent("-.inf", tag, ctx.scalarStyleFor(T))) - of NaN: ctx.put(scalarEvent(".nan", tag, ctx.scalarStyleFor(T))) - else: ctx.put(scalarEvent($value, tag, ctx.scalarStyleFor(T))) + of Inf: ctx.put(scalarEvent(".inf", tag, yAnchorNone, ctx.scalarStyleFor(T))) + of NegInf: ctx.put(scalarEvent("-.inf", tag, yAnchorNone, ctx.scalarStyleFor(T))) + of NaN: ctx.put(scalarEvent(".nan", tag, yAnchorNone, ctx.scalarStyleFor(T))) + else: ctx.put(scalarEvent($value, tag, yAnchorNone, ctx.scalarStyleFor(T))) proc yamlTag*(T: typedesc[bool]): Tag {.inline, raises: [].} = yTagBoolean