Skip to content

Commit

Permalink
Allow Not operands in Or expressions (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwagner84 authored Aug 23, 2023
1 parent 8e4023c commit 0c21158
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
### Added

* #687 Allow multi-field queries in `frequency` command


### Fixed

* #688 Allow `Not` operands in `Or` expressions


## [0.18.0] - 2023-07-27

### Added
Expand Down
2 changes: 2 additions & 0 deletions pica-matcher/src/field_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ fn parse_field_matcher_or(i: &[u8]) -> ParseResult<FieldMatcher> {
ws(parse_field_matcher_and),
ws(parse_field_matcher_cardinality),
ws(parse_field_matcher_singleton),
ws(parse_field_matcher_not),
ws(parse_field_matcher_exists),
)),
many1(preceded(
Expand All @@ -619,6 +620,7 @@ fn parse_field_matcher_or(i: &[u8]) -> ParseResult<FieldMatcher> {
ws(parse_field_matcher_and),
ws(parse_field_matcher_cardinality),
ws(parse_field_matcher_singleton),
ws(parse_field_matcher_not),
ws(parse_field_matcher_exists),
))),
)),
Expand Down
12 changes: 12 additions & 0 deletions pica-matcher/tests/field_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,17 @@ fn field_matcher_composite_or() -> anyhow::Result<()> {
&options
));

let matcher =
FieldMatcher::new("!014A.x? || 013A{#a == 2 && a == '1'}")?;
let options = MatcherOptions::default();

assert!(matcher.is_match(
vec![
&FieldMut::new("012A", None, vec![('0', "abc")]),
&FieldMut::new("013A", None, vec![('a', "1"), ('a', "2")]),
],
&options
));

Ok(())
}
15 changes: 15 additions & 0 deletions pica-matcher/tests/subfield_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,21 @@ fn subfield_matcher_or() -> anyhow::Result<()> {
assert!(!matcher
.is_match(&SubfieldRef::from_bytes(b"\x1fabcbc")?, &options));

// or
let matcher = SubfieldMatcher::new("!a? || b == 'x'")?;
let options = MatcherOptions::default();

assert!(!matcher
.is_match(&SubfieldRef::from_bytes(b"\x1faabab")?, &options));

assert!(matcher.is_match(
vec![
&SubfieldRef::from_bytes(b"\x1fabccd")?,
&SubfieldRef::from_bytes(b"\x1fbx")?
],
&options
));

// not
let matcher = SubfieldMatcher::new("a == 'bcd' || !(a != 'def')")?;
let options = MatcherOptions::default();
Expand Down

0 comments on commit 0c21158

Please sign in to comment.