Skip to content

Commit dd83bcf

Browse files
committed
primitives - targeting - eval - clean up
1 parent b607cdb commit dd83bcf

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

primitives/src/targeting/eval.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ impl fmt::Display for Error {
1717
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1818
match self {
1919
Error::TypeError => write!(f, "TypeError: Wrong type"),
20-
Error::UnknownVariable => write!(f, "UnknownVariable: Unknown varialbe passed"),
20+
Error::UnknownVariable => write!(f, "UnknownVariable: Unknown variable passed"),
2121
}
2222
}
2323
}
2424

25+
impl std::error::Error for Error {}
26+
2527
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
2628
#[serde(untagged)]
2729
pub enum Rule {
@@ -322,17 +324,11 @@ mod test {
322324
use crate::targeting::AdSlot;
323325

324326
#[test]
325-
fn deserialzes_intersects_rule() {
327+
fn deserialize_intersects_with_get_rule() {
326328
let json = r#"{"intersects": [{ "get": "adSlot.categories" }, ["News", "Bitcoin"]]}"#;
327329

328330
let parsed_rule = serde_json::from_str::<Rule>(json).expect("Should deserialize");
329331

330-
let mut expected_map = Map::new();
331-
expected_map.insert(
332-
"get".to_string(),
333-
SerdeValue::String("adSlot.categories".to_string()),
334-
);
335-
336332
let expected = Rule::Function(Function::new_intersects(
337333
Rule::Function(Function::new_get("adSlot.categories")),
338334
Rule::Value(Value::Array(vec![
@@ -383,7 +379,7 @@ mod test {
383379

384380
assert_eq!(
385381
Value::Bool(true),
386-
result.expect("Sould return Non-NULL result!")
382+
result.expect("Should return Non-NULL result!")
387383
);
388384

389385
let mut input = Input::default();
@@ -397,7 +393,7 @@ mod test {
397393

398394
assert_eq!(
399395
Value::Bool(false),
400-
result.expect("Sould return Non-NULL result!")
396+
result.expect("Should return Non-NULL result!")
401397
);
402398
}
403399

@@ -456,12 +452,12 @@ mod test {
456452

457453
let cases = vec![
458454
(Value::new_string("1000"), Value::BigNum(1000.into())),
459-
(Value::new_number(5000), Value::BigNum(5000.into())),
460-
(Value::BigNum(2.into()), Value::BigNum(2.into())),
455+
(Value::new_number(2_000), Value::BigNum(2_000.into())),
456+
(Value::BigNum(3.into()), Value::BigNum(3.into())),
461457
// rounded floats should work!
462458
(
463-
Value::Number(Number::from_f64(2.0).expect("should create float number")),
464-
Value::BigNum(2.into()),
459+
Value::Number(Number::from_f64(40.0).expect("should create float number")),
460+
Value::BigNum(40.into()),
465461
),
466462
];
467463

@@ -483,7 +479,7 @@ mod test {
483479

484480
let error_cases = vec![
485481
Value::new_string("text"),
486-
// BigNums can only be possitive
482+
// BigNums can only be positive
487483
Value::new_number(-100),
488484
Value::Bool(true),
489485
Value::Array(vec![Value::Bool(false)]),

0 commit comments

Comments
 (0)