diff --git a/ext/equations-parser b/ext/equations-parser index a210f5d..7428a00 160000 --- a/ext/equations-parser +++ b/ext/equations-parser @@ -1 +1 @@ -Subproject commit a210f5def5048ddd8e9095adeccfc27f39dd7811 +Subproject commit 7428a00a7e56f14afc9178de599e331bae71d17b diff --git a/ext/libnativemath/extconf.rb b/ext/libnativemath/extconf.rb index 97dba44..b0973e1 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 = 'a210f5def5048ddd8e9095adeccfc27f39dd7811'.freeze +COMMIT = '7428a00a7e56f14afc9178de599e331bae71d17b'.freeze Dir.chdir(BASEDIR) do system('git init') diff --git a/lib/parsec.rb b/lib/parsec.rb index 5df2643..41eb82f 100644 --- a/lib/parsec.rb +++ b/lib/parsec.rb @@ -6,7 +6,7 @@ module Parsec class Parsec using StringToBooleanRefinements - VERSION = '0.14.2'.freeze + VERSION = '0.15.0'.freeze # evaluates the equation and returns only the result def self.eval_equation(equation) diff --git a/parsec.gemspec b/parsec.gemspec index 4fea56e..5cafc8c 100644 --- a/parsec.gemspec +++ b/parsec.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'parsecs' - s.version = '0.14.2' + s.version = '0.15.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'] diff --git a/test/test_parsec.rb b/test/test_parsec.rb index 88cb816..3c337c5 100644 --- a/test/test_parsec.rb +++ b/test/test_parsec.rb @@ -391,4 +391,35 @@ def test_calculate assert_equal('One Two Three', parsec.eval_equation('calculate("\"One\" // \" \" // \"Two\" // \" \" // \"Three\"")')) assert_equal('3', parsec.eval_equation('calculate("number(calculate(\"1 + 1\")) + 1")')) end + + def test_weekday + parsec = Parsec::Parsec + assert_equal(0, parsec.eval_equation('weekday("2021-03-21")')) + assert_equal(1, parsec.eval_equation('weekday("2016-03-21")')) + assert_equal(2, parsec.eval_equation('weekday("2017-03-21")')) + assert_equal(3, parsec.eval_equation('weekday("2018-03-21")')) + assert_equal(4, parsec.eval_equation('weekday("2019-03-21")')) + + assert_equal(5, parsec.eval_equation('weekday("2014-03-21T21:03")')) + assert_equal(6, parsec.eval_equation('weekday("2015-03-21T21:03")')) + + assert_equal('Søndag', parsec.eval_equation('weekday("2021-03-21", "nb")')) + assert_equal('星期一', parsec.eval_equation('weekday("2016-03-21", "zh-CN")')) + assert_equal('Mardi', parsec.eval_equation('weekday("2017-03-21", "fr-FR")')) + assert_equal('วันพุธ', parsec.eval_equation('weekday("2018-03-21", "th-TH")')) + assert_equal('Quinta-feira', parsec.eval_equation('weekday("2019-03-21", "pt-BR")')) + + assert_raises(SyntaxError) { parsec.eval_equation('weekday("2019-03-21", "invalidlocale")') } + assert_raises(SyntaxError) { parsec.eval_equation('weekday("2024-32-21")') } + assert_raises(SyntaxError) { parsec.eval_equation('weekday("2024-09-17", "en", "one too many params")') } + end + + def test_current_time + parsec = Parsec::Parsec + assert_raises(SyntaxError) { parsec.eval_equation('current_time("1"))') } + assert_match(/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/, parsec.eval_equation('current_time(5)')) + assert_match(/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/, parsec.eval_equation('current_time()')) + assert_match(/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/, parsec.eval_equation('current_time(-3)')) + assert_match(/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/, parsec.eval_equation('current_time(-200)')) + end end