summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-06-29 22:00:44 +0200
committerljfa-ag <ljfa-ag@web.de>2015-06-29 22:00:44 +0200
commit69fcbd0fd080aa3e7522040c1abc6394e7a1e390 (patch)
tree50d3aad84f99d28bff1435e336968895976c2e51 /test
parent61b44772d7390cbffed3e2fa4af0138727d58bcf (diff)
downloadProject-Tick-69fcbd0fd080aa3e7522040c1abc6394e7a1e390.tar.gz
Project-Tick-69fcbd0fd080aa3e7522040c1abc6394e7a1e390.zip
Add more tests for tag_compound
Diffstat (limited to 'test')
-rw-r--r--test/nbttest.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/test/nbttest.cpp b/test/nbttest.cpp
index 60f090dd43..7b47d42f8f 100644
--- a/test/nbttest.cpp
+++ b/test/nbttest.cpp
@@ -20,6 +20,7 @@
#include "microtest.h"
#include "libnbt.h"
#include <iostream>
+#include <stdexcept>
using namespace nbt;
@@ -76,8 +77,6 @@ void test_tag_string()
void test_tag_compound()
{
- //Preliminary
- //Doesn't work yet, but this is the syntax I would like to have:
tag_compound comp/*{
{"foo", int16_t(12)},
{"bar", "baz"},
@@ -85,20 +84,25 @@ void test_tag_compound()
}*/;
ASSERT(comp["foo"].get_type() == tag_type::Short);
- ASSERT(int(comp["foo"]) == 12);
+ ASSERT(int32_t(comp["foo"]) == 12);
ASSERT(int16_t(comp.at("foo")) == int16_t(12));
+ EXPECT_EXCEPTION(int8_t(comp["foo"]), std::bad_cast);
+ EXPECT_EXCEPTION(std::string(comp["foo"]), std::bad_cast);
ASSERT(comp["bar"].get_type() == tag_type::String);
ASSERT(std::string(comp["bar"]) == "baz");
+ EXPECT_EXCEPTION(int(comp["bar"]), std::bad_cast);
ASSERT(comp["baz"].get_type() == tag_type::Double);
ASSERT(double(comp["baz"]) == -2.0);
- ASSERT(float(comp["baz"]) == -2.0f);
+ EXPECT_EXCEPTION(float(comp["baz"]), std::bad_cast);
comp["quux"] = tag_compound{/*{"Hello", "World"}, {"zero", 0}*/};
ASSERT(comp.at("quux").get_type() == tag_type::Compound);
ASSERT(std::string(comp["quux"].at("Hello")) == "World");
+ EXPECT_EXCEPTION(comp.at("nothing"), std::out_of_range);
+
tag_compound comp2/*{
{"foo", int16_t(12)},
{"bar", "baz"},
@@ -108,6 +112,16 @@ void test_tag_compound()
ASSERT(comp == comp2);
ASSERT(comp != (const tag_compound&)comp2["quux"]);
ASSERT(comp != comp2["quux"]);
+
+ ASSERT(comp.size() == 4);
+
+ ASSERT(comp.erase("nothing") == false);
+ ASSERT(comp.has_key("quux"));
+ ASSERT(comp.erase("quux") == true);
+ ASSERT(!comp.has_key("quux"));
+
+ comp.clear();
+ ASSERT(comp == tag_compound{});
}
int main()