dentaku 3.3.1 → 3.3.2
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/CHANGELOG.md +6 -1
- data/lib/dentaku.rb +0 -2
- data/lib/dentaku/ast/negation.rb +3 -1
- data/lib/dentaku/calculator.rb +6 -1
- data/lib/dentaku/version.rb +1 -1
- data/spec/ast/addition_spec.rb +6 -0
- data/spec/ast/arithmetic_spec.rb +6 -0
- data/spec/ast/division_spec.rb +6 -0
- data/spec/ast/negation_spec.rb +32 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1166f2fd23824ca3950d6db37cbd48d0198e939311b69541d37a832ce4106904
|
|
4
|
+
data.tar.gz: 81452369184a17266465c58797ee4ff4643e7d47ab6762f4b38ac2a23cac6ad0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d576e283f2381a8bf270981e1451f0668fd321e34c8a47f868a578411c82d1567402fc8d7dd264feb32fc82c1b722b01a931b439854c826d229e140419cf2d9c
|
|
7
|
+
data.tar.gz: bf601b8bdd70be48c02b801e05769bd8ce988552458d85512ef3445c39419f98d08e92915e6cc310cb772eb5d9c0b3db51c8dfec3dbe3665aa3533151110fbd8
|
data/CHANGELOG.md
CHANGED
|
@@ -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.
|
|
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
|
data/lib/dentaku.rb
CHANGED
data/lib/dentaku/ast/negation.rb
CHANGED
|
@@ -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,
|
|
10
|
+
raise NodeError.new(:numeric, node.type, :node),
|
|
9
11
|
"#{self.class} requires numeric operands"
|
|
10
12
|
end
|
|
11
13
|
end
|
data/lib/dentaku/calculator.rb
CHANGED
|
@@ -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,
|
|
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
|
data/lib/dentaku/version.rb
CHANGED
data/spec/ast/addition_spec.rb
CHANGED
|
@@ -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)
|
data/spec/ast/arithmetic_spec.rb
CHANGED
|
@@ -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
|
data/spec/ast/division_spec.rb
CHANGED
|
@@ -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.
|
|
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-
|
|
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
|