Skip to content

Commit

Permalink
Merge pull request #39 from ninjaprawn/testing
Browse files Browse the repository at this point in the history
Closes #39.
  • Loading branch information
sharplet committed Sep 15, 2016
2 parents 44046c1 + 4739d80 commit eab992d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Source/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public struct Options: OptionSetType {
/// foo.allMatches("foo\nbar\nfoo\n").count // 2
public static let AnchorsMatchLines = Options(rawValue: 1 << 2)

/// Usually, "." matches all characters except newlines (\n). Using this
/// this options will allow "." to match newLines
///
/// let newLines = Regex("test.test", options: .DotMatchesLineSeparators)
/// newLines.allMatches("test\ntest").count // 1
public static let DotMatchesLineSeparators = Options(rawValue: 1 << 3)

// MARK: OptionSetType

public let rawValue: Int
Expand All @@ -46,6 +53,7 @@ internal extension Options {
if contains(.IgnoreCase) { options.insert(.CaseInsensitive) }
if contains(.IgnoreMetacharacters) { options.insert(.IgnoreMetacharacters) }
if contains(.AnchorsMatchLines) { options.insert(.AnchorsMatchLines) }
if contains(.DotMatchesLineSeparators) { options.insert(.DotMatchesLineSeparators) }
return options
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/OptionsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ final class OptionsSpec: QuickSpec {
}
}

describe(".DotMatchesLineSeparators") {
it("allows dot to match newlines") {
let regex = Regex("test.test", options: .DotMatchesLineSeparators)
let multilineString = "test\ntest"
expect(regex.allMatches(multilineString).count).to(equal(1))
}
}

}
}

Expand Down

0 comments on commit eab992d

Please sign in to comment.