Browse Source
Implemented CSHARP-260. Modified JsonReader to support additional ways of representing regular expressions.
pull/63/head
Implemented CSHARP-260. Modified JsonReader to support additional ways of representing regular expressions.
pull/63/head

11 changed files with 185 additions and 39 deletions
-
56Bson/IO/JsonReader.cs
-
3Bson/IO/JsonScanner.cs
-
10Bson/IO/JsonWriter.cs
-
1BsonUnitTests/BsonUnitTests.csproj
-
4BsonUnitTests/DefaultSerializer/Serializers/BsonValueSerializerTests.cs
-
12BsonUnitTests/IO/BsonDocumentWriterTests.cs
-
8BsonUnitTests/IO/JsonReaderTests.cs
-
4BsonUnitTests/IO/JsonScannerTests.cs
-
10BsonUnitTests/IO/JsonWriterTests.cs
-
114BsonUnitTests/Jira/CSharp260Tests.cs
-
2BsonUnitTests/ObjectModel/BsonValueIConvertibleTests.cs
@ -0,0 +1,114 @@ |
|||
/* Copyright 2010-2011 10gen Inc. |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using NUnit.Framework; |
|||
|
|||
using MongoDB.Bson; |
|||
using MongoDB.Bson.IO; |
|||
using MongoDB.Bson.Serialization; |
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
|
|||
namespace MongoDB.BsonUnitTests.Jira.CSharp260 { |
|||
[TestFixture] |
|||
public class CSharp260Tests { |
|||
[Test] |
|||
public void TestConstantPattern() { |
|||
var json = "{ rx : /abc/ }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestConstantPatternWithOptions() { |
|||
var json = "{ rx : /abc/imxs }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("imxs", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestNewRegExpPattern() { |
|||
var json = "{ rx : new RegExp('abc') }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestNewRegExpPatternWithOptions() { |
|||
var json = "{ rx : new RegExp('abc', 'imxs') }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("imxs", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestRegExpPattern() { |
|||
var json = "{ rx : RegExp('abc') }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestRegExpPatternWithOptions() { |
|||
var json = "{ rx : RegExp('abc', 'imxs') }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("imxs", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestStrictPattern() { |
|||
var json = "{ rx : { $regex : 'abc' } }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("", rx.Options); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestStrictPatternWithOptions() { |
|||
var json = "{ rx : { $regex : 'abc', $options : 'imxs' } }"; |
|||
var document = BsonDocument.Parse(json); |
|||
Assert.AreEqual(BsonType.RegularExpression, document["rx"].BsonType); |
|||
var rx = document["rx"].AsBsonRegularExpression; |
|||
Assert.AreEqual("abc", rx.Pattern); |
|||
Assert.AreEqual("imxs", rx.Options); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue