Skip to content

Commit

Permalink
Results do not match other implementations #6
Browse files Browse the repository at this point in the history
  • Loading branch information
freestrings committed Jun 17, 2019
1 parent 1a5e8cc commit b41b9f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ mod parser_tests {
ParseToken::ArrayEof
]));

assert_eq!(run("$[:]"), Ok(vec![
ParseToken::Absolute,
ParseToken::Array,
ParseToken::Range(None, None),
ParseToken::ArrayEof
]));

match run("$[") {
Ok(_) => panic!(),
_ => {}
Expand Down Expand Up @@ -520,5 +527,12 @@ mod tokenizer_tests {
]
, Some(TokenError::Eof)
));

run("$[:]", (vec![
Token::Absolute(0),
Token::OpenArray(1),
Token::Split(2),
Token::CloseArray(3)
], Some(TokenError::Eof)));
}
}
7 changes: 7 additions & 0 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ impl Parser {

fn range_to(tokenizer: &mut TokenReader) -> ParseResult<Node> {
debug!("#range_to");
match tokenizer.peek_token() {
Ok(Token::CloseArray(_)) => {
return Ok(Self::node(ParseToken::Range(None, None)))
}
_ => {}
}

match tokenizer.next_token() {
Ok(Token::Key(pos, ref val)) => {
let digit = utils::string_to_isize(val, || tokenizer.err_msg_with_pos(pos))?;
Expand Down
7 changes: 7 additions & 0 deletions tests/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,11 @@ fn filer_same_obj() {
{"a": 1},
{"a": 1}
]));
}

#[test]
fn empty_range() {
setup();

select_and_then_compare("$[:]", json!(["first", "second"]), json!(["first", "second"]));
}

0 comments on commit b41b9f3

Please sign in to comment.