diff --git a/.idea/runConfigurations/filter.xml b/.idea/runConfigurations/filter.xml
deleted file mode 100644
index 157a24b..0000000
--- a/.idea/runConfigurations/filter.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/lib.xml b/.idea/runConfigurations/lib.xml
deleted file mode 100644
index 6bd36ec..0000000
--- a/.idea/runConfigurations/lib.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/mutable.xml b/.idea/runConfigurations/mutable.xml
deleted file mode 100644
index 765dcaf..0000000
--- a/.idea/runConfigurations/mutable.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/readme.xml b/.idea/runConfigurations/readme.xml
deleted file mode 100644
index 02c612e..0000000
--- a/.idea/runConfigurations/readme.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 3a56064..543e927 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,15 +24,9 @@ matrix:
before_script:
- rustup component add clippy
script:
- - cargo clean
- - cargo clippy -- -D warnings
- - cargo build --verbose --all
- - cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity
- - cargo test --verbose --all
- - cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting
- - cd ../../
+ - ./clippy.sh
after_success: |
- cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml
+ cargo tarpaulin --exclude-files wasm parser/mod.rs --out Xml
bash <(curl -s https://codecov.io/bash)
- rust: stable
os: osx
diff --git a/clippy.sh b/clippy.sh
new file mode 100755
index 0000000..9bf44eb
--- /dev/null
+++ b/clippy.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -e
+
+cargo clean
+cargo clippy -- -D warnings
+cargo build --verbose --all
+cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity
+cargo test --verbose --all
+cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting
+cd ../
\ No newline at end of file
diff --git a/src/select/mod.rs b/src/select/mod.rs
index c6f7716..142b973 100644
--- a/src/select/mod.rs
+++ b/src/select/mod.rs
@@ -710,17 +710,37 @@ impl<'a, 'b> Selector<'a, 'b> {
}
fn next_from_current_with_num(&mut self, index: f64) {
+ fn _collect<'a>(tmp: &mut Vec<&'a Value>, vec: &'a [Value], index: f64) {
+ let index = abs_index(index as isize, vec.len());
+ if let Some(v) = vec.get(index) {
+ tmp.push(v);
+ }
+ }
+
if let Some(current) = self.current.take() {
let mut tmp = Vec::new();
for c in current {
- if let Value::Array(vec) = c {
- let index = abs_index(index as isize, vec.len());
- if let Some(v) = c.get(index) {
- tmp.push(v);
+ match c {
+ Value::Object(map) => {
+ for k in map.keys() {
+ if let Some(Value::Array(vec)) = map.get(k) {
+ _collect(&mut tmp, vec, index);
+ }
+ }
}
+ Value::Array(vec) => {
+ _collect(&mut tmp, vec, index);
+ }
+ _ => {}
}
}
- self.current = Some(tmp);
+
+ if tmp.is_empty() {
+ self.terms.pop();
+ self.current = Some(vec![&Value::Null]);
+ } else {
+ self.current = Some(tmp);
+ }
}
debug!(
@@ -729,27 +749,6 @@ impl<'a, 'b> Selector<'a, 'b> {
);
}
- fn next_from_current_with_str(&mut self, keys: &[String]) {
- if let Some(current) = self.current.take() {
- let mut tmp = Vec::new();
- for c in current {
- if let Value::Object(map) = c {
- for key in keys {
- if let Some(v) = map.get(key) {
- tmp.push(v)
- }
- }
- }
- }
- self.current = Some(tmp);
- }
-
- debug!(
- "next_from_current_with_str : {:?}, {:?}",
- keys, self.current
- );
- }
-
fn next_all_from_current(&mut self) {
if let Some(current) = self.current.take() {
let mut tmp = Vec::new();
@@ -774,6 +773,32 @@ impl<'a, 'b> Selector<'a, 'b> {
debug!("next_all_from_current : {:?}", self.current);
}
+ fn next_from_current_with_str(&mut self, keys: &[String]) {
+ if let Some(current) = self.current.take() {
+ let mut tmp = Vec::new();
+ for c in current {
+ if let Value::Object(map) = c {
+ for key in keys {
+ if let Some(v) = map.get(key) {
+ tmp.push(v)
+ }
+ }
+ }
+ }
+
+ if tmp.is_empty() {
+ self.current = Some(vec![&Value::Null]);
+ } else {
+ self.current = Some(tmp);
+ }
+ }
+
+ debug!(
+ "next_from_current_with_str : {:?}, {:?}",
+ keys, self.current
+ );
+ }
+
fn all_from_current(&mut self) {
if let Some(current) = self.current.take() {
let mut tmp = Vec::new();
diff --git a/tests/return_type.rs b/tests/return_type.rs
index a1e0e40..04a5fed 100644
--- a/tests/return_type.rs
+++ b/tests/return_type.rs
@@ -1,6 +1,8 @@
#[macro_use]
extern crate serde_json;
+use serde_json::Value;
+
use common::{read_json, select_and_then_compare, setup};
mod common;
@@ -53,14 +55,14 @@ fn return_type_for_child_object_matched() {
);
}
-// #[test]
+#[test]
fn return_type_for_child_object_not_matched() {
setup();
select_and_then_compare(
"$.school[?(@.friends[10])]",
read_json("./benchmark/data_obj.json"),
- json!([]),
+ json!([Value::Null]),
);
}