Skip to content

Slight API change #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ package com.github.verbalexpressions
import java.util.regex.Pattern
import com.github.verbalexpressions.VerbalExpression._

case class VerbalExpression(prefix: String = "", expression: String = "", suffix: String = "", modifiers: Int = 0) {
final case class VerbalExpression(prefix: String = "", expression: String = "", suffix: String = "", modifiers: Int = 0) {

def add(value: String) = copy(expression = expression + value)
private[verbalexpressions] def add(value: String) = copy(expression = expression + value)

def andThen(value: StringOrVerbalExp) = add(s"($value)")
def `then` = andThen _
@@ -33,8 +33,13 @@ case class VerbalExpression(prefix: String = "", expression: String = "", suffix
def any = anyOf _

def lineBreak = add("(\\n|(\\r\\n))")
def startOfLine(enable: Boolean = true) = copy(prefix = if (enable) "^" else "")
def endOfLine(enable: Boolean = true) = copy(suffix = if (enable) "$" else "")
def mustStartLine() = startOfLine()
def lineStartNotMandatory() = startOfLine(false)
private[verbalexpressions] def startOfLine(enable: Boolean = true) = copy(prefix = if (enable) "^" else "")

def mustEndLine() = endOfLine()
def endOfLineNotMandatory() = endOfLine(false)
private[verbalexpressions] def endOfLine(enable: Boolean = true) = copy(suffix = if (enable) "$" else "")

def or(value: StringOrVerbalExp) = copy("(" + prefix, expression + ")|(" + value, ")" + suffix)

Original file line number Diff line number Diff line change
@@ -55,6 +55,16 @@ final class VerbalExpressionSpec extends Specification {
.startOfLine(false)
.toString mustEqual "expr"
}

"be turned on with 'mustStartLine'" in {
VerbalExpression().mustStartLine().toString mustEqual "^"
}

"be turned off with 'lineStartNotMandatory'" in {
VerbalExpression("^", "expr")
.lineStartNotMandatory()
.toString mustEqual "expr"
}
}

"endOfLine" should {