@@ -4351,6 +4351,113 @@ public void TestWhereSEndsWithAbcNot()
4351
4351
Assert . AreEqual ( 4 , Consume ( query ) ) ;
4352
4352
}
4353
4353
4354
+ [ Test ]
4355
+ public void TestWhereSIndexOfAnyBC ( )
4356
+ {
4357
+ var collection = _database . GetCollection ( "temp" ) ;
4358
+ collection . Drop ( ) ;
4359
+ collection . Insert ( new C { S = "bxxx" } ) ;
4360
+ collection . Insert ( new C { S = "xbxx" } ) ;
4361
+ collection . Insert ( new C { S = "xxbx" } ) ;
4362
+ collection . Insert ( new C { S = "xxxb" } ) ;
4363
+ collection . Insert ( new C { S = "bxbx" } ) ;
4364
+ collection . Insert ( new C { S = "xbbx" } ) ;
4365
+ collection . Insert ( new C { S = "xxbb" } ) ;
4366
+
4367
+ var query1 =
4368
+ from c in collection . AsQueryable < C > ( )
4369
+ where c . S . IndexOfAny ( new char [ ] { 'b' , 'c' } ) == 2
4370
+ select c ;
4371
+ Assert . AreEqual ( 2 , Consume ( query1 ) ) ;
4372
+
4373
+ var query2 =
4374
+ from c in collection . AsQueryable < C > ( )
4375
+ where c . S . IndexOfAny ( new char [ ] { 'b' , 'c' } , 1 ) == 2
4376
+ select c ;
4377
+ Assert . AreEqual ( 3 , Consume ( query2 ) ) ;
4378
+
4379
+ var query3 =
4380
+ from c in collection . AsQueryable < C > ( )
4381
+ where c . S . IndexOfAny ( new char [ ] { 'b' , 'c' } , 1 , 1 ) == 2
4382
+ select c ;
4383
+ Assert . AreEqual ( 0 , Consume ( query3 ) ) ;
4384
+
4385
+ var query4 =
4386
+ from c in collection . AsQueryable < C > ( )
4387
+ where c . S . IndexOfAny ( new char [ ] { 'b' , 'c' } , 1 , 2 ) == 2
4388
+ select c ;
4389
+ Assert . AreEqual ( 3 , Consume ( query4 ) ) ;
4390
+ }
4391
+
4392
+ [ Test ]
4393
+ public void TestWhereSIndexOfAnyBDashCEquals1 ( )
4394
+ {
4395
+ var query = from c in _collection . AsQueryable < C > ( )
4396
+ where c . S . IndexOfAny ( new char [ ] { 'b' , '-' , 'c' } ) == 1
4397
+ select c ;
4398
+
4399
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4400
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4401
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4402
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4403
+
4404
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4405
+ Assert . AreEqual ( "(C c) => (c.S.IndexOfAny(Char[]:{ 'b', '-', 'c' }) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4406
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4407
+ Assert . IsNull ( selectQuery . Projection ) ;
4408
+ Assert . IsNull ( selectQuery . Skip ) ;
4409
+ Assert . IsNull ( selectQuery . Take ) ;
4410
+
4411
+ Assert . AreEqual ( "{ \" s\" : /^[^b\\ -c]{1}[b\\ -c]/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4412
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4413
+ }
4414
+
4415
+ [ Test ]
4416
+ public void TestWhereSIndexOfAnyBCStartIndex1Equals1 ( )
4417
+ {
4418
+ var query = from c in _collection . AsQueryable < C > ( )
4419
+ where c . S . IndexOfAny ( new char [ ] { 'b' , '-' , 'c' } , 1 ) == 1
4420
+ select c ;
4421
+
4422
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4423
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4424
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4425
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4426
+
4427
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4428
+ Assert . AreEqual ( "(C c) => (c.S.IndexOfAny(Char[]:{ 'b', '-', 'c' }, 1) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4429
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4430
+ Assert . IsNull ( selectQuery . Projection ) ;
4431
+ Assert . IsNull ( selectQuery . Skip ) ;
4432
+ Assert . IsNull ( selectQuery . Take ) ;
4433
+
4434
+ Assert . AreEqual ( "{ \" s\" : /^.{1}[^b\\ -c]{0}[b\\ -c]/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4435
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4436
+ }
4437
+
4438
+ [ Test ]
4439
+ public void TestWhereSIndexOfAnyBCStartIndex1Count2Equals1 ( )
4440
+ {
4441
+ var query = from c in _collection . AsQueryable < C > ( )
4442
+ where c . S . IndexOfAny ( new char [ ] { 'b' , '-' , 'c' } , 1 , 2 ) == 1
4443
+ select c ;
4444
+
4445
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4446
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4447
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4448
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4449
+
4450
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4451
+ Assert . AreEqual ( "(C c) => (c.S.IndexOfAny(Char[]:{ 'b', '-', 'c' }, 1, 2) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4452
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4453
+ Assert . IsNull ( selectQuery . Projection ) ;
4454
+ Assert . IsNull ( selectQuery . Skip ) ;
4455
+ Assert . IsNull ( selectQuery . Take ) ;
4456
+
4457
+ Assert . AreEqual ( "{ \" s\" : /^.{1}(?=.{2})[^b\\ -c]{0}[b\\ -c]/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4458
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4459
+ }
4460
+
4354
4461
[ Test ]
4355
4462
public void TestWhereSIndexOfB ( )
4356
4463
{
@@ -5068,7 +5175,7 @@ where c.S.TrimStart(' ', '.', '-', '\t').TrimEnd().ToLower().Contains("xyz")
5068
5175
Assert . IsNull ( selectQuery . Skip ) ;
5069
5176
Assert . IsNull ( selectQuery . Take ) ;
5070
5177
5071
- Assert . AreEqual ( "{ \" s\" : /^[\\ \\ .\\ t- ]*.*xyz.*\\ s*$/is }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
5178
+ Assert . AreEqual ( "{ \" s\" : /^[\\ \\ .\\ - \\ t ]*.*xyz.*\\ s*$/is }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
5072
5179
Assert . AreEqual ( 1 , Consume ( query ) ) ;
5073
5180
}
5074
5181
0 commit comments