From 492da1c3047a7b2b36293525cb7bf9144ab898d7 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Wed, 11 Dec 2024 11:02:34 +0100 Subject: [PATCH] Test conversions. --- src/lang/builtins_xml.ml | 8 ++++++-- tests/language/xml_test.liq | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/lang/builtins_xml.ml b/src/lang/builtins_xml.ml index f5442cb442..c36b883f74 100644 --- a/src/lang/builtins_xml.ml +++ b/src/lang/builtins_xml.ml @@ -135,8 +135,12 @@ let rec xml_of_value = function match Methods.bindings methods with | [(name, Value.Tuple { value = []; methods })] -> xml_of_node ~name (Methods.bindings methods) - | [(name, Value.String { value = s; methods })] -> - xml_of_node ~xml_text:s ~name (Methods.bindings methods) + | [(name, (Value.String { methods } as v))] + | [(name, (Value.Float { methods } as v))] + | [(name, (Value.Int { methods } as v))] + | [(name, (Value.Bool { methods } as v))] -> + xml_of_node ~xml_text:(string_of_ground v) ~name + (Methods.bindings methods) | _ -> assert false) | _ -> assert false diff --git a/tests/language/xml_test.liq b/tests/language/xml_test.liq index ce95948e3a..071bf3a658 100644 --- a/tests/language/xml_test.liq +++ b/tests/language/xml_test.liq @@ -4,6 +4,9 @@ def f() = gni bla +1.23 +false +123 ' let xml.parse (x : @@ -11,6 +14,9 @@ def f() = bla: { foo: string.{ xml_params: {opt: float} }, bar: (string? * string?.{ xml_params: [(string * string)] }), + blo: float, + blu: bool, + ble: int, xml_params: [(string * string)].{ bla: bool } } } @@ -22,6 +28,9 @@ def f() = bla= { xml_params=[("param", "1"), ("bla", "true")].{bla=true}, + ble=123, + blu=false, + blo=1.23, bar=(null(), "bla".{xml_params=[("option", "aab")]}), foo="gni".{xml_params={opt=12.3}} } @@ -57,7 +66,7 @@ def f() = * { xml_params: [(string * string)], - xml_children: [(string * {xml_text: string?})] + xml_children: [(string * {xml_text: string})] } ) ] @@ -86,6 +95,18 @@ def f() = xml_children=[("xml_text", {xml_text="bla"})], xml_params=[("option", "aab")] } + ), + ( + "blo", + {xml_children=[("xml_text", {xml_text="1.23"})], xml_params=[]} + ), + ( + "blu", + {xml_children=[("xml_text", {xml_text="false"})], xml_params=[]} + ), + ( + "ble", + {xml_children=[("xml_text", {xml_text="123"})], xml_params=[]} ) ], xml_params=[("param", "1"), ("bla", "true")] @@ -99,6 +120,9 @@ def f() = gni bla + 1.23 + false + 123 ' )