Skip to content

Instantly share code, notes, and snippets.

@avit
Created April 28, 2018 23:47
Show Gist options
  • Save avit/d4235c646082983fbc64c8b3cd5c72a7 to your computer and use it in GitHub Desktop.
Save avit/d4235c646082983fbc64c8b3cd5c72a7 to your computer and use it in GitHub Desktop.
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