json/schema: add multipleOf test cases
This commit is contained in:
parent
0629ba07cd
commit
a2e2d59c98
@ -35,6 +35,7 @@ base::instantiate (std::string const &name, ::json::tree::node const &def)
|
|||||||
if (name == "minimum") return std::make_unique<minimum> (def);
|
if (name == "minimum") return std::make_unique<minimum> (def);
|
||||||
if (name == "exclusiveMaximum") return std::make_unique<exclusive_maximum> (def);
|
if (name == "exclusiveMaximum") return std::make_unique<exclusive_maximum> (def);
|
||||||
if (name == "exclusiveMinimum") return std::make_unique<exclusive_minimum> (def);
|
if (name == "exclusiveMinimum") return std::make_unique<exclusive_minimum> (def);
|
||||||
|
if (name == "multipleOf") return std::make_unique<multiple_of > (def);
|
||||||
if (name == "maximum") return std::make_unique<maximum> (def);
|
if (name == "maximum") return std::make_unique<maximum> (def);
|
||||||
if (name == "properties") return std::make_unique<properties> (def);
|
if (name == "properties") return std::make_unique<properties> (def);
|
||||||
if (name == "patternProperties") return std::make_unique<pattern_properties> (def);
|
if (name == "patternProperties") return std::make_unique<pattern_properties> (def);
|
||||||
|
@ -75,3 +75,16 @@ template class util::json::schema::constraint::inequality<std::less_equal>;
|
|||||||
template class util::json::schema::constraint::inequality<std::greater_equal>;
|
template class util::json::schema::constraint::inequality<std::greater_equal>;
|
||||||
template class util::json::schema::constraint::inequality<std::less>;
|
template class util::json::schema::constraint::inequality<std::less>;
|
||||||
template class util::json::schema::constraint::inequality<std::greater>;
|
template class util::json::schema::constraint::inequality<std::greater>;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <>
|
||||||
|
bool
|
||||||
|
util::json::schema::constraint::is_multiple<double>::operator() (double a, double b) const noexcept
|
||||||
|
{
|
||||||
|
return std::fmod (a, b) <= 1e-8;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
template class util::json::schema::constraint::inequality<util::json::schema::constraint::is_multiple>;
|
||||||
|
@ -48,4 +48,14 @@ namespace util::json::schema::constraint {
|
|||||||
using maximum = inequality<std::less_equal>;
|
using maximum = inequality<std::less_equal>;
|
||||||
using exclusive_minimum = inequality<std::greater>;
|
using exclusive_minimum = inequality<std::greater>;
|
||||||
using exclusive_maximum = inequality<std::less>;
|
using exclusive_maximum = inequality<std::less>;
|
||||||
|
|
||||||
|
|
||||||
|
// this is not technically an inequality, but the implementation fits in
|
||||||
|
// nicely here.
|
||||||
|
template <typename T>
|
||||||
|
struct is_multiple {
|
||||||
|
bool operator() (T, T) const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
using multiple_of = inequality<is_multiple>;
|
||||||
}
|
}
|
||||||
|
4
test/json/schema/parsing/bad/0000_multipleOf_zero.json
Normal file
4
test/json/schema/parsing/bad/0000_multipleOf_zero.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"description": "multipleOf must be strictly greater than zero",
|
||||||
|
"multipleOf": 0
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"description": "multipleOf must be strictly greater than zero",
|
||||||
|
"multipleOf": -1
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
1
|
@ -0,0 +1 @@
|
|||||||
|
0
|
@ -0,0 +1 @@
|
|||||||
|
1.5
|
@ -0,0 +1 @@
|
|||||||
|
15
|
1
test/json/schema/validation/2004_multiple_of/schema.json
Normal file
1
test/json/schema/validation/2004_multiple_of/schema.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ "type": "number", "multipleOf": 1.5 }
|
Loading…
Reference in New Issue
Block a user