Skip to content
This repository has been archived by the owner on Mar 4, 2018. It is now read-only.

Commit

Permalink
We wanted to have the ability to match the verbal expression spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurtis Rainbolt-Greene committed Aug 30, 2013
1 parent c53d524 commit 7440889
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/express/verbal_expressions.rb
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
112 changes: 112 additions & 0 deletions spec/lib/express/verbal_expressions_standard.rb
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

0 comments on commit 7440889

Please sign in to comment.