summaryrefslogtreecommitdiff
path: root/test/nbttest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/nbttest.cpp')
-rw-r--r--test/nbttest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/nbttest.cpp b/test/nbttest.cpp
index b041d44aa8..4c46668f0b 100644
--- a/test/nbttest.cpp
+++ b/test/nbttest.cpp
@@ -19,6 +19,7 @@
*/
#include "microtest.h"
#include "nbt_tags.h"
+#include "tag_visitor.h"
#include <algorithm>
#include <stdexcept>
@@ -425,6 +426,50 @@ void test_tag_int_array()
std::clog << "test_tag_int_array passed" << std::endl;
}
+void test_visitor()
+{
+ struct : public tag_visitor
+ {
+ tag_type visited = tag_type::Null;
+
+ void visit(tag_byte& tag) override { visited = tag_type::Byte; }
+ void visit(tag_short& tag) override { visited = tag_type::Short; }
+ void visit(tag_int& tag) override { visited = tag_type::Int; }
+ void visit(tag_long& tag) override { visited = tag_type::Long; }
+ void visit(tag_float& tag) override { visited = tag_type::Float; }
+ void visit(tag_double& tag) override { visited = tag_type::Double; }
+ void visit(tag_byte_array& tag) override { visited = tag_type::Byte_Array; }
+ void visit(tag_string& tag) override { visited = tag_type::String; }
+ void visit(tag_list& tag) override { visited = tag_type::List; }
+ void visit(tag_compound& tag) override { visited = tag_type::Compound; }
+ void visit(tag_int_array& tag) override { visited = tag_type::Int_Array; }
+ } v;
+
+ tag_byte().accept(v);
+ ASSERT(v.visited == tag_type::Byte);
+ tag_short().accept(v);
+ ASSERT(v.visited == tag_type::Short);
+ tag_int().accept(v);
+ ASSERT(v.visited == tag_type::Int);
+ tag_long().accept(v);
+ ASSERT(v.visited == tag_type::Long);
+ tag_float().accept(v);
+ ASSERT(v.visited == tag_type::Float);
+ tag_double().accept(v);
+ ASSERT(v.visited == tag_type::Double);
+ tag_byte_array().accept(v);
+ ASSERT(v.visited == tag_type::Byte_Array);
+ tag_string().accept(v);
+ ASSERT(v.visited == tag_type::String);
+ tag_list().accept(v);
+ ASSERT(v.visited == tag_type::List);
+ tag_compound().accept(v);
+ ASSERT(v.visited == tag_type::Compound);
+ tag_int_array().accept(v);
+ ASSERT(v.visited == tag_type::Int_Array);
+ std::clog << "test_visitor passed" << std::endl;
+}
+
int main()
{
test_tag();
@@ -436,4 +481,5 @@ int main()
test_tag_list();
test_tag_byte_array();
test_tag_int_array();
+ test_visitor();
}