From 90164aa3df623736e4d71bc3ec181263d1006661 Mon Sep 17 00:00:00 2001 From: Duncan McGreggor Date: Sun, 13 Aug 2023 19:40:29 -0500 Subject: [PATCH] Added new tests and fixes for fast_xml support. --- test/data.xml => priv/xml/sample01.xml | 0 priv/xml/sample02.xml | 23 +++++++++++++++++++++++ rebar.config | 2 +- src/lxml-fast.lfe | 4 ++-- src/lxml.lfe | 2 ++ test/unit-lxml-fast-tests.lfe | 22 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 3 deletions(-) rename test/data.xml => priv/xml/sample01.xml (100%) create mode 100644 priv/xml/sample02.xml diff --git a/test/data.xml b/priv/xml/sample01.xml similarity index 100% rename from test/data.xml rename to priv/xml/sample01.xml diff --git a/priv/xml/sample02.xml b/priv/xml/sample02.xml new file mode 100644 index 0000000..9cbcbca --- /dev/null +++ b/priv/xml/sample02.xml @@ -0,0 +1,23 @@ + + + + Charter Group +
+ 100 Main + Framingham + MA + 01701 +
+
+ 720 Prospect + Framingham + MA + 01701 +
+
+ 120 Ridge + MA + 01760 +
+
+
diff --git a/rebar.config b/rebar.config index b06b7e7..5370401 100644 --- a/rebar.config +++ b/rebar.config @@ -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"} ]}. diff --git a/src/lxml-fast.lfe b/src/lxml-fast.lfe index 612547a..77f6bb4 100644 --- a/src/lxml-fast.lfe +++ b/src/lxml-fast.lfe @@ -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)) diff --git a/src/lxml.lfe b/src/lxml.lfe index e0cc11c..4fdb6a2 100644 --- a/src/lxml.lfe +++ b/src/lxml.lfe @@ -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) diff --git a/test/unit-lxml-fast-tests.lfe b/test/unit-lxml-fast-tests.lfe index e69de29..d5a7b2e 100644 --- a/test/unit-lxml-fast-tests.lfe +++ b/test/unit-lxml-fast-tests.lfe @@ -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)))) \ No newline at end of file