This repository has been archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We wanted to have the ability to match the verbal expression spec.
- Loading branch information
Kurtis Rainbolt-Greene
committed
Aug 30, 2013
1 parent
c53d524
commit 7440889
Showing
2 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "express" | ||
require "pry" | ||
|
||
class Express | ||
alias_method :startOfLine, :starting | ||
alias_method :then, :with | ||
alias_method :lineBreak, :line | ||
alias_method :br, :line | ||
|
||
def anythingBut(value) | ||
many(matching { without(value) }.to_s, 0) | ||
end | ||
|
||
def somethingBut(value) | ||
something and without(value) | ||
end | ||
|
||
module Modifier | ||
class Many | ||
def to_s | ||
"#{open}#{value}#{operator}#{close}" | ||
end | ||
end | ||
end | ||
|
||
module Nested | ||
class Find | ||
def open | ||
"(?:" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require "spec_helper" | ||
require "express/verbal_expressions" | ||
|
||
describe "VerbalExpressions" do | ||
def expressed(method, *arguments) | ||
Express.new.send(method, *arguments).to_s | ||
end | ||
|
||
describe "#startOfLine" do | ||
it 'returns `^`' do | ||
expect(expressed(:startOfLine)).to eq('^') | ||
end | ||
end | ||
|
||
describe "#endOfLine" do | ||
it 'returns `$`' do | ||
expect(expressed(:endOfLine)).to eq('$') | ||
end | ||
end | ||
|
||
describe "#find" do | ||
it 'returns `(?:foo)`' do | ||
expect(expressed(:find, "foo")).to eq('(?:foo)') | ||
end | ||
end | ||
|
||
describe "#maybe" do | ||
it 'returns `(?:foo)?`' do | ||
expect(expressed(:maybe, "foo")).to eq('(?:foo)?') | ||
end | ||
end | ||
|
||
describe "#anything" do | ||
it 'returns `(?:.*)`' do | ||
expect(expressed(:anything)).to eq('(?:.*)') | ||
end | ||
end | ||
|
||
describe "#anythingBut" do | ||
it 'returns `(?:[^f]*)`' do | ||
expect(expressed(:anythingBut, "f")).to eq('(?:[^f]*)') | ||
end | ||
end | ||
|
||
describe "#something" do | ||
it 'returns `(?:.+)`' do | ||
expect(expressed(:something)).to eq('(?:.+)') | ||
end | ||
end | ||
|
||
describe "#somethingBut" do | ||
it 'returns `(?:[^f]+)`' do | ||
expect(expressed(:somethingBut)).to eq('(?:[^f]+)') | ||
end | ||
end | ||
|
||
describe "#lineBreak" do | ||
it 'returns `(?:(?:\n)|(?:\r\n))`' do | ||
expect(expressed(:lineBreak)).to eq('(?:(?:\n)|(?:\r\n))') | ||
end | ||
end | ||
|
||
describe "#br" do | ||
it 'returns `(?:(?:\n)|(?:\r\n))`' do | ||
expect(expressed(:br)).to eq('(?:(?:\n)|(?:\r\n))') | ||
end | ||
end | ||
|
||
describe "#tab" do | ||
it 'returns `\t`' do | ||
expect(expressed(:tab)).to eq('\t') | ||
end | ||
end | ||
|
||
describe "#anyOf" do | ||
it 'returns `"(?:[f])"`' do | ||
expect(expressed(:anyOf, "f")).to eq('"(?:[f])"') | ||
end | ||
end | ||
|
||
describe "#range" do | ||
it 'to be decided by spec' | ||
end | ||
|
||
describe "#withAnyCase" do | ||
it 'case insensitive search' | ||
end | ||
|
||
describe "#stopAtFirst" do | ||
it 'match first expression' | ||
end | ||
|
||
describe "#searchOneLine" do | ||
it 'only look at one line' | ||
end | ||
|
||
describe "#multiple" do | ||
it 'match multiple lines' | ||
end | ||
|
||
describe "#or" do | ||
it 'uses `|` as delimiter for or statements' | ||
end | ||
|
||
describe "#begindCapture" do | ||
it 'begins a capture' | ||
end | ||
|
||
describe "#endCapture" do | ||
it 'ends a capture' | ||
end | ||
end |