Allow instants to pass through schema validation. (#481) r=fluffyemily

* Allow instants to pass through schema validation.
* Expand cases in SchemaTypeChecking to catch enum bugs.
This commit is contained in:
Richard Newman 2017-06-16 09:15:29 -07:00 committed by GitHub
parent aa5f569df5
commit ea0e9d4c7b

View file

@ -243,12 +243,25 @@ impl SchemaTypeChecking for Schema {
(ValueType::Double, tv @ TypedValue::Double(_)) => Ok(tv),
(ValueType::String, tv @ TypedValue::String(_)) => Ok(tv),
(ValueType::Uuid, tv @ TypedValue::Uuid(_)) => Ok(tv),
(ValueType::Instant, tv @ TypedValue::Instant(_)) => Ok(tv),
(ValueType::Keyword, tv @ TypedValue::Keyword(_)) => Ok(tv),
// Ref coerces a little: we interpret some things depending on the schema as a Ref.
(ValueType::Ref, TypedValue::Long(x)) => Ok(TypedValue::Ref(x)),
(ValueType::Ref, TypedValue::Keyword(ref x)) => self.require_entid(&x).map(|entid| TypedValue::Ref(entid)),
// Otherwise, we have a type mismatch.
(value_type, _) => bail!(ErrorKind::BadEDNValuePair(value.clone(), value_type)),
// Enumerate all of the types here to allow the compiler to help us.
// We don't enumerate all `TypedValue` cases, though: that would multiply this
// collection by 8!
(vt @ ValueType::Boolean, _) |
(vt @ ValueType::Long, _) |
(vt @ ValueType::Double, _) |
(vt @ ValueType::String, _) |
(vt @ ValueType::Uuid, _) |
(vt @ ValueType::Instant, _) |
(vt @ ValueType::Keyword, _) |
(vt @ ValueType::Ref, _)
=> bail!(ErrorKind::BadEDNValuePair(value.clone(), vt)),
}
}
}