parsecs 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/libnativemath/extconf.rb +1 -1
- data/lib/parsec.rb +2 -2
- data/test/test_parsec.rb +42 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32cb384a1378a217a7be582ca5ea2de6f3dc70c94689dee52f87f8b0d29977f6
|
4
|
+
data.tar.gz: f22282eaf3ded82725e7eeb4f8ea481e81d27b3860bbf9c57670ce904df70afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203c5968bda180a314200b84c63b60401190334085580ccb6b908b78c82e7662c6fc857a88d8044b9455b04f880527f6c977f8a64233135c296f16af32c948bb
|
7
|
+
data.tar.gz: 552b910f8122d3b8de370b15a8921304658020d6fd429e007ebe1ef5dac23137775cc467e14ff2d5cebf22216d01f5f2918873935655aaadf7f01c42a61d738b
|
@@ -38,7 +38,7 @@ libs.each do |lib|
|
|
38
38
|
end
|
39
39
|
|
40
40
|
GIT_REPOSITORY = 'https://github.com/niltonvasques/equations-parser.git'.freeze
|
41
|
-
COMMIT = '
|
41
|
+
COMMIT = '111de602d62b77b4c90ee8d834d7ca64355057de'.freeze
|
42
42
|
|
43
43
|
Dir.chdir(BASEDIR) do
|
44
44
|
system('git init')
|
data/lib/parsec.rb
CHANGED
@@ -6,7 +6,7 @@ module Parsec
|
|
6
6
|
class Parsec
|
7
7
|
using StringToBooleanRefinements
|
8
8
|
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.7.0'.freeze
|
10
10
|
|
11
11
|
# evaluates the equation and returns only the result
|
12
12
|
def self.eval_equation(equation)
|
@@ -56,7 +56,7 @@ module Parsec
|
|
56
56
|
case ans['value']
|
57
57
|
when 'inf' then return 'Infinity'
|
58
58
|
when '-inf' then return '-Infinity'
|
59
|
-
when 'nan' then return
|
59
|
+
when 'nan', '-nan' then return 'nan'
|
60
60
|
end
|
61
61
|
|
62
62
|
case ans['type']
|
data/test/test_parsec.rb
CHANGED
@@ -115,8 +115,8 @@ class TestParsec < Minitest::Test
|
|
115
115
|
|
116
116
|
def test_date_functions
|
117
117
|
parsec = Parsec::Parsec
|
118
|
-
assert_equal(Date.today, Date.parse(parsec.eval_equation(
|
119
|
-
assert_match(/^\d{4}-\d{2}-\d{2}$/, parsec.eval_equation(
|
118
|
+
assert_equal(Date.today, Date.parse(parsec.eval_equation('current_date()')))
|
119
|
+
assert_match(/^\d{4}-\d{2}-\d{2}$/, parsec.eval_equation('current_date()'))
|
120
120
|
assert_equal(364, parsec.eval_equation('daysdiff("2018-01-01", "2018-12-31")'))
|
121
121
|
assert_equal(365, parsec.eval_equation('daysdiff("2016-01-01", "2016-12-31")'))
|
122
122
|
assert_equal(365, parsec.eval_equation('daysdiff("2000-01-01", "2000-12-31")'))
|
@@ -151,6 +151,44 @@ class TestParsec < Minitest::Test
|
|
151
151
|
assert_raises(SyntaxError) { parsec.eval_equation('hoursdiff(current_date(), "2010-01-01T08:30")') }
|
152
152
|
end
|
153
153
|
|
154
|
+
def test_add_days
|
155
|
+
parsec = Parsec::Parsec
|
156
|
+
|
157
|
+
# With Dates
|
158
|
+
assert_equal('2019-01-01', parsec.eval_equation('add_days("2019-01-01", 0)'))
|
159
|
+
assert_equal('2019-01-02', parsec.eval_equation('add_days("2019-01-01", 1)'))
|
160
|
+
assert_equal('2018-12-31', parsec.eval_equation('add_days("2019-01-01", -1)'))
|
161
|
+
assert_equal('2019-01-04', parsec.eval_equation('add_days("2019-01-01", 3)'))
|
162
|
+
|
163
|
+
# # With DateTimes
|
164
|
+
assert_equal('2019-01-01T08:30', parsec.eval_equation('add_days("2019-01-01T08:30", 0)'))
|
165
|
+
assert_equal('2019-02-01T12:30', parsec.eval_equation('add_days("2019-01-01T12:30", 31)'))
|
166
|
+
assert_equal('2019-01-02T15:30', parsec.eval_equation('add_days("2019-01-01T15:30", 1)'))
|
167
|
+
assert_equal('2019-01-02T20:30', parsec.eval_equation('add_days("2019-01-01T08:30", 1.5)'))
|
168
|
+
assert_equal('2018-12-31T08:30', parsec.eval_equation('add_days("2019-01-01T08:30", -1)'))
|
169
|
+
|
170
|
+
# With Errors
|
171
|
+
assert_raises(SyntaxError) { parsec.eval_equation_with_type('add_days("2019-01-33", 0)') }
|
172
|
+
# assert_raises(SyntaxError) { parsec.eval_equation_with_type('add_days("2019-01-01T08:61", 0)') } # Dont work on Linux
|
173
|
+
assert_raises(SyntaxError) { parsec.eval_equation_with_type('add_days()') }
|
174
|
+
assert_raises(SyntaxError) { parsec.eval_equation_with_type('add_days(1, 2, 3)') }
|
175
|
+
assert_raises(SyntaxError) { parsec.eval_equation_with_type('add_days(1, 2)') }
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_mask
|
179
|
+
parsec = Parsec::Parsec
|
180
|
+
assert_equal('123-456', parsec.eval_equation('mask("000-000", 123456)'))
|
181
|
+
assert_equal('00014', parsec.eval_equation('mask("00000", 14)'))
|
182
|
+
assert_equal('000 14', parsec.eval_equation('mask("000 00", 14)'))
|
183
|
+
assert_equal('#123', parsec.eval_equation('concat("#", mask("000", 123))'))
|
184
|
+
assert_equal('12345', parsec.eval_equation('mask("0000", 12345)'))
|
185
|
+
assert_equal('123 45', parsec.eval_equation('mask("00 00", 12345)'))
|
186
|
+
assert_equal('3-5591-1801', parsec.eval_equation('mask("0-0000-0000", 355911801)'))
|
187
|
+
assert_equal('35-5591-1801', parsec.eval_equation('mask("00-0000-0000", 3555911801)'))
|
188
|
+
assert_equal('12-1234-1234-1234', parsec.eval_equation('mask("00-0000-0000-0000", 12123412341234)'))
|
189
|
+
assert_equal('1-1234-1234-1234-1234', parsec.eval_equation('mask("0-0000-0000-0000-0000", 11234123412341234)'))
|
190
|
+
end
|
191
|
+
|
154
192
|
def test_eval_equation_with_type
|
155
193
|
parsec = Parsec::Parsec
|
156
194
|
assert_equal({ value: 10, type: :int }, parsec.eval_equation_with_type('(5 + 1) + (6 - 2)'))
|
@@ -160,8 +198,8 @@ class TestParsec < Minitest::Test
|
|
160
198
|
assert_equal({ value: 40.6853, type: :float }, parsec.eval_equation_with_type('10^log(3+2)'))
|
161
199
|
assert_equal({ value: 5.1, type: :float }, parsec.eval_equation_with_type('number("5.1")'))
|
162
200
|
equation_if = '4 > 2 ? "bigger" : "smaller"'
|
163
|
-
assert_equal({ value:
|
164
|
-
assert_equal({ value:
|
201
|
+
assert_equal({ value: 'bigger', type: :string }, parsec.eval_equation_with_type(equation_if))
|
202
|
+
assert_equal({ value: '5.123', type: :string }, parsec.eval_equation_with_type('string(5.123)'))
|
165
203
|
equation_boolean = '2 == 2 ? true : false'
|
166
204
|
assert_equal({ value: true, type: :boolean }, parsec.eval_equation_with_type(equation_boolean))
|
167
205
|
equation_boolean = '(3==3) and (3!=3)'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsecs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-04-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -82,7 +82,7 @@ requirements:
|
|
82
82
|
- swig
|
83
83
|
- cmake
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.7.
|
85
|
+
rubygems_version: 2.7.9
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: A gem to evaluate equations using muparserx C++ library
|