dentaku 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b760fc43a6d5745ea9c95827fb0ce03e8fef8453c2264ee1073e5754c2b8d402
4
- data.tar.gz: 04e03adf0729e170babe62c8f91cc88ca8aa46932dacb694ccfc564696eed765
3
+ metadata.gz: 1166f2fd23824ca3950d6db37cbd48d0198e939311b69541d37a832ce4106904
4
+ data.tar.gz: 81452369184a17266465c58797ee4ff4643e7d47ab6762f4b38ac2a23cac6ad0
5
5
  SHA512:
6
- metadata.gz: 006ec24c2c61758a1b7f5921e181ed49e2d54bf479091f9600ed31019fedd0a9411d744932e7dbf973b2e8fea098ff7299e58fd97851e5b2382a81e05043f8e4
7
- data.tar.gz: 7f9d3735fc20e918d808158e8c618e11a0021762f102d9d5b32eec7d24f6a28845c01912fbc63c4cb835438f7f8d6d494fe811a5b01e373a5a6296a087c4edda
6
+ metadata.gz: d576e283f2381a8bf270981e1451f0668fd321e34c8a47f868a578411c82d1567402fc8d7dd264feb32fc82c1b722b01a931b439854c826d229e140419cf2d9c
7
+ data.tar.gz: bf601b8bdd70be48c02b801e05769bd8ce988552458d85512ef3445c39419f98d08e92915e6cc310cb772eb5d9c0b3db51c8dfec3dbe3665aa3533151110fbd8
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## [v3.3.2] 2019-06-10
4
+ - add ability to pre-load AST cache
5
+ - fix negation node bug
6
+
3
7
  ## [v3.3.1] 2019-03-26
4
8
  - better errors for parse failures and exceptions in internal functions
5
9
  - fix Ruby 2.6.0 deprecation warnings
@@ -171,7 +175,8 @@
171
175
  ## [v0.1.0] 2012-01-20
172
176
  - initial release
173
177
 
174
- [HEAD]: https://github.com/rubysolo/dentaku/compare/v3.3.1...HEAD
178
+ [HEAD]: https://github.com/rubysolo/dentaku/compare/v3.3.2...HEAD
179
+ [v3.3.2]: https://github.com/rubysolo/dentaku/compare/v3.3.1...v3.3.2
175
180
  [v3.3.1]: https://github.com/rubysolo/dentaku/compare/v3.3.0...v3.3.1
176
181
  [v3.3.0]: https://github.com/rubysolo/dentaku/compare/v3.2.1...v3.3.0
177
182
  [v3.2.1]: https://github.com/rubysolo/dentaku/compare/v3.2.0...v3.2.1
@@ -44,8 +44,6 @@ module Dentaku
44
44
  @aliases = hash
45
45
  end
46
46
 
47
- private
48
-
49
47
  def self.calculator
50
48
  @calculator ||= Dentaku::Calculator.new
51
49
  end
@@ -1,11 +1,13 @@
1
1
  module Dentaku
2
2
  module AST
3
3
  class Negation < Arithmetic
4
+ attr_reader :node
5
+
4
6
  def initialize(node)
5
7
  @node = node
6
8
 
7
9
  unless valid_node?(node)
8
- raise NodeError.new(:numeric, left.type, :left),
10
+ raise NodeError.new(:numeric, node.type, :node),
9
11
  "#{self.class} requires numeric operands"
10
12
  end
11
13
  end
@@ -9,7 +9,8 @@ require 'dentaku/token'
9
9
  module Dentaku
10
10
  class Calculator
11
11
  include StringCasing
12
- attr_reader :result, :memory, :tokenizer, :case_sensitive, :aliases, :nested_data_support
12
+ attr_reader :result, :memory, :tokenizer, :case_sensitive, :aliases,
13
+ :nested_data_support, :ast_cache
13
14
 
14
15
  def initialize(options = {})
15
16
  clear
@@ -97,6 +98,10 @@ module Dentaku
97
98
  }
98
99
  end
99
100
 
101
+ def load_cache(ast_cache)
102
+ @ast_cache = ast_cache
103
+ end
104
+
100
105
  def clear_cache(pattern = :all)
101
106
  case pattern
102
107
  when :all
@@ -1,3 +1,3 @@
1
1
  module Dentaku
2
- VERSION = "3.3.1"
2
+ VERSION = "3.3.2"
3
3
  end
@@ -9,6 +9,12 @@ describe Dentaku::AST::Addition do
9
9
 
10
10
  let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) }
11
11
 
12
+ it 'allows access to its sub-trees' do
13
+ node = described_class.new(five, six)
14
+ expect(node.left).to eq(five)
15
+ expect(node.right).to eq(six)
16
+ end
17
+
12
18
  it 'performs addition' do
13
19
  node = described_class.new(five, six)
14
20
  expect(node.value).to eq(11)
@@ -15,6 +15,7 @@ describe Dentaku::AST::Arithmetic do
15
15
  expect(sub(one, two)).to eq(-1)
16
16
  expect(mul(one, two)).to eq(2)
17
17
  expect(div(one, two)).to eq(0.5)
18
+ expect(neg(one)).to eq(-1)
18
19
  end
19
20
 
20
21
  it 'performs an arithmetic operation with one numeric operand and one string operand' do
@@ -34,6 +35,7 @@ describe Dentaku::AST::Arithmetic do
34
35
  expect(sub(x, y)).to eq(-1)
35
36
  expect(mul(x, y)).to eq(2)
36
37
  expect(div(x, y)).to eq(0.5)
38
+ expect(neg(x)).to eq(-1)
37
39
  end
38
40
 
39
41
  private
@@ -53,4 +55,8 @@ describe Dentaku::AST::Arithmetic do
53
55
  def div(left, right)
54
56
  Dentaku::AST::Division.new(left, right).value(ctx)
55
57
  end
58
+
59
+ def neg(node)
60
+ Dentaku::AST::Negation.new(node).value(ctx)
61
+ end
56
62
  end
@@ -9,6 +9,12 @@ describe Dentaku::AST::Division do
9
9
 
10
10
  let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) }
11
11
 
12
+ it 'allows access to its sub-trees' do
13
+ node = described_class.new(five, six)
14
+ expect(node.left).to eq(five)
15
+ expect(node.right).to eq(six)
16
+ end
17
+
12
18
  it 'performs division' do
13
19
  node = described_class.new(five, six)
14
20
  expect(node.value.round(4)).to eq(0.8333)
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'dentaku/ast/arithmetic'
3
+
4
+ require 'dentaku/token'
5
+
6
+ describe Dentaku::AST::Negation do
7
+ let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) }
8
+ let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) }
9
+
10
+ it 'allows access to its sub-node' do
11
+ node = described_class.new(five)
12
+ expect(node.node).to eq(five)
13
+ end
14
+
15
+ it 'performs negation' do
16
+ node = described_class.new(five)
17
+ expect(node.value).to eq(-5)
18
+ end
19
+
20
+ it 'requires numeric operands' do
21
+ expect {
22
+ described_class.new(t)
23
+ }.to raise_error(Dentaku::NodeError, /requires numeric operands/)
24
+
25
+ expression = Dentaku::AST::Negation.new(five)
26
+ group = Dentaku::AST::Grouping.new(expression)
27
+
28
+ expect {
29
+ described_class.new(group)
30
+ }.not_to raise_error
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dentaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solomon White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-26 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -208,6 +208,7 @@ files:
208
208
  - spec/ast/max_spec.rb
209
209
  - spec/ast/min_spec.rb
210
210
  - spec/ast/mul_spec.rb
211
+ - spec/ast/negation_spec.rb
211
212
  - spec/ast/node_spec.rb
212
213
  - spec/ast/numeric_spec.rb
213
214
  - spec/ast/or_spec.rb
@@ -267,6 +268,7 @@ test_files:
267
268
  - spec/ast/max_spec.rb
268
269
  - spec/ast/min_spec.rb
269
270
  - spec/ast/mul_spec.rb
271
+ - spec/ast/negation_spec.rb
270
272
  - spec/ast/node_spec.rb
271
273
  - spec/ast/numeric_spec.rb
272
274
  - spec/ast/or_spec.rb