From 2af78efd50a5d2700b4b5a85f9f6018f32cebb1b Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Sat, 17 Dec 2016 20:14:03 +0100 Subject: [PATCH] Extracting integer --- Sources/Document+Extraction.swift | 4 ++++ Tests/BSONTests/BSONPublicTests.swift | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Sources/Document+Extraction.swift b/Sources/Document+Extraction.swift index 84f4658..b4262d7 100644 --- a/Sources/Document+Extraction.swift +++ b/Sources/Document+Extraction.swift @@ -6,6 +6,10 @@ extension Document { return nil } + if T.self == Int.self { + return response.int as? T + } + return response.rawValue as? T } } diff --git a/Tests/BSONTests/BSONPublicTests.swift b/Tests/BSONTests/BSONPublicTests.swift index 8813b03..2d04c9c 100644 --- a/Tests/BSONTests/BSONPublicTests.swift +++ b/Tests/BSONTests/BSONPublicTests.swift @@ -551,6 +551,9 @@ final class BSONPublicTests: XCTestCase { let regex = kittenDocument.extract("regex") as RegularExpression? XCTAssertNotNil(regex) XCTAssertEqual(regex?.pattern, "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}") + + XCTAssertEqual(kittenDocument.extract("cool32bitNumber") as Int?, 9001) + XCTAssertEqual(kittenDocument.extract("cool64bitNumber") as Int?, 21312153) } func testKeyDetection() {