fixes #141. Version 2.1.1

This commit is contained in:
Felix Krause 2024-01-18 08:08:41 +01:00
parent eee45683ea
commit 48a90e36e8
5 changed files with 17 additions and 11 deletions

View File

@ -1,3 +1,9 @@
## 2.1.1
Bugfixes:
* Fixed a bug that prevented float values to be serialized (#141)
## 2.1.0
Features:

View File

@ -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};

View File

@ -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

View File

@ -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"

View File

@ -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