Skip to content

Commit

Permalink
Added new tests and fixes for fast_xml support.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Aug 14, 2023
1 parent c660480 commit 90164aa
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
File renamed without changes.
23 changes: 23 additions & 0 deletions priv/xml/sample02.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<customers>
<customer id="55000">
<name>Charter Group</name>
<address>
<street>100 Main</street>
<city>Framingham</city>
<state>MA</state>
<zip>01701</zip>
</address>
<address>
<street>720 Prospect</street>
<city>Framingham</city>
<state>MA</state>
<zip>01701</zip>
</address>
<address>
<street>120 Ridge</street>
<state>MA</state>
<zip>01760</zip>
</address>
</customer>
</customers>
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{deps, [
{lfe, "2.1.2"},
{lutil, "0.14.1"},
{lutil, "0.14.2"},
{erlsom, "1.5.1"},
{fast_xml, "1.1.49"}
]}.
Expand Down
4 changes: 2 additions & 2 deletions src/lxml-fast.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
,(maps:from_list attrs)
,(els->tuple children opts '())))
((`#(xmlcdata ,data) _)
(lutil-binary:trim-bitstr-ws data))
(lutil-bin:trim-trailing-ws data))
((xml _)
`#(error no-match ,xml)))

(defun name
((n `#m(atom-key? ,akey?)) (when (is_binary n))
((n `#m(atom-keys? ,akey?)) (when (is_binary n))
(if akey?
(list_to_atom (binary_to_list n))
n))
Expand Down
2 changes: 2 additions & 0 deletions src/lxml.lfe
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(defmodule lxml
(export
(find-content 2)
(get-content 2)
(get-data 1)
(get-in 2)
(get-linked 2) (get-linked 3)
(map 2) (map 3) (map 4)
Expand Down
22 changes: 22 additions & 0 deletions test/unit-lxml-fast-tests.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(defmodule unit-lxml-fast-tests
(behaviour ltest-unit)
(export all))

(include-lib "ltest/include/ltest-macros.lfe")

;;; Test data

(defun sample-xml-01 ()
(let ((file (filename:join (list (code:priv_dir 'lxml) "xml" "sample01.xml"))))
(lxml:parse `#m(file ,file fxml true atom-keys? true))))

;;; Tests

(deftest get-in-tag-attr-content-tuple
(let ((data (sample-xml-01)))
(is-equal #(archaum #m() ())
(lxml:get-in '(life archaea) data))
(is-equal #"spirochetes"
(lxml:get-in '(life bacteria 1) data))
(is-equal #"cyanobacteria"
(lxml:get-in '(life bacteria 3) data))))

0 comments on commit 90164aa

Please sign in to comment.