No need for mutable executor in tests

This commit is contained in:
Tobie Morgan Hitchcock 2022-01-29 16:15:30 +00:00
parent 76f249589a
commit 6a5faf852d
10 changed files with 108 additions and 108 deletions

View file

@ -28,21 +28,21 @@ mod tests {
#[tokio::test]
async fn array_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::default();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("[]");
val.array(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.array(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn array_path() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: [] }");
val.array(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.array(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -26,19 +26,19 @@ mod tests {
#[tokio::test]
async fn clear_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{}");
val.clear(&ctx, &opt, &mut exe).await.unwrap();
val.clear(&ctx, &opt, &exe).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn clear_path() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{}");
val.clear(&ctx, &opt, &mut exe).await.unwrap();
val.clear(&ctx, &opt, &exe).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -44,51 +44,51 @@ mod tests {
#[tokio::test]
async fn dec_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("other");
let mut val = Value::parse("{ test: 100 }");
let res = Value::parse("{ test: 100, other: -10 }");
val.decrement(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.decrement(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn dec_number() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: 100 }");
let res = Value::parse("{ test: 90 }");
val.decrement(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.decrement(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn dec_array_number() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test[1]");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 190, 300] }");
val.decrement(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.decrement(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn dec_array_value() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 300] }");
val.decrement(&ctx, &opt, &mut exe, &idi, Value::from(200)).await.unwrap();
val.decrement(&ctx, &opt, &exe, &idi, Value::from(200)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn dec_array_array() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [200] }");
val.decrement(&ctx, &opt, &mut exe, &idi, Value::parse("[100, 300]")).await.unwrap();
val.decrement(&ctx, &opt, &exe, &idi, Value::parse("[100, 300]")).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -127,101 +127,101 @@ mod tests {
#[tokio::test]
async fn del_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::default();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null, something: 123 } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_reset() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_basic() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_wrong() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something.wrong");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null, something: 123 } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_other() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.other.something");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null, something: 123 } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_array() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1]");
let mut val = Value::parse("{ test: { something: [123, 456, 789] } }");
let res = Value::parse("{ test: { something: [123, 789] } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_array_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }, { }] } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_array_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[*].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ }, { }] } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_array_where_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }, { }] } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn del_array_where_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35]");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }] } }");
val.del(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.del(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -97,28 +97,28 @@ mod tests {
#[tokio::test]
async fn get_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::default();
let val = Value::parse("{ test: { other: null, something: 123 } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn get_basic() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something");
let val = Value::parse("{ test: { other: null, something: 123 } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, Value::from(123));
}
#[tokio::test]
async fn get_thing() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.other");
let val = Value::parse("{ test: { other: test:tobie, something: 123 } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(
res,
Value::from(Thing {
@ -130,19 +130,19 @@ mod tests {
#[tokio::test]
async fn get_array() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1]");
let val = Value::parse("{ test: { something: [123, 456, 789] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, Value::from(456));
}
#[tokio::test]
async fn get_array_thing() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1]");
let val = Value::parse("{ test: { something: [test:tobie, test:jaime] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(
res,
Value::from(Thing {
@ -154,37 +154,37 @@ mod tests {
#[tokio::test]
async fn get_array_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1].age");
let val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, Value::from(36));
}
#[tokio::test]
async fn get_array_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[*].age");
let val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, Value::from(vec![34, 36]));
}
#[tokio::test]
async fn get_array_where_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35].age");
let val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, Value::from(vec![36]));
}
#[tokio::test]
async fn get_array_where_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35]");
let val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = val.get(&ctx, &opt, &mut exe, &idi).await.unwrap();
let res = val.get(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(
res,
Value::from(vec![Value::from(map! {

View file

@ -45,51 +45,51 @@ mod tests {
#[tokio::test]
async fn inc_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("other");
let mut val = Value::parse("{ test: 100 }");
let res = Value::parse("{ test: 100, other: +10 }");
val.increment(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.increment(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn inc_number() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: 100 }");
let res = Value::parse("{ test: 110 }");
val.increment(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.increment(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn inc_array_number() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test[1]");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 210, 300] }");
val.increment(&ctx, &opt, &mut exe, &idi, Value::from(10)).await.unwrap();
val.increment(&ctx, &opt, &exe, &idi, Value::from(10)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn inc_array_value() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 200, 300] }");
val.increment(&ctx, &opt, &mut exe, &idi, Value::from(200)).await.unwrap();
val.increment(&ctx, &opt, &exe, &idi, Value::from(200)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn inc_array_array() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 200, 300, 400, 500] }");
val.increment(&ctx, &opt, &mut exe, &idi, Value::parse("[100, 300, 400, 500]"))
val.increment(&ctx, &opt, &exe, &idi, Value::parse("[100, 300, 400, 500]"))
.await
.unwrap();
assert_eq!(res, val);

View file

@ -28,21 +28,21 @@ mod tests {
#[tokio::test]
async fn object_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::default();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{}");
val.object(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.object(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn object_path() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: {} }");
val.object(&ctx, &opt, &mut exe, &idi).await.unwrap();
val.object(&ctx, &opt, &exe, &idi).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -52,85 +52,85 @@ mod tests {
#[tokio::test]
async fn patch_add_simple() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let ops = Array::parse("[{ op: 'add', path: '/temp', value: true }]");
let res = Value::parse("{ test: { other: null, something: 123 }, temp: true }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_remove_simple() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 }, temp: true }");
let ops = Array::parse("[{ op: 'remove', path: '/temp' }]");
let res = Value::parse("{ test: { other: null, something: 123 } }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_replace_simple() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 }, temp: true }");
let ops = Array::parse("[{ op: 'replace', path: '/temp', value: 'text' }]");
let res = Value::parse("{ test: { other: null, something: 123 }, temp: 'text' }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_change_simple() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 }, temp: 'test' }");
let ops = Array::parse(
"[{ op: 'change', path: '/temp', value: '@@ -1,4 +1,4 @@\n te\n-s\n+x\n t\n' }]",
);
let res = Value::parse("{ test: { other: null, something: 123 }, temp: 'text' }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_add_embedded() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let ops = Array::parse("[{ op: 'add', path: '/temp/test', value: true }]");
let res = Value::parse("{ test: { other: null, something: 123 }, temp: { test: true } }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_remove_embedded() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 }, temp: true }");
let ops = Array::parse("[{ op: 'remove', path: '/test/other' }]");
let res = Value::parse("{ test: { something: 123 }, temp: true }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_replace_embedded() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 }, temp: true }");
let ops = Array::parse("[{ op: 'replace', path: '/test/other', value: 'text' }]");
let res = Value::parse("{ test: { other: 'text', something: 123 }, temp: true }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn patch_change_embedded() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: 'test', something: 123 }, temp: true }");
let ops = Array::parse(
"[{ op: 'change', path: '/test/other', value: '@@ -1,4 +1,4 @@\n te\n-s\n+x\n t\n' }]",
);
let res = Value::parse("{ test: { other: 'text', something: 123 }, temp: true }");
val.patch(&ctx, &opt, &mut exe, &ops).await.unwrap();
val.patch(&ctx, &opt, &exe, &ops).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -28,11 +28,11 @@ mod tests {
#[tokio::test]
async fn replace() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ other: true }");
let obj = Object::from(map! {String::from("other") => Value::from(true) });
val.replace(&ctx, &opt, &mut exe, &obj).await.unwrap();
val.replace(&ctx, &opt, &exe, &obj).await.unwrap();
assert_eq!(res, val);
}
}

View file

@ -85,101 +85,101 @@ mod tests {
#[tokio::test]
async fn set_none() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::default();
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("999");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_reset() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: 999 }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_basic() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null, something: 999 } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_wrong() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something.wrong");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: null, something: 123 } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_other() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.other.something");
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{ test: { other: { something: 999 }, something: 123 } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_array() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1]");
let mut val = Value::parse("{ test: { something: [123, 456, 789] } }");
let res = Value::parse("{ test: { something: [123, 999, 789] } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(999)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(999)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_array_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[1].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }, { age: 21 }] } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(21)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(21)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_array_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[*].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 21 }, { age: 21 }] } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(21)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(21)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_array_where_field() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35].age");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }, { age: 21 }] } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(21)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(21)).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn set_array_where_fields() {
let (ctx, opt, mut exe) = mock();
let (ctx, opt, exe) = mock();
let idi = Idiom::parse("test.something[WHERE age > 35]");
let mut val = Value::parse("{ test: { something: [{ age: 34 }, { age: 36 }] } }");
let res = Value::parse("{ test: { something: [{ age: 34 }, 21] } }");
val.set(&ctx, &opt, &mut exe, &idi, Value::from(21)).await.unwrap();
val.set(&ctx, &opt, &exe, &idi, Value::from(21)).await.unwrap();
assert_eq!(res, val);
}
}