parsecs 0.10.3 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libnativemath/extconf.rb +1 -1
- data/lib/parsec.rb +2 -2
- data/test/test_parsec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0521908edb1a931bc50d3f62042405b9d7820fa50cda37c4313b1320f9520b7a'
|
4
|
+
data.tar.gz: 5338f27f94d431e9ae26cf1eb8ff06455f52c2fb5c45c7fa49c565bcf6b2160f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 249b1aa99be74e1916d3d0395155b8539fd90df8e66f7317a265b13070f74c97bd1c2baacce331eb3137b051493d2181767b82e8abeaf7cd1080bdd6e3742f75
|
7
|
+
data.tar.gz: 8446a182b3f3876276d23d313b09e7a7e8b36eeb39dcc3a08ff1b05e6839d3fed84fb31f07880cadbb511fc37f87c087127b3f144e609591a2e93119411f00c2
|
@@ -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 = 'b011ace5697fa65eade579f1c85aa38fd1fb816d'.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.11.2'.freeze
|
10
10
|
|
11
11
|
# evaluates the equation and returns only the result
|
12
12
|
def self.eval_equation(equation)
|
@@ -65,7 +65,7 @@ module Parsec
|
|
65
65
|
when 'int' then return ans['value'].to_i
|
66
66
|
when 'float' then return ans['value'].to_f
|
67
67
|
when 'boolean' then return ans['value'].to_bool
|
68
|
-
when 'string' then return error_check(ans['value'])
|
68
|
+
when 'string' then return error_check(ans['value'].force_encoding(Encoding::UTF_8))
|
69
69
|
when 'complex' then return 'complex number' # Maybe future implementation
|
70
70
|
when 'matrix' then return 'matrix value' # Maybe future implementation
|
71
71
|
end
|
data/test/test_parsec.rb
CHANGED
@@ -70,6 +70,7 @@ class TestParsec < Minitest::Test
|
|
70
70
|
assert_equal(false, parser.eval_equation('contains("1234567", "789")'))
|
71
71
|
assert_equal(true, parser.eval_equation('contains("2019-01-01T:08:30", "2019-01-01")'))
|
72
72
|
assert_equal(false, parser.eval_equation('contains("2019-01-01T:08:30", "2021-01-01")'))
|
73
|
+
assert_equal('Maçã', parser.eval_equation('"Maçã"'))
|
73
74
|
assert_raises(SyntaxError) { parser.eval_equation('contains(1234567, "789")') }
|
74
75
|
assert_raises(SyntaxError) { parser.eval_equation('contains("hello", 2.2)') }
|
75
76
|
assert_raises(SyntaxError) { parser.eval_equation_with_type('link()') }
|
@@ -84,6 +85,7 @@ class TestParsec < Minitest::Test
|
|
84
85
|
assert_equal('test lowercase', parser.eval_equation('tolower("TEST LOWERCASE")'))
|
85
86
|
assert_equal('Hello', parser.eval_equation('left("Hello World", 5)'))
|
86
87
|
assert_equal('World', parser.eval_equation('right("Hello World", 5)'))
|
88
|
+
assert_equal('Hello World', parser.eval_equation('right("Hello World", 20)'))
|
87
89
|
end
|
88
90
|
|
89
91
|
def test_general_equations
|
@@ -272,4 +274,21 @@ class TestParsec < Minitest::Test
|
|
272
274
|
assert_raises(SyntaxError) { parsec.eval_equation_with_type('concat(1, 2)') }
|
273
275
|
assert_raises(SyntaxError) { parsec.eval_equation_with_type('4 > 2 ? "smaller"') }
|
274
276
|
end
|
277
|
+
|
278
|
+
def test_timediff
|
279
|
+
parsec = Parsec::Parsec
|
280
|
+
assert_equal(1.5, parsec.eval_equation('timediff("02:00:00", "03:30:00")'))
|
281
|
+
assert_equal(22.5, parsec.eval_equation('timediff("03:30:00", "02:00:00")'))
|
282
|
+
assert_equal(0.01, parsec.eval_equation('timediff("02:00:00", "02:00:30")'))
|
283
|
+
assert_equal(23.99, parsec.eval_equation('timediff("02:00:30", "02:00:00")'))
|
284
|
+
assert_equal(0.0, parsec.eval_equation('timediff("02:00:00", "02:00:00")'))
|
285
|
+
|
286
|
+
# error scenarios
|
287
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("02:00:30", "02/01/20")') }
|
288
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("02:00:30", "02/01/20T02:00:30")') }
|
289
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("02/01/20", "02:00:30")') }
|
290
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("02:00:30", "02:61:30")') }
|
291
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("02:00:00", "02:30:62")') }
|
292
|
+
assert_raises(SyntaxError) { parsec.eval_equation('timediff("24:00:00", "02:30:59")') }
|
293
|
+
end
|
275
294
|
end
|
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.11.2
|
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:
|
13
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|