# HG changeset patch # User Kim Alvefur # Date 1640956443 -3600 # Node ID 3ac801630b4b78e0db93e99407d9986d0e131d47 # Parent 1a4c6125393281f2434818492024a816de40219d util.stanza: Cover :find method in tests This method is a bit complex so good to have some test coverage diff -r 1a4c61253932 -r 3ac801630b4b spec/util_stanza_spec.lua --- a/spec/util_stanza_spec.lua Fri Dec 31 14:01:12 2021 +0100 +++ b/spec/util_stanza_spec.lua Fri Dec 31 14:14:03 2021 +0100 @@ -552,4 +552,16 @@ assert.equal("\n\t\t\n\t\t\t\n\t\t\tmoo\n\t\t\n\t", tostring(s:indent(2, "\t"))); end); + describe("find", function() + it("works", function() + local s = st.stanza("root", { attr = "value" }):tag("child", + { xmlns = "urn:example:not:same"; childattr = "thisvalue" }):text_tag("nested", "text"):reset(); + assert.equal("value", s:find("@attr"), "finds attr") + assert.equal(s:get_child("child", "urn:example:not:same"), s:find("{urn:example:not:same}child"), + "equivalent to get_child") + assert.equal("thisvalue", s:find("{urn:example:not:same}child@childattr"), "finds child attr") + assert.equal("text", s:find("{urn:example:not:same}child/nested#"), "finds nested text") + assert.is_nil(s:find("child"), "respects namespaces") + end); + end); end);