Comparison

spec/util_rsm_spec.lua @ 11427:83f5499d1f10

util.rsm: Increase test coverage Test all fields in both directions in order to catch #1642
author Kim Alvefur <zash@zash.se>
date Sat, 06 Mar 2021 18:22:52 +0100
parent 10762:4fc224c97986
comparison
equal deleted inserted replaced
11426:c7948491c5e4 11427:83f5499d1f10
35 </set> 35 </set>
36 ]])); 36 ]]));
37 assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test)); 37 assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test));
38 end); 38 end);
39 39
40 it("all fields works", function()
41 local test = assert(xml.parse(strip([[
42 <set xmlns='http://jabber.org/protocol/rsm'>
43 <after>a</after>
44 <before>b</before>
45 <count>10</count>
46 <first index='1'>f</first>
47 <index>5</index>
48 <last>z</last>
49 <max>100</max>
50 </set>
51 ]])));
52 assert.same({
53 after = "a";
54 before = "b";
55 count = 10;
56 first = {index = 1; "f"};
57 index = 5;
58 last = "z";
59 max = 100;
60 }, rsm.parse(test));
61 end);
40 end); 62 end);
41 63
42 describe("generate", function () 64 describe("generate", function ()
43 it("works", function () 65 it("works", function ()
44 local test = xml.parse(strip([[ 66 local test = xml.parse(strip([[
82 assert.equal("10", r1:get_child_text("max")); 104 assert.equal("10", r1:get_child_text("max"));
83 assert.equal("100", r1:get_child_text("count")); 105 assert.equal("100", r1:get_child_text("count"));
84 assert.equal("1", r1:get_child("first").attr.index); 106 assert.equal("1", r1:get_child("first").attr.index);
85 end); 107 end);
86 108
109
110 it("all fields works", function ()
111 local res = rsm.generate({
112 after = "a";
113 before = "b";
114 count = 10;
115 first = {index = 1; "f"};
116 index = 5;
117 last = "z";
118 max = 100;
119 });
120 assert.equal("a", res:get_child_text("after"));
121 assert.equal("b", res:get_child_text("before"));
122 assert.equal("10", res:get_child_text("count"));
123 assert.equal("f", res:get_child_text("first"));
124 assert.equal("1", res:get_child("first").attr.index);
125 assert.equal("5", res:get_child_text("index"));
126 assert.equal("z", res:get_child_text("last"));
127 assert.equal("100", res:get_child_text("max"));
128 end);
87 end); 129 end);
130
88 end); 131 end);
89 132