From 59ba3a78037a6085f18a3c7ffcfa01342f79e13f Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Seifert Date: Thu, 5 Dec 2024 15:56:41 -0300 Subject: [PATCH 1/2] Update equations-parser and gem version --- ext/equations-parser | 2 +- ext/libnativemath/extconf.rb | 2 +- lib/parsec.rb | 2 +- parsec.gemspec | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/equations-parser b/ext/equations-parser index 39d949b..39ba4c4 160000 --- a/ext/equations-parser +++ b/ext/equations-parser @@ -1 +1 @@ -Subproject commit 39d949b5f53d1650eb8f166db3883900f5ce55d4 +Subproject commit 39ba4c44c14df83b8dd5ea98e69d1607f9b07f6f diff --git a/ext/libnativemath/extconf.rb b/ext/libnativemath/extconf.rb index 36e2881..bda0b01 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 = '39d949b5f53d1650eb8f166db3883900f5ce55d4'.freeze +COMMIT = '39ba4c44c14df83b8dd5ea98e69d1607f9b07f6f'.freeze Dir.chdir(BASEDIR) do system('git init') diff --git a/lib/parsec.rb b/lib/parsec.rb index 78cfae0..41eb82f 100644 --- a/lib/parsec.rb +++ b/lib/parsec.rb @@ -6,7 +6,7 @@ module Parsec class Parsec using StringToBooleanRefinements - VERSION = '0.14.0'.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 4dcacf7..5cafc8c 100644 --- a/parsec.gemspec +++ b/parsec.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'parsecs' - s.version = '0.14.0' + 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'] From becdc8133d8f71832d43237359cdfcd457805efe Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Seifert Date: Thu, 5 Dec 2024 15:56:52 -0300 Subject: [PATCH 2/2] Add tests --- test/test_parsec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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