factbase 0.0.60 → 0.1.1

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: ebfb3fe82bdf543291f6fd7630c2b69deb3949e6788b79d85c5d58ea733240b3
4
- data.tar.gz: 38d05a0630a444f8a77e67b96a3f90aa213ec5f47b764c25401fd90320449ae7
3
+ metadata.gz: 48e3aa4baba1a3e241c30002133a56627b43e9ef5ce903c46fbafe2873a8625f
4
+ data.tar.gz: f6fe14cbed445d1bd07e743f4b29f4eca2b65c3b46438a73c4654644626f8ae3
5
5
  SHA512:
6
- metadata.gz: 29f84d7e12a5cd5b4260590cc40f0a74afa500bec5aaad9f8f3e2c0673fc7864ef9a7c7ac30d08bd5015c3fb87f23cf7123b2ae54306ba58d15c0d0d834f350c
7
- data.tar.gz: 1aab5b40d3f47148377d302284af4bed085580bafb4de9acc7b3b9c602e502bdfd3814063095c33f80f63439fe213d190aa9067c55e93c00662f1c3556aa8287
6
+ metadata.gz: 0b9900e9aefabc39c5a84af552c34011fa54cffaa9828f3eb84aa677ec2f006ee6a32028cb74be5d04a65a7e68e7d516f072d7b78dd89aa91a04168c67fdd561
7
+ data.tar.gz: 915d162e0b9ff8f533ef3f34f9b39cca0593fd1823a14918acb99f0f1f9d88aaf08016d85d5fdfd892410ebe701392a16322f8c4dc8cb16fc93e064287b29d01
@@ -27,4 +27,4 @@ jobs:
27
27
  runs-on: ubuntu-22.04
28
28
  steps:
29
29
  - uses: actions/checkout@v4
30
- - uses: yegor256/copyrights-action@0.0.4
30
+ - uses: yegor256/copyrights-action@0.0.5
data/Gemfile CHANGED
@@ -24,11 +24,12 @@ source 'https://rubygems.org'
24
24
  gemspec
25
25
 
26
26
  gem 'minitest', '5.24.1', require: false
27
+ gem 'minitest-reporters', '1.7.1', require: false
27
28
  gem 'rake', '13.2.1', require: false
28
29
  gem 'rspec-rails', '6.1.3', require: false
29
- gem 'rubocop', '1.64.1', require: false
30
+ gem 'rubocop', '1.65.0', require: false
30
31
  gem 'rubocop-performance', '1.21.1', require: false
31
- gem 'rubocop-rspec', '3.0.1', require: false
32
+ gem 'rubocop-rspec', '3.0.3', require: false
32
33
  gem 'simplecov', '0.22.0', require: false
33
34
  gem 'simplecov-cobertura', '2.1.0', require: false
34
35
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -40,6 +40,7 @@ GEM
40
40
  minitest (>= 5.1)
41
41
  mutex_m
42
42
  tzinfo (~> 2.0)
43
+ ansi (1.5.0)
43
44
  ast (2.4.2)
44
45
  backtrace (0.4.0)
45
46
  base64 (0.2.0)
@@ -56,7 +57,7 @@ GEM
56
57
  i18n (1.14.5)
57
58
  concurrent-ruby (~> 1.0)
58
59
  io-console (0.7.2)
59
- irb (1.13.2)
60
+ irb (1.14.0)
60
61
  rdoc (>= 4.0.0)
61
62
  reline (>= 0.4.2)
62
63
  json (2.7.2)
@@ -66,6 +67,11 @@ GEM
66
67
  nokogiri (>= 1.12.0)
67
68
  loog (0.5.2)
68
69
  minitest (5.24.1)
70
+ minitest-reporters (1.7.1)
71
+ ansi
72
+ builder
73
+ minitest (>= 5.0)
74
+ ruby-progressbar
69
75
  mutex_m (0.2.0)
70
76
  nokogiri (1.16.6-arm64-darwin)
71
77
  racc (~> 1.4)
@@ -77,13 +83,13 @@ GEM
77
83
  racc (~> 1.4)
78
84
  others (0.0.3)
79
85
  parallel (1.25.1)
80
- parser (3.3.3.0)
86
+ parser (3.3.4.0)
81
87
  ast (~> 2.4.1)
82
88
  racc
83
89
  psych (5.1.2)
84
90
  stringio
85
91
  racc (1.8.0)
86
- rack (3.1.4)
92
+ rack (3.1.7)
87
93
  rack-session (2.0.0)
88
94
  rack (>= 3.0.0)
89
95
  rack-test (2.1.0)
@@ -113,7 +119,7 @@ GEM
113
119
  regexp_parser (2.9.2)
114
120
  reline (0.5.9)
115
121
  io-console (~> 0.5)
116
- rexml (3.3.1)
122
+ rexml (3.3.2)
117
123
  strscan
118
124
  rspec-core (3.13.0)
119
125
  rspec-support (~> 3.13.0)
@@ -132,13 +138,13 @@ GEM
132
138
  rspec-mocks (~> 3.13)
133
139
  rspec-support (~> 3.13)
134
140
  rspec-support (3.13.1)
135
- rubocop (1.64.1)
141
+ rubocop (1.65.0)
136
142
  json (~> 2.3)
137
143
  language_server-protocol (>= 3.17.0)
138
144
  parallel (~> 1.10)
139
145
  parser (>= 3.3.0.2)
140
146
  rainbow (>= 2.2.2, < 4.0)
141
- regexp_parser (>= 1.8, < 3.0)
147
+ regexp_parser (>= 2.4, < 3.0)
142
148
  rexml (>= 3.2.5, < 4.0)
143
149
  rubocop-ast (>= 1.31.1, < 2.0)
144
150
  ruby-progressbar (~> 1.7)
@@ -148,7 +154,7 @@ GEM
148
154
  rubocop-performance (1.21.1)
149
155
  rubocop (>= 1.48.1, < 2.0)
150
156
  rubocop-ast (>= 1.31.1, < 2.0)
151
- rubocop-rspec (3.0.1)
157
+ rubocop-rspec (3.0.3)
152
158
  rubocop (~> 1.61)
153
159
  ruby-progressbar (1.13.0)
154
160
  simplecov (0.22.0)
@@ -181,11 +187,12 @@ PLATFORMS
181
187
  DEPENDENCIES
182
188
  factbase!
183
189
  minitest (= 5.24.1)
190
+ minitest-reporters (= 1.7.1)
184
191
  rake (= 13.2.1)
185
192
  rspec-rails (= 6.1.3)
186
- rubocop (= 1.64.1)
193
+ rubocop (= 1.65.0)
187
194
  rubocop-performance (= 1.21.1)
188
- rubocop-rspec (= 3.0.1)
195
+ rubocop-rspec (= 3.0.3)
189
196
  simplecov (= 0.22.0)
190
197
  simplecov-cobertura (= 2.1.0)
191
198
  yard (= 0.9.36)
data/factbase.gemspec CHANGED
@@ -42,13 +42,13 @@ Gem::Specification.new do |s|
42
42
  s.files = `git ls-files`.split($RS)
43
43
  s.rdoc_options = ['--charset=UTF-8']
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
- s.add_runtime_dependency 'backtrace', '~>0.3'
46
- s.add_runtime_dependency 'decoor', '~>0.0'
47
- s.add_runtime_dependency 'json', '~>2.7'
48
- s.add_runtime_dependency 'loog', '~>0.2'
49
- s.add_runtime_dependency 'nokogiri', '~>1.10'
50
- s.add_runtime_dependency 'others', '~>0.0'
51
- s.add_runtime_dependency 'tago', '~>0.0'
52
- s.add_runtime_dependency 'yaml', '~>0.3'
45
+ s.add_dependency 'backtrace', '~>0.3'
46
+ s.add_dependency 'decoor', '~>0.0'
47
+ s.add_dependency 'json', '~>2.7'
48
+ s.add_dependency 'loog', '~>0.2'
49
+ s.add_dependency 'nokogiri', '~>1.10'
50
+ s.add_dependency 'others', '~>0.0'
51
+ s.add_dependency 'tago', '~>0.0'
52
+ s.add_dependency 'yaml', '~>0.3'
53
53
  s.metadata['rubygems_mfa_required'] = 'true'
54
54
  end
@@ -29,20 +29,37 @@ require_relative 'term'
29
29
  #
30
30
  # This is an internal class, it is not supposed to be instantiated directly.
31
31
  #
32
+ # However, you can use it directly, if you need a parser of our syntax. You can
33
+ # create your own "Term" class and let this parser make instances of it for
34
+ # every term it meets in the query:
35
+ #
36
+ # require 'factbase/syntax'
37
+ # t = Factbase::Syntax.new('(hello world)', MyTerm).to_term
38
+ #
39
+ # The +MyTerm+ class should have a constructor with two arguments:
40
+ # the operator and the list of operands (Array).
41
+ #
32
42
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
43
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
34
44
  # License:: MIT
35
45
  class Factbase::Syntax
36
46
  # Ctor.
37
47
  # @param [String] query The query, for example "(eq id 42)"
38
- def initialize(query)
48
+ # @param [Class] term The class to instantiate to make every term
49
+ def initialize(query, term: Factbase::Term)
39
50
  @query = query
51
+ @term = term
40
52
  end
41
53
 
42
54
  # Convert it to a term.
43
55
  # @return [Term] The term detected
44
56
  def to_term
45
- build.simplify
57
+ @to_term ||=
58
+ begin
59
+ t = build
60
+ t = t.simplify if t.respond_to?(:simplify)
61
+ t
62
+ end
46
63
  rescue StandardError => e
47
64
  err = "#{e.message} in \"#{@query}\""
48
65
  err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
@@ -60,7 +77,7 @@ class Factbase::Syntax
60
77
  raise 'Too many terms' if @ast[1] != @tokens.size
61
78
  term = @ast[0]
62
79
  raise 'No terms found' if term.nil?
63
- raise 'Not a term' unless term.is_a?(Factbase::Term)
80
+ raise 'Not a term' unless term.is_a?(@term)
64
81
  term
65
82
  end
66
83
 
@@ -89,7 +106,7 @@ class Factbase::Syntax
89
106
  operands << operand
90
107
  break if tokens[at] == :close
91
108
  end
92
- [Factbase::Term.new(op, operands), at + 1]
109
+ [@term.new(op, operands), at + 1]
93
110
  end
94
111
 
95
112
  # Turns a query into an array of tokens.
data/lib/factbase/term.rb CHANGED
@@ -130,13 +130,6 @@ class Factbase::Term
130
130
 
131
131
  private
132
132
 
133
- def either(fact, maps)
134
- assert_args(2)
135
- v = the_values(0, fact, maps)
136
- return v unless v.nil?
137
- the_values(1, fact, maps)
138
- end
139
-
140
133
  def at(fact, maps)
141
134
  assert_args(2)
142
135
  i = the_values(0, fact, maps)
@@ -57,6 +57,20 @@ module Factbase::Term::Logical
57
57
  true
58
58
  end
59
59
 
60
+ def when(fact, maps)
61
+ assert_args(2)
62
+ a = @operands[0]
63
+ b = @operands[1]
64
+ !a.evaluate(fact, maps) || (a.evaluate(fact, maps) && b.evaluate(fact, maps))
65
+ end
66
+
67
+ def either(fact, maps)
68
+ assert_args(2)
69
+ v = the_values(0, fact, maps)
70
+ return v unless v.nil?
71
+ the_values(1, fact, maps)
72
+ end
73
+
60
74
  def and_or_simplify
61
75
  strs = []
62
76
  ops = []
@@ -79,13 +93,6 @@ module Factbase::Term::Logical
79
93
  and_or_simplify
80
94
  end
81
95
 
82
- def when(fact, maps)
83
- assert_args(2)
84
- a = @operands[0]
85
- b = @operands[1]
86
- !a.evaluate(fact, maps) || (a.evaluate(fact, maps) && b.evaluate(fact, maps))
87
- end
88
-
89
96
  def _only_bool(val, pos)
90
97
  val = val[0] if val.is_a?(Array)
91
98
  return false if val.nil?
data/lib/factbase.rb CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
81
81
  # License:: MIT
82
82
  class Factbase
83
83
  # Current version of the gem (changed by .rultor.yml on every release)
84
- VERSION = '0.0.60'
84
+ VERSION = '0.1.1'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; end
@@ -99,7 +99,7 @@ class Factbase
99
99
  Factbase.new(@maps.map { |m| m.transform_values(&:dup) })
100
100
  end
101
101
 
102
- # Size.
102
+ # Size, the total number of facts in the factbase.
103
103
  # @return [Integer] How many facts are in there
104
104
  def size
105
105
  @maps.size
@@ -114,11 +114,11 @@ class Factbase
114
114
  #
115
115
  # @return [Factbase::Fact] The fact just inserted
116
116
  def insert
117
- require_relative 'factbase/fact'
118
117
  map = {}
119
118
  @mutex.synchronize do
120
119
  @maps << map
121
120
  end
121
+ require_relative 'factbase/fact'
122
122
  Factbase::Fact.new(@mutex, map)
123
123
  end
124
124
 
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require_relative '../../../lib/factbase/term'
25
+
26
+ # Defn test.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestDefn < Minitest::Test
31
+ def test_defn_simple
32
+ t = Factbase::Term.new(:defn, [:foo, 'self.to_s'])
33
+ assert_equal(true, t.evaluate(fact('foo' => 4), []))
34
+ t1 = Factbase::Term.new(:foo, ['hello, world!'])
35
+ assert_equal('(foo \'hello, world!\')', t1.evaluate(fact, []))
36
+ end
37
+
38
+ def test_defn_again_by_mistake
39
+ t = Factbase::Term.new(:defn, [:and, 'self.to_s'])
40
+ assert_raises do
41
+ t.evaluate(fact, [])
42
+ end
43
+ end
44
+
45
+ def test_defn_bad_name_by_mistake
46
+ t = Factbase::Term.new(:defn, [:to_s, 'self.to_s'])
47
+ assert_raises do
48
+ t.evaluate(fact, [])
49
+ end
50
+ end
51
+
52
+ def test_defn_bad_name_spelling_by_mistake
53
+ t = Factbase::Term.new(:defn, [:'some-key', 'self.to_s'])
54
+ assert_raises do
55
+ t.evaluate(fact, [])
56
+ end
57
+ end
58
+
59
+ def test_undef_simple
60
+ t = Factbase::Term.new(:defn, [:hello, 'self.to_s'])
61
+ assert_equal(true, t.evaluate(fact, []))
62
+ t = Factbase::Term.new(:undef, [:hello])
63
+ assert_equal(true, t.evaluate(fact, []))
64
+ end
65
+
66
+ private
67
+
68
+ def fact(map = {})
69
+ Factbase::Fact.new(Mutex.new, map)
70
+ end
71
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require_relative '../../../lib/factbase/term'
25
+
26
+ # Logical test.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestLogical < Minitest::Test
31
+ def test_not_matching
32
+ t = Factbase::Term.new(:not, [Factbase::Term.new(:always, [])])
33
+ assert(!t.evaluate(fact('foo' => [100]), []))
34
+ end
35
+
36
+ def test_not_eq_matching
37
+ t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, [:foo, 100])])
38
+ assert(t.evaluate(fact('foo' => [42, 12, -90]), []))
39
+ assert(!t.evaluate(fact('foo' => 100), []))
40
+ end
41
+
42
+ def test_either
43
+ t = Factbase::Term.new(:either, [Factbase::Term.new(:at, [5, :foo]), 42])
44
+ assert_equal([42], t.evaluate(fact('foo' => 4), []))
45
+ end
46
+
47
+ def test_or_matching
48
+ t = Factbase::Term.new(
49
+ :or,
50
+ [
51
+ Factbase::Term.new(:eq, [:foo, 4]),
52
+ Factbase::Term.new(:eq, [:bar, 5])
53
+ ]
54
+ )
55
+ assert(t.evaluate(fact('foo' => [4]), []))
56
+ assert(t.evaluate(fact('bar' => [5]), []))
57
+ assert(!t.evaluate(fact('bar' => [42]), []))
58
+ end
59
+
60
+ def test_when_matching
61
+ t = Factbase::Term.new(
62
+ :when,
63
+ [
64
+ Factbase::Term.new(:eq, [:foo, 4]),
65
+ Factbase::Term.new(:eq, [:bar, 5])
66
+ ]
67
+ )
68
+ assert(t.evaluate(fact('foo' => 4, 'bar' => 5), []))
69
+ assert(!t.evaluate(fact('foo' => 4), []))
70
+ assert(t.evaluate(fact('foo' => 5, 'bar' => 5), []))
71
+ end
72
+
73
+ private
74
+
75
+ def fact(map = {})
76
+ Factbase::Fact.new(Mutex.new, map)
77
+ end
78
+ end
@@ -106,6 +106,12 @@ class TestMath < Minitest::Test
106
106
  assert_equal('Float', t.evaluate(fact, []).class.to_s)
107
107
  end
108
108
 
109
+ def test_plus
110
+ t = Factbase::Term.new(:plus, [:foo, 42])
111
+ assert_equal(46, t.evaluate(fact('foo' => 4), []))
112
+ assert(t.evaluate(fact, []).nil?)
113
+ end
114
+
109
115
  private
110
116
 
111
117
  def fact(map = {})
@@ -28,6 +28,13 @@ require_relative '../../../lib/factbase/term'
28
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
29
  # License:: MIT
30
30
  class TestStrings < Minitest::Test
31
+ def test_regexp_matching
32
+ t = Factbase::Term.new(:matches, [:foo, '[a-z]+'])
33
+ assert(t.evaluate(fact('foo' => 'hello'), []))
34
+ assert(t.evaluate(fact('foo' => 'hello 42'), []))
35
+ assert(!t.evaluate(fact('foo' => 42), []))
36
+ end
37
+
31
38
  def test_concat
32
39
  t = Factbase::Term.new(:concat, [42, 'hi', 3.14, :hey, Time.now])
33
40
  s = t.evaluate(fact, [])
@@ -40,7 +47,7 @@ class TestStrings < Minitest::Test
40
47
  end
41
48
 
42
49
  def test_sprintf
43
- t = Factbase::Term.new(:sprintf, ['hi, %s!', 'Jeff', :hey])
50
+ t = Factbase::Term.new(:sprintf, ['hi, %s!', 'Jeff'])
44
51
  assert_equal('hi, Jeff!', t.evaluate(fact, []))
45
52
  end
46
53
 
@@ -120,8 +120,13 @@ class TestQuery < Minitest::Test
120
120
  '(agg (always) (count))' => 2,
121
121
  '(agg (eq bar $v) (count))' => 1,
122
122
  '(agg (eq z 40) (count))' => 0
123
- }.each do |q, r|
124
- assert_equal(r, Factbase::Query.new(maps, Mutex.new, q).one(v: 4), "#{q} -> #{r}")
123
+ }.each do |q, expected|
124
+ result = Factbase::Query.new(maps, Mutex.new, q).one(v: 4)
125
+ if expected.nil?
126
+ assert_nil(result, "#{q} -> nil")
127
+ else
128
+ assert_equal(expected, result, "#{q} -> #{expected}")
129
+ end
125
130
  end
126
131
  end
127
132
 
@@ -35,7 +35,7 @@ class TestSyntax < Minitest::Test
35
35
  "(foo 'one two three ')",
36
36
  "(foo 'one two three ' 'tail tail')"
37
37
  ].each do |q|
38
- assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
38
+ assert_equal(q, Factbase::Syntax.new(q).to_term.to_s, q)
39
39
  end
40
40
  end
41
41
 
@@ -50,7 +50,7 @@ class TestSyntax < Minitest::Test
50
50
  "(foo 'Hello,\n\nworld!\r\t\n')\n",
51
51
  "(or ( a 4) (b 5) (always) (and (always) (c 5) \t\t(r 7 w8s w8is 'Foo')))"
52
52
  ].each do |q|
53
- Factbase::Syntax.new(q).to_term
53
+ assert(!Factbase::Syntax.new(q).to_term.nil?)
54
54
  end
55
55
  end
56
56
 
@@ -70,7 +70,7 @@ class TestSyntax < Minitest::Test
70
70
  '(eq t 3.0e+21)',
71
71
  "(foo (x (f (t (y 42 'Hey you'))) (never) (r 3)) y z)"
72
72
  ].each do |q|
73
- assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
73
+ assert_equal(q, Factbase::Syntax.new(q).to_term.to_s, q)
74
74
  end
75
75
  end
76
76
 
@@ -33,17 +33,6 @@ class TestTerm < Minitest::Test
33
33
  assert(!t.evaluate(fact('foo' => [100]), []))
34
34
  end
35
35
 
36
- def test_not_matching
37
- t = Factbase::Term.new(:not, [Factbase::Term.new(:always, [])])
38
- assert(!t.evaluate(fact('foo' => [100]), []))
39
- end
40
-
41
- def test_not_eq_matching
42
- t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, [:foo, 100])])
43
- assert(t.evaluate(fact('foo' => [42, 12, -90]), []))
44
- assert(!t.evaluate(fact('foo' => 100), []))
45
- end
46
-
47
36
  def test_size_matching
48
37
  t = Factbase::Term.new(:size, [:foo])
49
38
  assert_equal(3, t.evaluate(fact('foo' => [42, 12, -90]), []))
@@ -74,74 +63,6 @@ class TestTerm < Minitest::Test
74
63
  assert_equal('nil', t.evaluate(fact, []))
75
64
  end
76
65
 
77
- def test_regexp_matching
78
- t = Factbase::Term.new(:matches, [:foo, '[a-z]+'])
79
- assert(t.evaluate(fact('foo' => 'hello'), []))
80
- assert(t.evaluate(fact('foo' => 'hello 42'), []))
81
- assert(!t.evaluate(fact('foo' => 42), []))
82
- end
83
-
84
- def test_or_matching
85
- t = Factbase::Term.new(
86
- :or,
87
- [
88
- Factbase::Term.new(:eq, [:foo, 4]),
89
- Factbase::Term.new(:eq, [:bar, 5])
90
- ]
91
- )
92
- assert(t.evaluate(fact('foo' => [4]), []))
93
- assert(t.evaluate(fact('bar' => [5]), []))
94
- assert(!t.evaluate(fact('bar' => [42]), []))
95
- end
96
-
97
- def test_when_matching
98
- t = Factbase::Term.new(
99
- :when,
100
- [
101
- Factbase::Term.new(:eq, [:foo, 4]),
102
- Factbase::Term.new(:eq, [:bar, 5])
103
- ]
104
- )
105
- assert(t.evaluate(fact('foo' => 4, 'bar' => 5), []))
106
- assert(!t.evaluate(fact('foo' => 4), []))
107
- assert(t.evaluate(fact('foo' => 5, 'bar' => 5), []))
108
- end
109
-
110
- def test_defn_simple
111
- t = Factbase::Term.new(:defn, [:foo, 'self.to_s'])
112
- assert_equal(true, t.evaluate(fact('foo' => 4), []))
113
- t1 = Factbase::Term.new(:foo, ['hello, world!'])
114
- assert_equal('(foo \'hello, world!\')', t1.evaluate(fact, []))
115
- end
116
-
117
- def test_defn_again_by_mistake
118
- t = Factbase::Term.new(:defn, [:and, 'self.to_s'])
119
- assert_raises do
120
- t.evaluate(fact, [])
121
- end
122
- end
123
-
124
- def test_defn_bad_name_by_mistake
125
- t = Factbase::Term.new(:defn, [:to_s, 'self.to_s'])
126
- assert_raises do
127
- t.evaluate(fact, [])
128
- end
129
- end
130
-
131
- def test_defn_bad_name_spelling_by_mistake
132
- t = Factbase::Term.new(:defn, [:'some-key', 'self.to_s'])
133
- assert_raises do
134
- t.evaluate(fact, [])
135
- end
136
- end
137
-
138
- def test_undef_simple
139
- t = Factbase::Term.new(:defn, [:hello, 'self.to_s'])
140
- assert_equal(true, t.evaluate(fact, []))
141
- t = Factbase::Term.new(:undef, [:hello])
142
- assert_equal(true, t.evaluate(fact, []))
143
- end
144
-
145
66
  def test_past
146
67
  t = Factbase::Term.new(:prev, [:foo])
147
68
  assert_nil(t.evaluate(fact('foo' => 4), []))
@@ -154,17 +75,6 @@ class TestTerm < Minitest::Test
154
75
  assert_equal(5, t.evaluate(fact('foo' => [4, 5]), []))
155
76
  end
156
77
 
157
- def test_either
158
- t = Factbase::Term.new(:either, [Factbase::Term.new(:at, [5, :foo]), 42])
159
- assert_equal([42], t.evaluate(fact('foo' => 4), []))
160
- end
161
-
162
- def test_plus
163
- t = Factbase::Term.new(:plus, [:foo, 42])
164
- assert_equal(46, t.evaluate(fact('foo' => 4), []))
165
- assert(t.evaluate(fact, []).nil?)
166
- end
167
-
168
78
  def test_report_missing_term
169
79
  t = Factbase::Term.new(:something, [])
170
80
  msg = assert_raises do
data/test/test__helper.rb CHANGED
@@ -29,3 +29,6 @@ require 'simplecov-cobertura'
29
29
  SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
30
30
 
31
31
  require 'minitest/autorun'
32
+
33
+ require 'minitest/reporters'
34
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.60
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -183,6 +183,8 @@ files:
183
183
  - renovate.json
184
184
  - test/factbase/terms/test_aggregates.rb
185
185
  - test/factbase/terms/test_aliases.rb
186
+ - test/factbase/terms/test_defn.rb
187
+ - test/factbase/terms/test_logical.rb
186
188
  - test/factbase/terms/test_math.rb
187
189
  - test/factbase/terms/test_strings.rb
188
190
  - test/factbase/test_accum.rb