Repository: MiSawa/xq
Pull request #64 (2022-02-23 05:02:29)

Fix contains filter on booleans to be jq compatible
This PR fixes `contains/1` filter to be more jq compatible. This filter on booleans emits error if the values are different.
```sh
❯ jq -c '.[] | [contains(.,not)?]' <<< '[false,true]'
[true]
[true]

❯ jq -n 'true | contains(false)'
jq: error (at <unknown>): boolean (true) and boolean (false) cannot have their containment checked

❯ xq -c '.[] | [contains(.,not)?]' <<< '[false,true]'
[true,false]
[true,false]

❯ xq --version
xq 0.2.2-df131ce732645c4c89d9b393404c8fd0be2f08e5
```


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 00cdda9..25ad66c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1079,7 +1079,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 
 [[package]]
 name = "xq"
-version = "0.2.3"
+version = "0.2.1"
 dependencies = [
  "anyhow",
  "base64",
diff --git a/Cargo.toml b/Cargo.toml
index 7c232be..c7e2a0b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "xq"
-version = "0.2.3"
+version = "0.2.2"
 authors = ["mi_sawa <mi.sawa.1216+git@gmail.com>"]
 edition = "2021"
 description = "A reimplementation of jq."
diff --git a/README.md b/README.md
index 5851a43..296d658 100644
--- a/README.md
+++ b/README.md
@@ -76,12 +76,10 @@ if you've installed via `cargo install`. Also remove the cloned directory if you
 ## Pubilsh new version
 Note for myself. TL;DR: Bump the version, reflect it to the lock file, commit changes and `cargo publish`.
 ```shell
-$ git swithc master                 # make sure you're on the master branch
 $ cargo set-version --bump patch    # or just edit Cargo.toml to bump the version
 $ cargo build                       # to generate Cargo.lock
 $ git commit -am "Bump version"     # so that there's no uncommited changes
-$ git tag v0.2.x                    # just in case...
-$ git push --tags
+$ git push                          # and it's synced with the remote repo
 $ cargo publish
 ```
 
diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs
index 967f651..9f65092 100644
--- a/src/intrinsic/mod.rs
+++ b/src/intrinsic/mod.rs
@@ -171,7 +171,7 @@ fn contains(context: Value, element: Value) -> Result<Value> {
     fn contains_rec(lhs: &Value, rhs: &Value) -> Result<bool> {
         Ok(match (lhs, rhs) {
             (Value::Null, Value::Null) => true,
-            (Value::Boolean(lhs), Value::Boolean(rhs)) => lhs == rhs,
+            (Value::Boolean(lhs), Value::Boolean(rhs)) if lhs == rhs => true,
             (Value::Number(lhs), Value::Number(rhs)) => lhs == rhs, // TODO: nan handling in JQ semantics...
             (Value::String(lhs), Value::String(rhs)) => lhs.contains(rhs.as_ref()),
             (Value::Array(lhs), Value::Array(rhs)) => rhs


Test patch:
diff --git a/tests/hand_written/mod.rs b/tests/hand_written/mod.rs
index 7dc68e0..2be4b5f 100644
--- a/tests/hand_written/mod.rs
+++ b/tests/hand_written/mod.rs
@@ -98,6 +98,20 @@ test!(
     "#
 );
 
+test!(
+    contains_on_boolean,
+    r#"
+    .[] | [contains(.,not)?]
+    "#,
+    r#"
+    [false,true]
+    "#,
+    r#"
+    [true]
+    [true]
+    "#
+);
+
 test!(
     indices_with_empty_array,
     r#"