Commit af17f196 authored by ylavic's avatar ylavic

Unit test for Pointer::operator<().

parent 055f1fa6
......@@ -15,7 +15,9 @@
#include "unittest.h"
#include "rapidjson/pointer.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/ostreamwrapper.h"
#include <sstream>
#include <set>
using namespace rapidjson;
......@@ -1493,6 +1495,71 @@ TEST(Pointer, Ambiguity) {
}
}
TEST(Pointer, LessThan) {
static const char *pointers[] = {
"/a/b",
"/a/c",
"/a",
"/d/1",
"/d/2/z",
"/d/2/3",
"/d/2",
"/d/2/zz",
"/d/1",
"/d/2/z",
"/e/f~g",
"/e/f~0g",
"/e/f~1g",
"/e/f~~g",
"#/e/f%2fg",
"/e/f.g",
""
};
static struct {
const char *string;
bool valid;
} ordered_pointers[] = {
{ "", true },
{ "/a", true },
{ "/a/b", true },
{ "/a/c", true },
{ "/d/1", true },
{ "/d/1", true },
{ "/d/2", true },
{ "/d/2/3", true },
{ "/d/2/z", true },
{ "/d/2/z", true },
{ "/d/2/zz", true },
{ "/e/f.g", true },
{ "/e/f~1g", true },
{ "/e/f~1g", true }, // was "#/e/f%2fg"
{ "/e/f~0g", true },
{ "/e/f~g", false },
{ "/e/f~~g", false }
};
MemoryPoolAllocator<> allocator;
typedef GenericPointer<Value, MemoryPoolAllocator<> > PooledPointer;
std::multiset<PooledPointer> set;
size_t i;
for (i = 0; i < sizeof(pointers) / sizeof(*pointers); ++i) {
set.insert(PooledPointer(pointers[i], &allocator));
}
i = 0;
for (std::set<PooledPointer>::iterator it = set.begin(); it != set.end(); ++it) {
EXPECT_TRUE(i < sizeof(ordered_pointers) / sizeof(*ordered_pointers));
EXPECT_EQ(it->IsValid(), ordered_pointers[i].valid);
if (it->IsValid()) {
std::stringstream ss;
OStreamWrapper os(ss);
EXPECT_TRUE(it->Stringify(os));
EXPECT_EQ(ss.str(), ordered_pointers[i].string);
}
i++;
}
}
// https://github.com/Tencent/rapidjson/issues/483
namespace myjson {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment