Don’t treat arrays as sets

Closes #1690
This commit is contained in:
Tobie Morgan Hitchcock 2023-03-25 22:38:09 +00:00
parent b49d58a362
commit 4dba9fc675
3 changed files with 35 additions and 40 deletions

View file

@ -175,21 +175,15 @@ impl Serialize for Array {
impl ops::Add<Value> for Array {
type Output = Self;
fn add(mut self, other: Value) -> Self {
if !self.0.iter().any(|x| *x == other) {
self.0.push(other)
}
self.0.push(other);
self
}
}
impl ops::Add for Array {
type Output = Self;
fn add(mut self, other: Self) -> Self {
for v in other.0 {
if !self.0.iter().any(|x| *x == v) {
self.0.push(v)
}
}
fn add(mut self, mut other: Self) -> Self {
self.0.append(&mut other.0);
self
}
}

View file

@ -79,7 +79,7 @@ mod tests {
let (ctx, opt, txn) = mock().await;
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 200, 300, 200] }");
val.increment(&ctx, &opt, &txn, &idi, Value::from(200)).await.unwrap();
assert_eq!(res, val);
}
@ -89,7 +89,7 @@ mod tests {
let (ctx, opt, txn) = mock().await;
let idi = Idiom::parse("test");
let mut val = Value::parse("{ test: [100, 200, 300] }");
let res = Value::parse("{ test: [100, 200, 300, 400, 500] }");
let res = Value::parse("{ test: [100, 200, 300, 100, 300, 400, 500] }");
val.increment(&ctx, &opt, &txn, &idi, Value::parse("[100, 300, 400, 500]")).await.unwrap();
assert_eq!(res, val);
}

View file

@ -149,37 +149,10 @@ async fn subquery_ifelse() -> Result<(), Error> {
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
sport: [
'basketball'
]
}",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::None;
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
count: 1,
id: person:test,
sport: [
'basketball'
]
}",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
sport: [
'basketball',
'football'
]
}",
);
@ -196,7 +169,6 @@ async fn subquery_ifelse() -> Result<(), Error> {
id: person:test,
sport: [
'basketball',
'football'
]
}",
);
@ -207,7 +179,36 @@ async fn subquery_ifelse() -> Result<(), Error> {
"{
sport: [
'basketball',
'football'
'football',
]
}",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::None;
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
count: 1,
id: person:test,
sport: [
'basketball',
'football',
]
}",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
sport: [
'basketball',
'football',
'football',
]
}",
);