Skip to content

Commit 35d1484

Browse files
Polishing.
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
1 parent 0561b80 commit 35d1484

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReaderUnitTests.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ void regexConsidersBindValueWithOptions() {
102102
assertThat(pattern.getOptions()).isEqualTo("i");
103103
}
104104

105+
@Test // GH-4806
106+
void treatsQuotedValueThatLooksLikeRegexAsPlainString() {
107+
108+
Document target = parse("{ 'c': '/^?0$/i' }", "foo");
109+
110+
assertThat(target.get("c")).isInstanceOf(String.class);
111+
}
112+
113+
@Test // GH-4806
114+
void treatsStringParameterValueThatLooksLikeRegexAsPlainString() {
115+
116+
Document target = parse("{ 'c': ?0 }", "/^foo$/i");
117+
118+
assertThat(target.get("c")).isInstanceOf(String.class);
119+
}
120+
105121
@Test
106122
void bindValueToRegex() {
107123

@@ -145,15 +161,13 @@ void bindToKey() {
145161
@Test
146162
void bindListValue() {
147163

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

153168
@Test
154169
void bindListOfBinaryValue() {
155170

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

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

171-
// {'id':?#{ [0] ? { $exists :true} : [1] }}
172-
173185
@Test
174186
void bindDocumentValue() {
175187

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

181192
@Test
182193
void arrayWithoutBinding() {
183194

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

189199
@Test
190200
void bindSpEL() {
191201

192-
// "{ arg0 : ?#{[0]} }"
193202
Document target = parse("{ arg0 : ?#{[0]} }", 100.01D);
194203
assertThat(target).isEqualTo(new Document("arg0", 100.01D));
195204
}

0 commit comments

Comments
 (0)