comparison spec/util_stanza_spec.lua @ 11786:39164ea2ab9e

util.stanza: Add :get_child_with_attr() + tests
author Matthew Wild <mwild1@gmail.com>
date Sun, 12 Sep 2021 10:31:02 +0100
parents f051394762ff
children 7d6497294d92
comparison
equal deleted inserted replaced
11785:b1381e302cab 11786:39164ea2ab9e
453 s:maptags(function () end); 453 s:maptags(function () end);
454 end, "Invalid stanza"); 454 end, "Invalid stanza");
455 end); 455 end);
456 end); 456 end);
457 457
458 describe("get_child_with_attr", function ()
459 local s = st.message({ type = "chat" })
460 :text_tag("body", "Hello world", { ["xml:lang"] = "en" })
461 :text_tag("body", "Bonjour le monde", { ["xml:lang"] = "fr" })
462 :text_tag("body", "Hallo Welt", { ["xml:lang"] = "de" })
463
464 it("works", function ()
465 assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "en"):get_text(), "Hello world");
466 assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "de"):get_text(), "Hallo Welt");
467 assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "fr"):get_text(), "Bonjour le monde");
468 assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "FR"));
469 assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "es"));
470 end);
471
472 it("supports normalization", function ()
473 assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "EN", string.upper):get_text(), "Hello world");
474 assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "ES", string.upper));
475 end);
476 end);
477
458 describe("#clone", function () 478 describe("#clone", function ()
459 it("works", function () 479 it("works", function ()
460 local s = st.message({type="chat"}, "Hello"):reset(); 480 local s = st.message({type="chat"}, "Hello"):reset();
461 local c = st.clone(s); 481 local c = st.clone(s);
462 assert.same(s, c); 482 assert.same(s, c);