Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Add tests to verify expected behaviour of quoted expressions and string that look like expressions.
Remove comments that look like old merge conflict left overs and apply code format.

Original Pull Request: #4807
  • Loading branch information
christophstrobl committed Oct 15, 2024
1 parent dc1bd84 commit a8c3644
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ void regexConsidersBindValueWithOptions() {
assertThat(pattern.getOptions()).isEqualTo("i");
}

@Test // GH-4806
void treatsQuotedValueThatLooksLikeRegexAsPlainString() {

Document target = parse("{ 'c': '/^?0$/i' }", "foo");

assertThat(target.get("c")).isInstanceOf(String.class);
}

@Test // GH-4806
void treatsStringParameterValueThatLooksLikeRegexAsPlainString() {

Document target = parse("{ 'c': ?0 }", "/^foo$/i");

assertThat(target.get("c")).isInstanceOf(String.class);
}

@Test
void bindValueToRegex() {

Expand Down Expand Up @@ -145,15 +161,13 @@ void bindToKey() {
@Test
void bindListValue() {

//
Document target = parse("{ 'lastname' : { $in : ?0 } }", Arrays.asList("Kohlin", "Davar"));
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { $in : ['Kohlin', 'Davar' ]} }"));
}

@Test
void bindListOfBinaryValue() {

//
byte[] value = "Kohlin".getBytes(StandardCharsets.UTF_8);
List<byte[]> args = Collections.singletonList(value);

Expand All @@ -168,28 +182,23 @@ void bindExtendedExpression() {
assertThat(target).isEqualTo(Document.parse("{ \"id\" : { \"$exists\" : true}}"));
}

// {'id':?#{ [0] ? { $exists :true} : [1] }}

@Test
void bindDocumentValue() {

//
Document target = parse("{ 'lastname' : ?0 }", new Document("$eq", "Kohlin"));
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { '$eq' : 'Kohlin' } }"));
}

@Test
void arrayWithoutBinding() {

//
Document target = parse("{ 'lastname' : { $in : [\"Kohlin\", \"Davar\"] } }");
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { $in : ['Kohlin', 'Davar' ]} }"));
}

@Test
void bindSpEL() {

// "{ arg0 : ?#{[0]} }"
Document target = parse("{ arg0 : ?#{[0]} }", 100.01D);
assertThat(target).isEqualTo(new Document("arg0", 100.01D));
}
Expand Down

0 comments on commit a8c3644

Please sign in to comment.