factbase 0.7.2 → 0.7.4
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/.github/workflows/benchmark.yml +3 -1
- data/.gitignore +5 -5
- data/.rultor.yml +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +29 -25
- data/REUSE.toml +4 -0
- data/Rakefile +10 -3
- data/benchmark/bench_factbase.rb +56 -0
- data/benchmark/bench_query.rb +41 -0
- data/benchmark/bench_taped.rb +33 -0
- data/lib/factbase/churn.rb +4 -0
- data/lib/factbase/logged.rb +172 -0
- data/lib/factbase/looged.rb +2 -2
- data/lib/factbase/taped.rb +16 -18
- data/lib/factbase.rb +10 -11
- data/test/factbase/terms/test_aggregates.rb +2 -2
- data/test/factbase/terms/test_aliases.rb +4 -4
- data/test/factbase/terms/test_casting.rb +1 -2
- data/test/factbase/terms/test_debug.rb +2 -2
- data/test/factbase/terms/test_defn.rb +2 -2
- data/test/factbase/terms/test_logical.rb +2 -2
- data/test/factbase/terms/test_math.rb +1 -2
- data/test/factbase/terms/test_meta.rb +2 -2
- data/test/factbase/terms/test_ordering.rb +2 -2
- data/test/factbase/terms/test_strings.rb +2 -2
- data/test/factbase/terms/test_system.rb +1 -2
- data/test/factbase/test_accum.rb +2 -2
- data/test/factbase/test_churn.rb +3 -2
- data/test/factbase/test_fact.rb +2 -2
- data/test/factbase/test_flatten.rb +2 -2
- data/test/factbase/test_inv.rb +2 -2
- data/test/factbase/test_logged.rb +129 -0
- data/test/factbase/test_looged.rb +8 -8
- data/test/factbase/test_pre.rb +2 -2
- data/test/factbase/test_query.rb +2 -2
- data/test/factbase/test_rules.rb +2 -2
- data/test/factbase/test_syntax.rb +2 -2
- data/test/factbase/test_tallied.rb +2 -2
- data/test/factbase/test_taped.rb +12 -2
- data/test/factbase/test_tee.rb +2 -2
- data/test/factbase/test_term.rb +2 -2
- data/test/factbase/test_to_json.rb +2 -2
- data/test/factbase/test_to_xml.rb +2 -2
- data/test/factbase/test_to_yaml.rb +2 -2
- data/test/test__helper.rb +3 -1
- data/test/test_factbase.rb +45 -12
- metadata +8 -7
- data/benchmarks/simple.rb +0 -127
data/lib/factbase.rb
CHANGED
@@ -37,7 +37,7 @@ require 'yaml'
|
|
37
37
|
# {
|
38
38
|
# 'name': ['Jeff', 'Walter'],
|
39
39
|
# 'age': [42, 'unknown'],
|
40
|
-
# 'place: 'LA'
|
40
|
+
# 'place': 'LA'
|
41
41
|
# }
|
42
42
|
#
|
43
43
|
# Value sets, as you can see, allow data of different types. However, there
|
@@ -64,7 +64,7 @@ require 'yaml'
|
|
64
64
|
# License:: MIT
|
65
65
|
class Factbase
|
66
66
|
# Current version of the gem (changed by .rultor.yml on every release)
|
67
|
-
VERSION = '0.7.
|
67
|
+
VERSION = '0.7.4'
|
68
68
|
|
69
69
|
# An exception that may be thrown in a transaction, to roll it back.
|
70
70
|
class Rollback < StandardError; end
|
@@ -147,36 +147,35 @@ class Factbase
|
|
147
147
|
# A the end of this script, the factbase will be empty. No facts will
|
148
148
|
# inserted and all changes that happened in the block will be rolled back.
|
149
149
|
#
|
150
|
-
# @return [
|
150
|
+
# @return [Factbase::Churn] How many facts have been changed (zero if rolled back)
|
151
151
|
def txn
|
152
152
|
pairs = {}
|
153
|
-
lookup = {}
|
154
153
|
before =
|
155
154
|
@mutex.synchronize do
|
156
155
|
@maps.map do |m|
|
157
156
|
n = m.transform_values(&:dup)
|
158
157
|
# rubocop:disable Lint/HashCompareByIdentity
|
159
158
|
pairs[n.object_id] = m.object_id
|
160
|
-
lookup[n.object_id] = n
|
161
159
|
# rubocop:enable Lint/HashCompareByIdentity
|
162
160
|
n
|
163
161
|
end
|
164
162
|
end
|
165
163
|
require_relative 'factbase/taped'
|
166
|
-
taped = Factbase::Taped.new(before
|
164
|
+
taped = Factbase::Taped.new(before)
|
167
165
|
begin
|
168
166
|
require_relative 'factbase/light'
|
169
167
|
yield Factbase::Light.new(Factbase.new(taped, cache: @cache), @cache)
|
170
168
|
rescue Factbase::Rollback
|
171
169
|
return 0
|
172
170
|
end
|
173
|
-
|
171
|
+
require_relative 'factbase/churn'
|
172
|
+
churn = Factbase::Churn.new
|
174
173
|
@mutex.synchronize do
|
175
174
|
taped.inserted.each do |oid|
|
176
175
|
b = taped.find_by_object_id(oid)
|
177
176
|
next if b.nil?
|
178
177
|
@maps << b
|
179
|
-
|
178
|
+
churn.append(1, 0, 0)
|
180
179
|
end
|
181
180
|
garbage = []
|
182
181
|
taped.added.each do |oid|
|
@@ -184,15 +183,15 @@ class Factbase
|
|
184
183
|
next if b.nil?
|
185
184
|
garbage << pairs[oid]
|
186
185
|
@maps << b
|
187
|
-
|
186
|
+
churn.append(0, 0, 1)
|
188
187
|
end
|
189
188
|
taped.deleted.each do |oid|
|
190
189
|
garbage << pairs[oid]
|
191
|
-
|
190
|
+
churn.append(0, 1, 0)
|
192
191
|
end
|
193
192
|
@maps.delete_if { |m| garbage.include?(m.object_id) }
|
194
193
|
end
|
195
|
-
|
194
|
+
churn
|
196
195
|
end
|
197
196
|
|
198
197
|
# Export it into a chain of bytes.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
require_relative '../../../lib/factbase/syntax'
|
9
9
|
|
@@ -11,7 +11,7 @@ require_relative '../../../lib/factbase/syntax'
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
13
|
# License:: MIT
|
14
|
-
class TestAggregates <
|
14
|
+
class TestAggregates < Factbase::Test
|
15
15
|
def test_aggregation
|
16
16
|
maps = [
|
17
17
|
{ 'x' => [1], 'y' => [0], 'z' => [4] },
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
require_relative '../../../lib/factbase/syntax'
|
9
9
|
require_relative '../../../lib/factbase/accum'
|
@@ -12,7 +12,7 @@ require_relative '../../../lib/factbase/accum'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestAliases <
|
15
|
+
class TestAliases < Factbase::Test
|
16
16
|
def test_aliases
|
17
17
|
maps = [
|
18
18
|
{ 'x' => [1], 'y' => [0], 't1' => [Time.now], 't2' => [Time.now] },
|
@@ -47,8 +47,8 @@ class TestAliases < Minitest::Test
|
|
47
47
|
t = Factbase::Syntax.new(Factbase.new, q).to_term
|
48
48
|
maps.each do |m|
|
49
49
|
f = Factbase::Accum.new(fact(m), {}, false)
|
50
|
-
require_relative '../../../lib/factbase/
|
51
|
-
f = Factbase::
|
50
|
+
require_relative '../../../lib/factbase/logged'
|
51
|
+
f = Factbase::Logged::Fact.new(f, Loog::NULL)
|
52
52
|
next unless t.evaluate(f, maps)
|
53
53
|
assert(Factbase::Syntax.new(Factbase.new, r).to_term.evaluate(f, []), "#{q} -> #{f} doesn't match #{r}")
|
54
54
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
require 'minitest/autorun'
|
7
6
|
require_relative '../../test__helper'
|
8
7
|
require_relative '../../../lib/factbase/term'
|
9
8
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
12
|
# License:: MIT
|
14
|
-
class TestCasting <
|
13
|
+
class TestCasting < Factbase::Test
|
15
14
|
def test_to_str
|
16
15
|
t = Factbase::Term.new(Factbase.new, :to_string, [Time.now])
|
17
16
|
assert_equal('String', t.evaluate(fact, []).class.to_s)
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Debug test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestDebug <
|
13
|
+
class TestDebug < Factbase::Test
|
14
14
|
def test_traced
|
15
15
|
t = Factbase::Term.new(Factbase.new, :traced, [Factbase::Term.new(Factbase.new, :defn, [:test_debug, 'self.to_s'])])
|
16
16
|
assert_output("(traced (defn test_debug 'self.to_s')) -> true\n") do
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Defn test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestDefn <
|
13
|
+
class TestDefn < Factbase::Test
|
14
14
|
def test_defn_simple
|
15
15
|
t = Factbase::Term.new(Factbase.new, :defn, [:foo, 'self.to_s'])
|
16
16
|
assert(t.evaluate(fact('foo' => 4), []))
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Logical test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestLogical <
|
13
|
+
class TestLogical < Factbase::Test
|
14
14
|
def test_not_matching
|
15
15
|
t = Factbase::Term.new(Factbase.new, :not, [Factbase::Term.new(Factbase.new, :always, [])])
|
16
16
|
refute(t.evaluate(fact('foo' => [100]), []))
|
@@ -3,7 +3,6 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
require 'minitest/autorun'
|
7
6
|
require_relative '../../test__helper'
|
8
7
|
require_relative '../../../lib/factbase/term'
|
9
8
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
12
|
# License:: MIT
|
14
|
-
class TestMath <
|
13
|
+
class TestMath < Factbase::Test
|
15
14
|
def test_simple
|
16
15
|
t = Factbase::Term.new(Factbase.new, :eq, [:foo, 42])
|
17
16
|
assert(t.evaluate(fact('foo' => [42]), []))
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Meta test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestMeta <
|
13
|
+
class TestMeta < Factbase::Test
|
14
14
|
def test_exists
|
15
15
|
t = Factbase::Term.new(Factbase.new, :exists, [:foo])
|
16
16
|
assert(t.evaluate(fact('foo' => 41), []))
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Ordering test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestOrdering <
|
13
|
+
class TestOrdering < Factbase::Test
|
14
14
|
def test_prev
|
15
15
|
t = Factbase::Term.new(Factbase.new, :prev, [:foo])
|
16
16
|
assert_nil(t.evaluate(fact('foo' => 41), []))
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../../test__helper'
|
7
7
|
require_relative '../../../lib/factbase/term'
|
8
8
|
|
9
9
|
# Strings test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestStrings <
|
13
|
+
class TestStrings < Factbase::Test
|
14
14
|
def test_regexp_matching
|
15
15
|
t = Factbase::Term.new(Factbase.new, :matches, [:foo, '[a-z]+'])
|
16
16
|
assert(t.evaluate(fact('foo' => 'hello'), []))
|
@@ -3,7 +3,6 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
require 'minitest/autorun'
|
7
6
|
require_relative '../../test__helper'
|
8
7
|
require_relative '../../../lib/factbase/term'
|
9
8
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
12
|
# License:: MIT
|
14
|
-
class TestSystem <
|
13
|
+
class TestSystem < Factbase::Test
|
15
14
|
def test_env
|
16
15
|
ENV.store('FOO', 'bar')
|
17
16
|
t = Factbase::Term.new(Factbase.new, :env, ['FOO', ''])
|
data/test/factbase/test_accum.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require_relative '../../lib/factbase'
|
8
8
|
require_relative '../../lib/factbase/accum'
|
9
9
|
require_relative '../../lib/factbase/fact'
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/fact'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestAccum <
|
15
|
+
class TestAccum < Factbase::Test
|
16
16
|
def test_holds_props
|
17
17
|
map = {}
|
18
18
|
f = Factbase::Fact.new(Factbase.new, Mutex.new, map)
|
data/test/factbase/test_churn.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'loog'
|
8
8
|
require_relative '../../lib/factbase'
|
9
9
|
require_relative '../../lib/factbase/churn'
|
@@ -12,11 +12,12 @@ require_relative '../../lib/factbase/churn'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestChurn <
|
15
|
+
class TestChurn < Factbase::Test
|
16
16
|
def test_appends
|
17
17
|
c = Factbase::Churn.new
|
18
18
|
c.append(1, 2, 3)
|
19
19
|
assert_equal('1i/2d/3a', c.to_s)
|
20
|
+
assert_equal(6, c.to_i)
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_checks_for_zero
|
data/test/factbase/test_fact.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require_relative '../../lib/factbase'
|
8
8
|
require_relative '../../lib/factbase/fact'
|
9
9
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/fact'
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
13
|
# License:: MIT
|
14
|
-
class TestFact <
|
14
|
+
class TestFact < Factbase::Test
|
15
15
|
def test_injects_data_correctly
|
16
16
|
map = {}
|
17
17
|
f = Factbase::Fact.new(Factbase.new, Mutex.new, map)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require_relative '../../lib/factbase'
|
8
8
|
require_relative '../../lib/factbase/flatten'
|
9
9
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/flatten'
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
13
|
# License:: MIT
|
14
|
-
class TestFlatten <
|
14
|
+
class TestFlatten < Factbase::Test
|
15
15
|
def test_mapping
|
16
16
|
maps = [{ 'b' => [42], 'i' => 1 }, { 'a' => 33, 'i' => 0 }, { 'c' => %w[hey you], 'i' => 2 }]
|
17
17
|
to = Factbase::Flatten.new(maps, 'i').it
|
data/test/factbase/test_inv.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'loog'
|
8
8
|
require_relative '../../lib/factbase'
|
9
9
|
require_relative '../../lib/factbase/inv'
|
@@ -13,7 +13,7 @@ require_relative '../../lib/factbase/pre'
|
|
13
13
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
14
14
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
15
15
|
# License:: MIT
|
16
|
-
class TestInv <
|
16
|
+
class TestInv < Factbase::Test
|
17
17
|
def test_simple_checking
|
18
18
|
fb =
|
19
19
|
Factbase::Inv.new(Factbase.new) do |p, v|
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require_relative '../test__helper'
|
7
|
+
require 'loog'
|
8
|
+
require_relative '../../lib/factbase'
|
9
|
+
require_relative '../../lib/factbase/logged'
|
10
|
+
|
11
|
+
# Test.
|
12
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
|
+
# License:: MIT
|
15
|
+
class TestLogged < Factbase::Test
|
16
|
+
def test_simple_setting
|
17
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
18
|
+
fb.insert
|
19
|
+
fb.insert.bar = 3
|
20
|
+
found = 0
|
21
|
+
fb.query('(exists bar)').each do |f|
|
22
|
+
assert_predicate(f.bar, :positive?)
|
23
|
+
f.foo = 42
|
24
|
+
assert_equal(42, f.foo)
|
25
|
+
found += 1
|
26
|
+
end
|
27
|
+
assert_equal(1, found)
|
28
|
+
assert_equal(2, fb.size)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_reading_one
|
32
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
33
|
+
fb.insert
|
34
|
+
fb.insert.bar = 42
|
35
|
+
assert_equal(1, fb.query('(agg (exists bar) (count))').one)
|
36
|
+
assert_equal([42], fb.query('(agg (exists bar) (first bar))').one)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_with_txn
|
40
|
+
log = Loog::Buffer.new
|
41
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
42
|
+
assert(
|
43
|
+
fb.txn do |fbt|
|
44
|
+
fbt.insert.foo = 42
|
45
|
+
end
|
46
|
+
)
|
47
|
+
assert_equal(1, fb.size)
|
48
|
+
assert_includes(log.to_s, 'touched', log)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_with_txn_rollback
|
52
|
+
log = Loog::Buffer.new
|
53
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
54
|
+
assert_equal(0, fb.txn { raise Factbase::Rollback })
|
55
|
+
assert_equal(0, fb.size)
|
56
|
+
assert_includes(log.to_s, 'rolled back', log)
|
57
|
+
refute_includes(log.to_s, 'didn\'t touch', log)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_with_modifying_txn
|
61
|
+
log = Loog::Buffer.new
|
62
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
63
|
+
fb.insert.foo = 1
|
64
|
+
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i, log)
|
65
|
+
assert_equal(1, fb.txn { |fbt| fbt.query('(always)').each.to_a[0].foo = 42 }.to_i)
|
66
|
+
assert_includes(log.to_s, 'touched', log)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_with_empty_txn
|
70
|
+
log = Loog::Buffer.new
|
71
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
72
|
+
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i)
|
73
|
+
assert_includes(log.to_s, 'touched', log)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_returns_int
|
77
|
+
fb = Factbase.new
|
78
|
+
fb.insert
|
79
|
+
fb.insert
|
80
|
+
assert_equal(2, Factbase::Logged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_returns_int_when_empty
|
84
|
+
fb = Factbase.new
|
85
|
+
assert_equal(0, Factbase::Logged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_logs_when_enumerator
|
89
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
90
|
+
assert_equal(0, fb.query('(always)').each.to_a.size)
|
91
|
+
fb.insert
|
92
|
+
assert_equal(1, fb.query('(always)').each.to_a.size)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_proper_logging
|
96
|
+
log = Loog::Buffer.new
|
97
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
98
|
+
fb.insert
|
99
|
+
fb.insert.bar = 3
|
100
|
+
fb.insert
|
101
|
+
fb.insert.str =
|
102
|
+
"Он поскорей звонит. Вбегает
|
103
|
+
К нему слуга француз Гильо,
|
104
|
+
Халат и туфли предлагает
|
105
|
+
И подает ему белье.
|
106
|
+
Спешит Онегин одеваться,
|
107
|
+
Слуге велит приготовляться
|
108
|
+
С ним вместе ехать и с собой
|
109
|
+
Взять также ящик боевой.
|
110
|
+
Готовы санки беговые.
|
111
|
+
Он сел, на мельницу летит.
|
112
|
+
Примчались. Он слуге велит
|
113
|
+
Лепажа стволы роковые
|
114
|
+
Нести за ним, а лошадям
|
115
|
+
Отъехать в поле к двум дубкам."
|
116
|
+
fb.query('(exists bar)').each(&:to_s)
|
117
|
+
fb.query('(not (exists bar))').delete!
|
118
|
+
[
|
119
|
+
'Inserted new fact #1',
|
120
|
+
'Inserted new fact #2',
|
121
|
+
'Set \'bar\' to 3 (Integer)',
|
122
|
+
'Set \'str\' to "Он поскорей звонит. Вбегает\n ... Отъехать в поле к двум дубкам." (String)',
|
123
|
+
'Found 1 fact(s) by \'(exists bar)\'',
|
124
|
+
'Deleted 3 fact(s) out of 4 by \'(not (exists bar))\''
|
125
|
+
].each do |s|
|
126
|
+
assert_includes(log.to_s, s, "#{log}\n")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'loog'
|
8
8
|
require_relative '../../lib/factbase'
|
9
9
|
require_relative '../../lib/factbase/looged'
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/looged'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestLooged <
|
15
|
+
class TestLooged < Factbase::Test
|
16
16
|
def test_simple_setting
|
17
17
|
fb = Factbase::Looged.new(Factbase.new, Loog::NULL)
|
18
18
|
fb.insert
|
@@ -45,7 +45,7 @@ class TestLooged < Minitest::Test
|
|
45
45
|
end
|
46
46
|
)
|
47
47
|
assert_equal(1, fb.size)
|
48
|
-
assert_includes(log.to_s, '
|
48
|
+
assert_includes(log.to_s, 'touched', log)
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_with_txn_rollback
|
@@ -61,16 +61,16 @@ class TestLooged < Minitest::Test
|
|
61
61
|
log = Loog::Buffer.new
|
62
62
|
fb = Factbase::Looged.new(Factbase.new, log)
|
63
63
|
fb.insert.foo = 1
|
64
|
-
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }, log)
|
65
|
-
assert_equal(1, fb.txn { |fbt| fbt.query('(always)').each.to_a[0].foo = 42 })
|
66
|
-
assert_includes(log.to_s, '
|
64
|
+
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i, log)
|
65
|
+
assert_equal(1, fb.txn { |fbt| fbt.query('(always)').each.to_a[0].foo = 42 }.to_i)
|
66
|
+
assert_includes(log.to_s, 'touched', log)
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_with_empty_txn
|
70
70
|
log = Loog::Buffer.new
|
71
71
|
fb = Factbase::Looged.new(Factbase.new, log)
|
72
|
-
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a })
|
73
|
-
assert_includes(log.to_s, '
|
72
|
+
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i)
|
73
|
+
assert_includes(log.to_s, 'touched', log)
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_returns_int
|
data/test/factbase/test_pre.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'loog'
|
8
8
|
require_relative '../../lib/factbase/pre'
|
9
9
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/pre'
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
13
|
# License:: MIT
|
14
|
-
class TestPre <
|
14
|
+
class TestPre < Factbase::Test
|
15
15
|
def test_simple_setting
|
16
16
|
fb = Factbase::Pre.new(Factbase.new) { |f| f.foo = 42 }
|
17
17
|
f = fb.insert
|
data/test/factbase/test_query.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'time'
|
8
8
|
require_relative '../../lib/factbase'
|
9
9
|
require_relative '../../lib/factbase/query'
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/query'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestQuery <
|
15
|
+
class TestQuery < Factbase::Test
|
16
16
|
def test_simple_parsing
|
17
17
|
maps = []
|
18
18
|
maps << { 'foo' => [42] }
|
data/test/factbase/test_rules.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require_relative '../../lib/factbase'
|
8
8
|
require_relative '../../lib/factbase/rules'
|
9
9
|
require_relative '../../lib/factbase/pre'
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/pre'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestRules <
|
15
|
+
class TestRules < Factbase::Test
|
16
16
|
def test_simple_checking
|
17
17
|
fb = Factbase::Rules.new(
|
18
18
|
Factbase.new,
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require_relative '../../lib/factbase/syntax'
|
8
8
|
|
9
9
|
# Syntax test.
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
|
-
class TestSyntax <
|
13
|
+
class TestSyntax < Factbase::Test
|
14
14
|
def test_parses_string_right
|
15
15
|
[
|
16
16
|
"(foo 'abc')",
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
-
|
6
|
+
require_relative '../test__helper'
|
7
7
|
require 'threads'
|
8
8
|
require_relative '../../lib/factbase'
|
9
9
|
require_relative '../../lib/factbase/tallied'
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/tallied'
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
|
-
class TestTallied <
|
15
|
+
class TestTallied < Factbase::Test
|
16
16
|
def test_counts_size
|
17
17
|
fb = Factbase::Tallied.new(Factbase.new)
|
18
18
|
assert_equal(0, fb.size)
|