Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
trobro committed Sep 6, 2017
1 parent 5513d96 commit f22717d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/test_value.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <hjson.h>
#include <assert.h>
#include <cmath>
#include <cstring>


static std::string _test_string_param(std::string param) {
return param;
}


void test_value() {
Expand Down Expand Up @@ -106,11 +112,13 @@ void test_value() {
assert(val == val2);
assert(val != "beta");
assert("beta" != val);
assert(_test_string_param(val) == "alpha");
val = std::string("alpha");
std::string st = val;
assert(val == val2);
assert(val2 == std::string("alpha"));
assert(val2 != std::string("beta"));
assert(std::string("alpha") == val2.operator const std::string());
assert(std::string("beta") != val2.operator const std::string());
assert(val.to_double() == 0);
assert(val.to_string() == "alpha");
Expand Down Expand Up @@ -173,6 +181,8 @@ void test_value() {
std::string leaft1 = val["first"];
assert(leaft1 == "leaf1");
assert(val[std::string("first")] == "leaf1");
assert(val["first"] == "leaf1");
assert(!strcmp("leaf1", val["first"]));

auto it = val.begin();
assert(it->first == "first");
Expand Down Expand Up @@ -241,6 +251,11 @@ void test_value() {
val[0] = 0;
assert(!"Did not throw error when trying to assign Value to VECTOR index that is out of bounds.");
} catch(Hjson::index_out_of_bounds e) {}
try {
const Hjson::Value val2;
const auto val3 = val2[0];
assert(!"Did not throw error when trying to access VECTOR index that is out of bounds.");
} catch(Hjson::index_out_of_bounds e) {}
try {
if (val[0].empty()) {
assert(!"Did not throw error when trying to access VECTOR index that is out of bounds.");
Expand Down Expand Up @@ -274,6 +289,16 @@ void test_value() {
} catch(Hjson::index_out_of_bounds e) {}
}

{
Hjson::Value val;
{
Hjson::Value val2;
val2.push_back("first");
val = val2[0];
}
assert(val == "first");
}

{
Hjson::Value val;
Hjson::Value val2 = val["åäö"];
Expand Down

0 comments on commit f22717d

Please sign in to comment.