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

Commit

Permalink
Adding sample test for Regexper
Browse files Browse the repository at this point in the history
  • Loading branch information
javallone committed Dec 25, 2012
1 parent f2685ed commit c40edad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
19 changes: 19 additions & 0 deletions lib/regexper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'treetop'
require 'regexper/modules'

module Regexper
base_path = File.expand_path(File.dirname(__FILE__))

Treetop.load(File.join(base_path, 'regexper_parser.treetop'))
@@parser = RegexperParser.new

def self.parse(data)
tree = @@parser.parse(data)

if tree.nil?
raise Exception, "Parse error: #{@@parser.failure_reason} line=#{@@parser.failure_line}, column=#{@@parser.failure_column}"
end

return tree
end
end
19 changes: 0 additions & 19 deletions parser.rb → lib/regexper/modules.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
require 'treetop'

module Regexper
base_path = File.expand_path(File.dirname(__FILE__))

Treetop.load(File.join(base_path, 'regexper_parser.treetop'))
@@parser = RegexperParser.new

def self.parse(data)
tree = @@parser.parse(data)

if tree.nil?
raise Exception, "Parse error: #{@@parser.failure_reason} line=#{@@parser.failure_line}, column=#{@@parser.failure_column}"
end

return tree
end
end

module Regexper
module Regexp
def content
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions spec/lib/regexper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'
require 'regexper'

describe Regexper do

describe ".parse" do

it "returns a parsed regular expression" do
Regexper.parse('test').should be_a(Treetop::Runtime::SyntaxNode)
end

end

end

0 comments on commit c40edad

Please sign in to comment.