parsecs 0.7.0 → 0.8.0
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 +9 -7
- data/test/test_parsec.rb +20 -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: 794032417267277d5b12e9ef7d76b3bbcbc4e2590fa1230c1d4600388a74aa55
|
4
|
+
data.tar.gz: 7005495e663ef1656090b582bba5738cc2ccf8075bc182c672a5b87db6a034bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01edc288484e0c48e71afa19d9bca1a93e329f39c9af0d1efcba725e3783c9ba7c3d09bccd347f014f185460154b456d99dce2df7ec8caadbd89ec5e8a5e0b9d
|
7
|
+
data.tar.gz: db1b0a6a59331065e8d279d9be948164cc103ba8c29331f94143f109c6b72e018bc92ebd74cc492cf047a5aa51cce0c434b7600f8c062379cd061c6a62427a55
|
@@ -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 = 'eca316d8ad99d4f2e68539a1efd7524288817006'.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.8.0'.freeze
|
10
10
|
|
11
11
|
# evaluates the equation and returns only the result
|
12
12
|
def self.eval_equation(equation)
|
@@ -15,7 +15,7 @@ module Parsec
|
|
15
15
|
|
16
16
|
# evaluates the equation and returns the result and its data type
|
17
17
|
def self.eval_equation_with_type(equation)
|
18
|
-
sanitize(equation, true)
|
18
|
+
equation = sanitize(equation, true)
|
19
19
|
|
20
20
|
result = Libnativemath.native_eval(equation)
|
21
21
|
{ value: convert(result), type: result['type'].to_sym }
|
@@ -23,20 +23,20 @@ module Parsec
|
|
23
23
|
|
24
24
|
# returns true or raise an error
|
25
25
|
def self.validate_syntax!(equation)
|
26
|
-
sanitize(equation)
|
26
|
+
equation = sanitize(equation)
|
27
27
|
|
28
28
|
validate(Libnativemath.native_eval(equation), true)
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns true or an error string
|
32
32
|
def self.validate_syntax(equation)
|
33
|
-
sanitize(equation)
|
33
|
+
equation = sanitize(equation)
|
34
34
|
|
35
35
|
validate(Libnativemath.native_eval(equation), false)
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.get_result_type(equation)
|
39
|
-
sanitize(equation, true)
|
39
|
+
equation = sanitize(equation, true)
|
40
40
|
|
41
41
|
result = Libnativemath.native_eval(equation)
|
42
42
|
result['type'].to_sym if validate(result, true)
|
@@ -45,11 +45,13 @@ module Parsec
|
|
45
45
|
private_class_method
|
46
46
|
|
47
47
|
def self.sanitize(equation, new_line = false)
|
48
|
-
equation.gsub
|
48
|
+
equation = equation.gsub(/[\n\t\r]/, ' ')
|
49
49
|
|
50
50
|
# The following regex remove all spaces that are not between quot marks
|
51
51
|
# https://tinyurl.com/ybc7bng3
|
52
|
-
equation.gsub
|
52
|
+
equation = equation.gsub(/( |(".*?"))/, '\\2') if new_line == true
|
53
|
+
|
54
|
+
equation
|
53
55
|
end
|
54
56
|
|
55
57
|
def self.convert(ans)
|
data/test/test_parsec.rb
CHANGED
@@ -189,6 +189,26 @@ class TestParsec < Minitest::Test
|
|
189
189
|
assert_equal('1-1234-1234-1234-1234', parsec.eval_equation('mask("0-0000-0000-0000-0000", 11234123412341234)'))
|
190
190
|
end
|
191
191
|
|
192
|
+
def test_default_value
|
193
|
+
parsec = Parsec::Parsec
|
194
|
+
|
195
|
+
# Success Scenarios
|
196
|
+
assert_equal(10, parsec.eval_equation('default_value(10, 1)'))
|
197
|
+
assert_equal(1, parsec.eval_equation('default_value(NULL, 1)'))
|
198
|
+
assert_equal(10.4, parsec.eval_equation('default_value(10.4, 1.01)'))
|
199
|
+
assert_equal(1.01, parsec.eval_equation('default_value(NULL, 1.01)'))
|
200
|
+
assert_equal('filled', parsec.eval_equation('default_value("filled", "default")'))
|
201
|
+
assert_equal('default', parsec.eval_equation('default_value(NULL, "default")'))
|
202
|
+
assert_equal(false, parsec.eval_equation('default_value(false, true)'))
|
203
|
+
assert_equal(true, parsec.eval_equation('default_value(NULL, true)'))
|
204
|
+
|
205
|
+
# Error Scenarios
|
206
|
+
assert_raises(SyntaxError) { parsec.eval_equation('default_value(1, 4.5)') }
|
207
|
+
assert_raises(SyntaxError) { parsec.eval_equation('default_value(4.5, "string")') }
|
208
|
+
assert_raises(SyntaxError) { parsec.eval_equation('default_value("string", true)') }
|
209
|
+
assert_raises(SyntaxError) { parsec.eval_equation('default_value(true, 1)') }
|
210
|
+
end
|
211
|
+
|
192
212
|
def test_eval_equation_with_type
|
193
213
|
parsec = Parsec::Parsec
|
194
214
|
assert_equal({ value: 10, type: :int }, parsec.eval_equation_with_type('(5 + 1) + (6 - 2)'))
|
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.8.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:
|
13
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|