Skip to content

Commit

Permalink
Test conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Dec 11, 2024
1 parent e4ab65f commit 492da1c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/lang/builtins_xml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 25 additions & 1 deletion tests/language/xml_test.liq
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ def f() =
<foo opt="12.3">gni</foo>
<bar />
<bar option="aab">bla</bar>
<blo>1.23</blo>
<blu>false</blu>
<ble>123</ble>
</bla>'

let xml.parse (x :
{
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 }
}
}
Expand All @@ -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}}
}
Expand Down Expand Up @@ -57,7 +66,7 @@ def f() =
*
{
xml_params: [(string * string)],
xml_children: [(string * {xml_text: string?})]
xml_children: [(string * {xml_text: string})]
}
)
]
Expand Down Expand Up @@ -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")]
Expand All @@ -99,6 +120,9 @@ def f() =
<foo opt="12.3">gni</foo>
<bar/>
<bar option="aab">bla</bar>
<blo>1.23</blo>
<blu>false</blu>
<ble>123</ble>
</bla>'
)

Expand Down

0 comments on commit 492da1c

Please sign in to comment.