Debian Codegraph @

src/keywords/boolean.rs

raw symbols SCIP
1 use crate::paths::{LazyLocation, Location};
2
3 use crate::{
4 error::ValidationError,
5 keywords::CompilationResult,
6 validator::{Validate, ValidationContext},
7 };
8 use serde_json::Value;
9
10 pub(crate) struct FalseValidator {
11 location: Location,
12 }
13 impl FalseValidator {
14 #[inline]
15 pub(crate) fn compile<'a>(location: Location) -> CompilationResult<'a> {
16 Ok(Box::new(FalseValidator { location }))
17 }
18 }
19 impl Validate for FalseValidator {
20 fn is_valid(&self, _: &Value, _ctx: &mut ValidationContext) -> bool {
21 false
22 }
23
24 fn validate<'i>(
25 &self,
26 instance: &'i Value,
27 location: &LazyLocation,
28 _ctx: &mut ValidationContext,
29 ) -> Result<(), ValidationError<'i>> {
30 Err(ValidationError::false_schema(
31 self.location.clone(),
32 location.into(),
33 instance,
34 ))
35 }
36 }
37
38 #[cfg(test)]
39 mod tests {
40 use crate::tests_util;
41 use serde_json::json;
42
43 #[test]
44 fn location() {
45 tests_util::assert_schema_location(&json!(false), &json!(1), "");
46 }
47 }