Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'samus/master'

  • Loading branch information...
commit 93ccee00fd0bd1f88f66b5cecaab3b18f2212a28 2 parents f604a53 + f264954
unknown authored
View
14 source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs
@@ -355,6 +355,20 @@ where Regex.IsMatch(p.FirstName, "Joe")
}
[Test]
+ public void Regex_IsMatch_CaseInsensitive()
+ {
+ var people = from p in Collection.Linq()
+ where Regex.IsMatch(p.FirstName, "Joe", RegexOptions.IgnoreCase)
+ select p;
+
+ var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(0, queryObject.NumberToLimit);
+ Assert.AreEqual(0, queryObject.NumberToSkip);
+ Assert.AreEqual(new Document("FirstName", new MongoRegex("Joe", MongoRegexOption.IgnoreCase)), queryObject.Query);
+ }
+
+ [Test]
public void SingleEqualConstraint()
{
var people = Collection.Linq().Where(p => "Jack" == p.FirstName);
View
10 source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs
@@ -371,6 +371,16 @@ where Regex.IsMatch(p.FirstName, "Joe")
}
[Test]
+ public void Regex_IsMatch_CaseInsensitive()
+ {
+ var people = (from p in Collection.Linq()
+ where Regex.IsMatch(p.FirstName, "joe", RegexOptions.IgnoreCase)
+ select p).ToList();
+
+ Assert.AreEqual(1, people.Count);
+ }
+
+ [Test]
public void Single()
{
var person = Collection.Linq().Where(x => x.Age == 21).Single();
View
16 source/MongoDB.Tests/UnitTests/TestMongoRegex.cs
@@ -46,6 +46,14 @@ public void CanBeConstructedFromRegex()
}
[Test]
+ public void MongoRegexOptionFlagsAreIndependent()
+ {
+ var regex = new MongoRegex("expression", MongoRegexOption.IgnoreCase);
+ Assert.AreEqual("expression", regex.Expression);
+ Assert.AreEqual("i", regex.RawOptions);
+ }
+
+ [Test]
public void CanBeConstructedWithMongoRegexOption()
{
var regex = new MongoRegex("expression", MongoRegexOption.IgnoreCase | MongoRegexOption.IgnorePatternWhitespace | MongoRegexOption.Multiline);
@@ -54,6 +62,14 @@ public void CanBeConstructedWithMongoRegexOption()
}
[Test]
+ public void CanBeConstructedWithRegexOptions()
+ {
+ var regex = new MongoRegex("expression", RegexOptions.IgnoreCase | RegexOptions.Multiline);
+ Assert.AreEqual("expression", regex.Expression);
+ Assert.AreEqual("im", regex.RawOptions);
+ }
+
+ [Test]
public void CanReadOptions()
{
var regex = new MongoRegex("expression", "img");
View
6 source/MongoDB/Linq/Translators/DocumentFormatter.cs
@@ -225,7 +225,11 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
else
throw new InvalidQueryException(string.Format("Only the static Regex.IsMatch is supported.", m.Method.Name));
- AddCondition(new MongoRegex(value));
+ var regexOptions = RegexOptions.None;
+ if (m.Arguments.Count > 2)
+ regexOptions = EvaluateConstant<RegexOptions>(m.Arguments[2]);
+
+ AddCondition(new MongoRegex(value, regexOptions));
PopConditionScope();
return m;
}
View
10 source/MongoDB/MongoRegex.cs
@@ -39,6 +39,16 @@ public MongoRegex(string expression, MongoRegexOption options)
}
/// <summary>
+ /// Initializes a new instance of the <see cref="MongoRegex"/> class.
+ /// </summary>
+ /// <param name="expression">The Regex expression.</param>
+ /// <param name="options">The Regex options.</param>
+ public MongoRegex(string expression, RegexOptions options)
+ : this(new Regex(expression, options))
+ {
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref = "MongoRegex" /> class.
/// </summary>
/// <param name = "regex">The regex.</param>
View
2  source/MongoDB/MongoRegexOption.cs
@@ -25,6 +25,6 @@ public enum MongoRegexOption
/// <summary>
/// g - Eliminates unescaped white space from the pattern.
/// </summary>
- IgnorePatternWhitespace = 3
+ IgnorePatternWhitespace = 4
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.