TEST(SchemaValidatingReader, Simple) { Document sd; sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }"); SchemaDocument s(sd); Document d; StringStream ss("\"red\""); SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s); d.Populate(reader); EXPECT_TRUE(reader.GetParseResult()); EXPECT_TRUE(reader.IsValid()); EXPECT_TRUE(d.IsString()); EXPECT_STREQ("red", d.GetString()); }
TEST(SchemaValidatingReader, Invalid) { Document sd; sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}"); SchemaDocument s(sd); Document d; StringStream ss("\"ABCD\""); SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s); d.Populate(reader); EXPECT_FALSE(reader.GetParseResult()); EXPECT_FALSE(reader.IsValid()); EXPECT_EQ(kParseErrorTermination, reader.GetParseResult().Code()); EXPECT_STREQ("maxLength", reader.GetInvalidSchemaKeyword()); EXPECT_TRUE(reader.GetInvalidSchemaPointer() == SchemaDocument::PointerType("")); EXPECT_TRUE(reader.GetInvalidDocumentPointer() == SchemaDocument::PointerType("")); EXPECT_TRUE(d.IsNull()); }