parsecs 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32cb384a1378a217a7be582ca5ea2de6f3dc70c94689dee52f87f8b0d29977f6
4
- data.tar.gz: f22282eaf3ded82725e7eeb4f8ea481e81d27b3860bbf9c57670ce904df70afe
3
+ metadata.gz: 794032417267277d5b12e9ef7d76b3bbcbc4e2590fa1230c1d4600388a74aa55
4
+ data.tar.gz: 7005495e663ef1656090b582bba5738cc2ccf8075bc182c672a5b87db6a034bd
5
5
  SHA512:
6
- metadata.gz: 203c5968bda180a314200b84c63b60401190334085580ccb6b908b78c82e7662c6fc857a88d8044b9455b04f880527f6c977f8a64233135c296f16af32c948bb
7
- data.tar.gz: 552b910f8122d3b8de370b15a8921304658020d6fd429e007ebe1ef5dac23137775cc467e14ff2d5cebf22216d01f5f2918873935655aaadf7f01c42a61d738b
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 = '111de602d62b77b4c90ee8d834d7ca64355057de'.freeze
41
+ COMMIT = 'eca316d8ad99d4f2e68539a1efd7524288817006'.freeze
42
42
 
43
43
  Dir.chdir(BASEDIR) do
44
44
  system('git init')
@@ -6,7 +6,7 @@ module Parsec
6
6
  class Parsec
7
7
  using StringToBooleanRefinements
8
8
 
9
- VERSION = '0.7.0'.freeze
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!(/[\n\t\r]/, ' ')
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!(/( |(".*?"))/, '\\2') if new_line == true
52
+ equation = equation.gsub(/( |(".*?"))/, '\\2') if new_line == true
53
+
54
+ equation
53
55
  end
54
56
 
55
57
  def self.convert(ans)
@@ -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.7.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: 2019-04-25 00:00:00.000000000 Z
13
+ date: 2020-06-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest