Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/equations-parser
2 changes: 1 addition & 1 deletion ext/libnativemath/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/parsec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion parsec.gemspec
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
31 changes: 31 additions & 0 deletions test/test_parsec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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