Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing javascript regular expressions using a ruby test suite
require 'therubyracer'
js = V8::Context.new
matches = (<<-___).split("\n---\n")
123
---
abc
___
pattern = DATA.reduce("") { |str, line|
str << line.partition('#')[0].strip
}
puts "Testing: /#{pattern}/", "---"
matches.each do |match|
puts match, js.eval(<<-___)
/#{pattern}/.test(#{match.inspect});
___
end
__END__
\d+ # example expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment