From b07f40c02ec9ee55c69725585011290da66d57ed Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 6 Feb 2011 08:41:14 +0100 Subject: [PATCH] test the bson functionality, and provide examples for using it --- scripts/tests/common.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index f0d987ada..467dfeb5a 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -885,3 +885,26 @@ function test_bug_1679() assert_true(find_in_report(f, "Die Einheit kann keine weiteren langen Befehle", "cr")) assert_true(find_in_report(f, "entdeckt, dass es keinen Weg nach Westen gibt")) end + +function test_bson() + local r = region.create(0, 0, "mountain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + attrib.create(r, 1) + assert_equal(attrib.get(r)().data, 1) + attrib.create(u, 3) + assert_equal(attrib.get(u)().data, 3) + attrib.create(f, 5) + assert_equal(attrib.get(f)().data, 5) +end + +function test_bson_with_multiple_attribs() + local r = region.create(0, 0, "mountain") + attrib.create(r, { a=1}) + attrib.create(r, { a=5}) + local total = 0 + for a in attrib.get(r) do + total = total + a.data.a; + end + assert_equal(6, total) +end