diff --git a/ext/equations-parser b/ext/equations-parser index 8c4fab5..8769175 160000 --- a/ext/equations-parser +++ b/ext/equations-parser @@ -1 +1 @@ -Subproject commit 8c4fab5b8949704cf4d80d4a4a898f451cbb3890 +Subproject commit 8769175390cafd9c40b52477f1c97184266c4a68 diff --git a/ext/libnativemath/extconf.rb b/ext/libnativemath/extconf.rb index 1164664..d5d11a5 100644 --- a/ext/libnativemath/extconf.rb +++ b/ext/libnativemath/extconf.rb @@ -38,7 +38,7 @@ end GIT_REPOSITORY = 'https://github.com/oxeanbits/equations-parser.git'.freeze -COMMIT = '8c4fab5b8949704cf4d80d4a4a898f451cbb3890'.freeze +COMMIT = '8769175390cafd9c40b52477f1c97184266c4a68'.freeze Dir.chdir(BASEDIR) do system('git init') diff --git a/parsec.gemspec b/parsec.gemspec index a411a76..7052f8e 100644 --- a/parsec.gemspec +++ b/parsec.gemspec @@ -1,11 +1,11 @@ Gem::Specification.new do |s| s.name = 'parsecs' - s.version = '0.11.9' + s.version = '0.12.0' s.platform = Gem::Platform::RUBY s.authors = ['Nilton Vasques', 'Victor Cordeiro', 'Beatriz Fagundes'] s.email = ['nilton.vasques@gmail.com', 'victorcorcos@gmail.com', 'beatrizsfslima@gmail.com'] - s.description = 'ParseCs is a gem to evaluate equations using a lighter and extented version of the muparserx C++ library' - s.homepage = 'https://github.com/niltonvasques/parsec' + s.description = 'Parsecs is a gem to evaluate equations using a lighter and extented version of the muparserx C++ library' + s.homepage = 'https://github.com/oxeanbits/parsec' s.summary = 'A gem to evaluate equations using muparserx C++ library' s.files = ['lib/parsec.rb', 'lib/string_to_boolean_refinements.rb', 'ext/libnativemath/libnativemath.i', 'ext/libnativemath/libnativemath.cpp', 'ext/libnativemath/libnativemath.h'] diff --git a/test/test_parsec.rb b/test/test_parsec.rb index bedca51..5f4e97d 100644 --- a/test/test_parsec.rb +++ b/test/test_parsec.rb @@ -302,4 +302,40 @@ def test_timediff assert_raises(SyntaxError) { parsec.eval_equation('timediff("02:00:00", "02:30:62")') } assert_raises(SyntaxError) { parsec.eval_equation('timediff("24:00:00", "02:30:59")') } end + + def test_regex + parsec = Parsec::Parsec + assert_equal('World', parsec.eval_equation('regex("Hello World", "Hello (.*)")')) + assert_equal('71', parsec.eval_equation('regex("71 123456789", "([0-9]{2}) [0-9]{9}")')) + assert_equal('ISSUE-123', parsec.eval_equation('regex("ISSUE-123 Fix bug", "(ISSUE-[0-9]+) (.*)")')) + assert_equal('2019-01-01', parsec.eval_equation('regex("2019-01-01T:08:30", "([0-9]{4}-[0-9]{2}-[0-9]{2})T:[0-9]{2}:[0-9]{2}")')) + assert_equal('2019-01', parsec.eval_equation('regex("2019-01-01T:08:30", "([0-9]{4}-[0-9]{2})-[0-9]{2}T:[0-9]{2}:[0-9]{2}")')) + assert_equal('2019', parsec.eval_equation('regex("2019-01-01T:08:30", "([0-9]{4})-[0-9]{2}-[0-9]{2}T:[0-9]{2}:[0-9]{2}")')) + # Regex tests with no capture group + assert_equal('', parsec.eval_equation('regex("Hello World", "Hello .*")')) + + # Regex tests with optional groups + assert_equal('1234', parsec.eval_equation('regex("Product 1234 (color: red)", "Product ([0-9]+)( \\\\(color: (.*)\\\\))?")')) + assert_equal('1234', parsec.eval_equation('regex("Product 1234", "Product ([0-9]+)( \\\\(color: (.*)\\\\))?")')) + + # Regex tests with alternation + assert_equal('Green', parsec.eval_equation('regex("Green Apple", "(Green|Red) Apple")')) + assert_equal('Red', parsec.eval_equation('regex("Red Apple", "(Green|Red) Apple")')) + + # Regex tests with character classes + assert_equal('A123', parsec.eval_equation('regex("BoxA123", "Box([A-Za-z][0-9]+)")')) + assert_equal('C456', parsec.eval_equation('regex("BoxC456", "Box([A-Za-z][0-9]+)")')) + + # Regex tests with positive lookaheads + assert_equal('apple', parsec.eval_equation('regex("apple123banana", "([a-z]+)(?=\\\\d+)")')) + + assert_equal('456', parsec.eval_equation('regex("123red456blue", "(\\\\d+)(?=blue)")')) + + # Regex tests with negative lookaheads + assert_equal('123', parsec.eval_equation('regex("123red456blue", "(\\\\d+)(?!blue)")')) + + # Regex tests with nested lookaheads + assert_equal('apple', parsec.eval_equation('regex("apple123redbanana", "(?=apple)([a-z]+)(?=\\\\d+red)")')) + assert_equal('apple', parsec.eval_equation('regex("apple123red456banana", "(?=apple)([a-z]+)(?=(\\\\d+red)\\\\d+banana)")')) + end end