Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 20, 2012
Fuji, Goro Add a test launcher (`make test`) 367e4a3
Fuji, Goro Add tests for constructors bd8d9d8
Showing with 22 additions and 7 deletions.
  1. +4 −0 Makefile
  2. +18 −7 picojson.h
View
4 Makefile
@@ -0,0 +1,4 @@
+test: picojson.h
+ $(CXX) -x c++ $(OPTIMIZE) -Wall -Wextra -DTEST_PICOJSON picojson.h -o test
+ prove -v ./test
+ rm test
View
25 picojson.h
@@ -788,7 +788,7 @@ static void ok(bool b, const char* name = "")
static int n = 1;
if (! b)
success = false;
- printf("%s %d - %s\n", b ? "ok" : "ng", n++, name);
+ printf("%s %d - %s\n", b ? "ok" : "not ok", n++, name);
}
template <typename T> void is(const T& x, const T& y, const char* name = "")
@@ -797,6 +797,7 @@ template <typename T> void is(const T& x, const T& y, const char* name = "")
ok(true, name);
} else {
ok(false, name);
+ std::cout << "# got [" << x << "]" << std::endl;
}
}
@@ -804,8 +805,22 @@ template <typename T> void is(const T& x, const T& y, const char* name = "")
int main(void)
{
- plan(65);
-
+ plan(69);
+
+ // constructors
+#define TEST(expr, expected) \
+ is(picojson::value expr .serialize(), string(expected), "picojson::value" #expr)
+
+ TEST( (true), "true");
+ TEST( (false), "false");
+ TEST( (42.0), "42");
+ TEST( (string("hello")), "\"hello\"");
+ TEST( ("hello"), "\"hello\"");
+ TEST( ("hello", 4), "\"hell\"");
+
+#undef TEST
+
+
#define TEST(in, type, cmp, serialize_test) { \
picojson::value v; \
const char* s = in; \
@@ -932,7 +947,6 @@ int main(void)
ok(picojson::value(3.0).serialize() == "3",
"integral number should be serialized as a integer");
- picojson::value("abcd");
{
const char* s = "{ \"a\": [1,2], \"d\": 2 }";
@@ -942,9 +956,6 @@ int main(void)
ok(err.empty(), "null_parse_context");
}
- is(picojson::value("abc").serialize(), std::string("\"abc\""), "value(const char*)");
- is(picojson::value("abc", 1).serialize(), std::string("\"a\""), "value(const char*, size_t)");
-
return success ? 0 : 1;
}

No commit comments for this range

Something went wrong with that request. Please try again.