Software /
code /
prosody
Diff
spec/util_stanza_spec.lua @ 10717:05e4645fc9b3
util.stanza: Add method returning stanza with added indentation
Adds indentation and line breaks to stanzas, to make stanzas easier to
read for humans.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 12 Apr 2020 17:03:05 +0200 |
parent | 10503:e25a1a9a6e7e |
child | 11083:4d12a6785531 |
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua Sat Apr 11 19:31:15 2020 +0200 +++ b/spec/util_stanza_spec.lua Sun Apr 12 17:03:05 2020 +0200 @@ -459,4 +459,12 @@ assert.equal("true", s2.attr["my-awesome-ns\1bar"]); end); end); + + describe("indent", function () + local s = st.stanza("foo"):text("\n"):tag("bar"):tag("baz"):up():text_tag("cow", "moo"); + assert.equal("<foo>\n\t<bar>\n\t\t<baz/>\n\t\t<cow>moo</cow>\n\t</bar>\n</foo>", tostring(s:indent())); + assert.equal("<foo>\n <bar>\n <baz/>\n <cow>moo</cow>\n </bar>\n</foo>", tostring(s:indent(1, " "))); + assert.equal("<foo>\n\t\t<bar>\n\t\t\t<baz/>\n\t\t\t<cow>moo</cow>\n\t\t</bar>\n\t</foo>", tostring(s:indent(2, "\t"))); + end); + end);