judges 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -0
- data/fixtures/try/try.rb +1 -1
- data/judges.gemspec +1 -1
- data/lib/judges/commands/update.rb +1 -1
- data/lib/judges/judge.rb +0 -2
- data/lib/judges.rb +1 -1
- data/test/test_judge.rb +0 -23
- metadata +1 -5
- data/lib/judges/fb/if_absent.rb +0 -74
- data/lib/judges/fb/once.rb +0 -54
- data/test/fb/test_if_absent.rb +0 -103
- data/test/fb/test_once.rb +0 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be8151f228edd7b8c45f0fcf1f566e8585fae93ce87bcb7f56ca6f452a1b67ca
|
4
|
+
data.tar.gz: 99e20604a1f8a78a0c5dbf4080522aab725a7e82df5cb87d3b456962636aad10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2df81af8fd18810e54c05fc3631a2e38037d45e49a7f87cd4e9e8592155b155b81671ad5641e3923886e86752fa3be8c5f7926f2ce539d48ccfac714269f44d4
|
7
|
+
data.tar.gz: 6fd2568f060510bc0b0600cc9d186d622025a7f886085bf5993bc3388f246c283c2c08c785199d609fd7a4729eb949a27a829d199785d43334addbdcd7f51248
|
data/Gemfile.lock
CHANGED
@@ -92,6 +92,7 @@ GEM
|
|
92
92
|
ffi (1.17.0-aarch64-linux-gnu)
|
93
93
|
ffi (1.17.0-arm-linux-gnu)
|
94
94
|
ffi (1.17.0-arm64-darwin)
|
95
|
+
ffi (1.17.0-x64-mingw-ucrt)
|
95
96
|
ffi (1.17.0-x86-linux-gnu)
|
96
97
|
ffi (1.17.0-x86_64-darwin)
|
97
98
|
ffi (1.17.0-x86_64-linux-gnu)
|
@@ -121,6 +122,8 @@ GEM
|
|
121
122
|
racc (~> 1.4)
|
122
123
|
nokogiri (1.16.5-arm64-darwin)
|
123
124
|
racc (~> 1.4)
|
125
|
+
nokogiri (1.16.5-x64-mingw-ucrt)
|
126
|
+
racc (~> 1.4)
|
124
127
|
nokogiri (1.16.5-x86-linux)
|
125
128
|
racc (~> 1.4)
|
126
129
|
nokogiri (1.16.5-x86_64-darwin)
|
@@ -244,6 +247,7 @@ PLATFORMS
|
|
244
247
|
aarch64-linux
|
245
248
|
arm-linux
|
246
249
|
arm64-darwin
|
250
|
+
x64-mingw-ucrt
|
247
251
|
x86-linux
|
248
252
|
x86_64-darwin
|
249
253
|
x86_64-linux
|
data/fixtures/try/try.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
$fb.query("(and (exists number) (lt time #{Time.now.utc.iso8601}))").each do |f|
|
24
24
|
n = $fb.insert
|
25
25
|
n.guess = f.number
|
26
26
|
end
|
data/judges.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=3.2'
|
28
28
|
s.name = 'judges'
|
29
|
-
s.version = '0.
|
29
|
+
s.version = '0.3.0'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
32
32
|
s.description =
|
@@ -85,7 +85,7 @@ class Judges::Update
|
|
85
85
|
elapsed(@loog) do
|
86
86
|
done = judges.each_with_index do |p, i|
|
87
87
|
local = {}
|
88
|
-
@loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
|
88
|
+
@loog.info("\n👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
|
89
89
|
before = fb.size
|
90
90
|
begin
|
91
91
|
p.run(fb, global, local, options)
|
data/lib/judges/judge.rb
CHANGED
@@ -23,8 +23,6 @@
|
|
23
23
|
require_relative '../judges'
|
24
24
|
require_relative '../judges/to_rel'
|
25
25
|
require_relative '../judges/elapsed'
|
26
|
-
require_relative '../judges/fb/once'
|
27
|
-
require_relative '../judges/fb/if_absent'
|
28
26
|
|
29
27
|
# A single judge.
|
30
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
data/lib/judges.rb
CHANGED
data/test/test_judge.rb
CHANGED
@@ -55,14 +55,6 @@ class TestPack < Minitest::Test
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def test_with_supplemenary_functions
|
59
|
-
Dir.mktmpdir do |d|
|
60
|
-
File.write(File.join(d, 'x.rb'), 'each_once($fb, "(always)").to_a')
|
61
|
-
judge = Judges::Judge.new(d, nil, Loog::NULL)
|
62
|
-
judge.run(Factbase.new, {}, {}, {})
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
58
|
def test_passes_local_vars_between_tests
|
67
59
|
Dir.mktmpdir do |d|
|
68
60
|
File.write(
|
@@ -93,21 +85,6 @@ class TestPack < Minitest::Test
|
|
93
85
|
end
|
94
86
|
end
|
95
87
|
|
96
|
-
def test_with_library
|
97
|
-
Dir.mktmpdir do |d|
|
98
|
-
dir = File.join(d, 'judges')
|
99
|
-
FileUtils.mkdir_p(dir)
|
100
|
-
File.write(File.join(dir, 'x.rb'), '$fb.insert.bar = $foo; each_once($fb, "(always)").to_a')
|
101
|
-
lib = File.join(d, 'lib')
|
102
|
-
FileUtils.mkdir_p(lib)
|
103
|
-
File.write(File.join(lib, 'y.rb'), '$foo = 42')
|
104
|
-
judge = Judges::Judge.new(dir, lib, Loog::NULL)
|
105
|
-
fb = Factbase.new
|
106
|
-
judge.run(fb, {}, {}, {})
|
107
|
-
assert_equal(42, fb.query('(always)').each.to_a.first.bar)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
88
|
def test_with_broken_ruby_syntax
|
112
89
|
assert_raises do
|
113
90
|
Dir.mktmpdir do |d|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: judges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -187,8 +187,6 @@ files:
|
|
187
187
|
- lib/judges/commands/trim.rb
|
188
188
|
- lib/judges/commands/update.rb
|
189
189
|
- lib/judges/elapsed.rb
|
190
|
-
- lib/judges/fb/if_absent.rb
|
191
|
-
- lib/judges/fb/once.rb
|
192
190
|
- lib/judges/impex.rb
|
193
191
|
- lib/judges/judge.rb
|
194
192
|
- lib/judges/judges.rb
|
@@ -205,8 +203,6 @@ files:
|
|
205
203
|
- test/commands/test_test.rb
|
206
204
|
- test/commands/test_trim.rb
|
207
205
|
- test/commands/test_update.rb
|
208
|
-
- test/fb/test_if_absent.rb
|
209
|
-
- test/fb/test_once.rb
|
210
206
|
- test/test__helper.rb
|
211
207
|
- test/test_baza.rb
|
212
208
|
- test/test_categories.rb
|
data/lib/judges/fb/if_absent.rb
DELETED
@@ -1,74 +0,0 @@
|
|
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 NONINFRINGEMENT. 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 'judges'
|
24
|
-
require 'time'
|
25
|
-
|
26
|
-
# Injects a fact if it's absent in the factbase.
|
27
|
-
def if_absent(fb)
|
28
|
-
attrs = {}
|
29
|
-
f = Judges::Accumulator.new(attrs)
|
30
|
-
yield f
|
31
|
-
q = attrs.map do |k, v|
|
32
|
-
vv = v.to_s
|
33
|
-
if v.is_a?(String)
|
34
|
-
vv = "'#{vv.gsub('"', '\\\\"').gsub("'", "\\\\'")}'"
|
35
|
-
elsif v.is_a?(Time)
|
36
|
-
vv = v.utc.iso8601
|
37
|
-
end
|
38
|
-
"(eq #{k} #{vv})"
|
39
|
-
end.join(' ')
|
40
|
-
q = "(and #{q})"
|
41
|
-
return unless fb.query(q).each.to_a.empty?
|
42
|
-
n = fb.insert
|
43
|
-
attrs.each { |k, v| n.send("#{k}=", v) }
|
44
|
-
n
|
45
|
-
end
|
46
|
-
|
47
|
-
# Predents to be a fact, just accumulating all attribute sets.
|
48
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
49
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
50
|
-
# License:: MIT
|
51
|
-
class Judges::Accumulator
|
52
|
-
def initialize(map)
|
53
|
-
@map = map
|
54
|
-
end
|
55
|
-
|
56
|
-
def method_missing(*args)
|
57
|
-
k = args[0]
|
58
|
-
if k.end_with?('=')
|
59
|
-
@map[k[0..-2].to_sym] = args[1]
|
60
|
-
else
|
61
|
-
@map[k.to_sym]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
66
|
-
def respond_to?(_method, _include_private = false)
|
67
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
68
|
-
true
|
69
|
-
end
|
70
|
-
|
71
|
-
def respond_to_missing?(_method, _include_private = false)
|
72
|
-
true
|
73
|
-
end
|
74
|
-
end
|
data/lib/judges/fb/once.rb
DELETED
@@ -1,54 +0,0 @@
|
|
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 NONINFRINGEMENT. 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 'judges'
|
24
|
-
require 'factbase/tuples'
|
25
|
-
|
26
|
-
# Returns a decorated global factbase, which only touches facts once.
|
27
|
-
def each_once(fb, query, judge: $judge)
|
28
|
-
return to_enum(__method__, fb, query, judge:) unless block_given?
|
29
|
-
q = "(and #{query} (not (eq seen '#{judge}')))"
|
30
|
-
fb.query(q).each do |f|
|
31
|
-
yield f
|
32
|
-
f.seen = judge
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Returns a decorated global factbase, which only touches a tuple once.
|
37
|
-
def each_tuple_once(fb, *queries, judge: $judge)
|
38
|
-
return to_enum(__method__, fb, *queries, judge:) unless block_given?
|
39
|
-
qq = queries.map { |q| "(and #{q} (not (eq seen '#{judge}')))" }
|
40
|
-
Factbase::Tuples.new(fb, qq).each do |fs|
|
41
|
-
yield fs
|
42
|
-
fs.each do |f|
|
43
|
-
f.seen = judge
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def each_tuple_once_txn(fb, *queries, judge: $judge)
|
49
|
-
fb.txn do |fbt|
|
50
|
-
each_tuple_once(fb, *queries, judge:) do |fs|
|
51
|
-
yield [fbt] + fs
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/test/fb/test_if_absent.rb
DELETED
@@ -1,103 +0,0 @@
|
|
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 NONINFRINGEMENT. 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 'tmpdir'
|
25
|
-
require 'factbase'
|
26
|
-
require 'factbase/looged'
|
27
|
-
require 'loog'
|
28
|
-
require_relative '../../lib/judges'
|
29
|
-
require_relative '../../lib/judges/fb/if_absent'
|
30
|
-
|
31
|
-
# Test.
|
32
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
33
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
34
|
-
# License:: MIT
|
35
|
-
class TestIfAbsent < Minitest::Test
|
36
|
-
def test_ignores
|
37
|
-
fb = Factbase.new
|
38
|
-
fb.insert.foo = 'hello dude'
|
39
|
-
n = if_absent(fb) do |f|
|
40
|
-
f.foo = 'hello dude'
|
41
|
-
end
|
42
|
-
assert(n.nil?)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_ignores_with_time
|
46
|
-
fb = Factbase.new
|
47
|
-
t = Time.now
|
48
|
-
fb.insert.foo = t
|
49
|
-
n = if_absent(fb) do |f|
|
50
|
-
f.foo = t
|
51
|
-
end
|
52
|
-
assert(n.nil?)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_injects
|
56
|
-
fb = Factbase.new
|
57
|
-
n = if_absent(fb) do |f|
|
58
|
-
f.foo = 42
|
59
|
-
end
|
60
|
-
assert_equal(42, n.foo)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_injects_and_reads
|
64
|
-
if_absent(Factbase.new) do |f|
|
65
|
-
f.foo = 42
|
66
|
-
assert_equal(42, f.foo)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_complex_ignores
|
71
|
-
fb = Factbase.new
|
72
|
-
f1 = fb.insert
|
73
|
-
f1.foo = 'hello, "dude"!'
|
74
|
-
f1.abc = 42
|
75
|
-
t = Time.now
|
76
|
-
f1.z = t
|
77
|
-
f1.bar = 3.14
|
78
|
-
n = if_absent(fb) do |f|
|
79
|
-
f.foo = 'hello, "dude"!'
|
80
|
-
f.abc = 42
|
81
|
-
f.z = t
|
82
|
-
f.bar = 3.14
|
83
|
-
end
|
84
|
-
assert(n.nil?)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_complex_injects
|
88
|
-
fb = Factbase.new
|
89
|
-
f1 = fb.insert
|
90
|
-
f1.foo = 'hello, dude!'
|
91
|
-
f1.abc = 42
|
92
|
-
t = Time.now
|
93
|
-
f1.z = t
|
94
|
-
f1.bar = 3.14
|
95
|
-
n = if_absent(fb) do |f|
|
96
|
-
f.foo = "hello, \\\"dude\\\" \\' \\' ( \n\n ) (! '"
|
97
|
-
f.abc = 42
|
98
|
-
f.z = t + 1
|
99
|
-
f.bar = 3.15
|
100
|
-
end
|
101
|
-
assert(!n.nil?)
|
102
|
-
end
|
103
|
-
end
|
data/test/fb/test_once.rb
DELETED
@@ -1,88 +0,0 @@
|
|
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 NONINFRINGEMENT. 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 'factbase'
|
25
|
-
require_relative '../../lib/judges'
|
26
|
-
require_relative '../../lib/judges/fb/once'
|
27
|
-
|
28
|
-
# Test.
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
31
|
-
# License:: MIT
|
32
|
-
class TestOnce < Minitest::Test
|
33
|
-
def test_touch_once
|
34
|
-
fb = Factbase.new
|
35
|
-
fb.insert
|
36
|
-
assert(!each_once(fb, '(always)', judge: 'something').to_a.empty?)
|
37
|
-
assert(each_once(fb, '(always)', judge: 'something').to_a.empty?)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_seen_property
|
41
|
-
fb = Factbase.new
|
42
|
-
f1 = fb.insert
|
43
|
-
f1.foo = 42
|
44
|
-
assert_equal(1, each_tuple_once(fb, '(eq foo 42)', judge: 'x').to_a.size)
|
45
|
-
assert(each_tuple_once(fb, '(eq foo 42)', judge: 'x').to_a.empty?)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_seen_all_or_nothing
|
49
|
-
fb = Factbase.new
|
50
|
-
f1 = fb.insert
|
51
|
-
f1.a = 1
|
52
|
-
assert(each_tuple_once(fb, '(exists a)', '(exists b)', judge: 'x').to_a.empty?)
|
53
|
-
f2 = fb.insert
|
54
|
-
f2.b = 1
|
55
|
-
assert(!each_tuple_once(fb, '(exists a)', '(exists b)', judge: 'x').to_a.empty?)
|
56
|
-
assert(each_tuple_once(fb, '(exists a)', '(exists b)', judge: 'x').to_a.empty?)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_with_txn
|
60
|
-
fb = Factbase.new
|
61
|
-
f1 = fb.insert
|
62
|
-
f1.foo = 42
|
63
|
-
each_tuple_once(fb, '(exists foo)', judge: 'xx') do |fs|
|
64
|
-
fb.txn do |fbt|
|
65
|
-
f = fbt.insert
|
66
|
-
f.bar = 1
|
67
|
-
end
|
68
|
-
fs[0].xyz = 'hey'
|
69
|
-
end
|
70
|
-
assert_equal(1, fb.query('(exists seen)').each.to_a.size)
|
71
|
-
assert_equal(1, fb.query('(exists bar)').each.to_a.size)
|
72
|
-
assert_equal(1, fb.query('(exists xyz)').each.to_a.size)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_with_chain_txn
|
76
|
-
fb = Factbase.new
|
77
|
-
f1 = fb.insert
|
78
|
-
f1.foo = 42
|
79
|
-
each_tuple_once_txn(fb, '(exists foo)', judge: 'xx') do |fbt, ff|
|
80
|
-
f = fbt.insert
|
81
|
-
f.bar = 1
|
82
|
-
ff.xyz = 'hey'
|
83
|
-
end
|
84
|
-
assert_equal(1, fb.query('(exists seen)').each.to_a.size)
|
85
|
-
assert_equal(1, fb.query('(exists bar)').each.to_a.size)
|
86
|
-
assert_equal(1, fb.query('(exists xyz)').each.to_a.size)
|
87
|
-
end
|
88
|
-
end
|