factbase 0.0.31 → 0.0.32
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/README.md +1 -2
- data/lib/factbase/syntax.rb +1 -1
- data/lib/factbase/term.rb +8 -1
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_inv.rb +1 -1
- data/test/factbase/test_looged.rb +4 -4
- data/test/factbase/test_pre.rb +1 -1
- data/test/factbase/test_query.rb +10 -0
- data/test/factbase/test_syntax.rb +3 -3
- data/test/factbase/test_term.rb +6 -1
- data/test/test_factbase.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e563c36bf3d61f977bbae719a1b6069973a40b28f37ba4e3222f7fbae7091c
|
4
|
+
data.tar.gz: ecd5e6b589ceda68f8a25369e6d7c169500dab90ac6bfca26af5384d0e74bdc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc18cb91cd74af7e9e87b0740b10d1409278ce0dc8a7ea589ef8c45a5b61501dbe0706faf012a49862c911c25859d85a93ad1e6e275421af4c3255bcd5d1b2b
|
7
|
+
data.tar.gz: bf4d812092097c9edb40ccd4aeac447b96906bbdbb515696199f9fa229d8e620ba36b2c80435e1d75115c07e5f2bac6029215df0657d03d51ceb42d053f6652c
|
data/README.md
CHANGED
@@ -56,8 +56,7 @@ assert(f2.query('(eq foo 42)').each.to_a.size == 1)
|
|
56
56
|
|
57
57
|
All terms available in a query:
|
58
58
|
|
59
|
-
* `()`
|
60
|
-
* `(nil)` is false
|
59
|
+
* `(always)` and `(never)` are "true" and "false"
|
61
60
|
* `(not t)` inverses the `t` if it's boolean (exception otherwise)
|
62
61
|
* `(or t1 t2 ...)` returns true if at least one argument is true
|
63
62
|
* `(and t1 t2 ...)` returns true if all arguments are true
|
data/lib/factbase/syntax.rb
CHANGED
data/lib/factbase/term.rb
CHANGED
@@ -43,6 +43,8 @@ class Factbase::Term
|
|
43
43
|
# @return [bool] TRUE if matches
|
44
44
|
def evaluate(fact)
|
45
45
|
send(@op, fact)
|
46
|
+
rescue NoMethodError => _e
|
47
|
+
raise "Term '#{@op}' is not defined"
|
46
48
|
end
|
47
49
|
|
48
50
|
# Put it into the context: let it see the entire array of maps.
|
@@ -87,11 +89,16 @@ class Factbase::Term
|
|
87
89
|
|
88
90
|
private
|
89
91
|
|
90
|
-
def
|
92
|
+
def always(_fact)
|
91
93
|
assert_args(0)
|
92
94
|
true
|
93
95
|
end
|
94
96
|
|
97
|
+
def never(_fact)
|
98
|
+
assert_args(0)
|
99
|
+
false
|
100
|
+
end
|
101
|
+
|
95
102
|
def not(fact)
|
96
103
|
assert_args(1)
|
97
104
|
!only_bool(the_value(0, fact))
|
data/lib/factbase.rb
CHANGED
data/test/factbase/test_inv.rb
CHANGED
@@ -48,19 +48,19 @@ class TestLooged < Minitest::Test
|
|
48
48
|
fb = Factbase.new
|
49
49
|
fb.insert
|
50
50
|
fb.insert
|
51
|
-
assert_equal(2, Factbase::Looged.new(fb, Loog::NULL).query('()').each(&:to_s))
|
51
|
+
assert_equal(2, Factbase::Looged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_returns_int_when_empty
|
55
55
|
fb = Factbase.new
|
56
|
-
assert_equal(0, Factbase::Looged.new(fb, Loog::NULL).query('()').each(&:to_s))
|
56
|
+
assert_equal(0, Factbase::Looged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_logs_when_enumerator
|
60
60
|
fb = Factbase::Looged.new(Factbase.new, Loog::NULL)
|
61
|
-
assert_equal(0, fb.query('()').each.to_a.size)
|
61
|
+
assert_equal(0, fb.query('(always)').each.to_a.size)
|
62
62
|
fb.insert
|
63
|
-
assert_equal(1, fb.query('()').each.to_a.size)
|
63
|
+
assert_equal(1, fb.query('(always)').each.to_a.size)
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_proper_logging
|
data/test/factbase/test_pre.rb
CHANGED
data/test/factbase/test_query.rb
CHANGED
@@ -90,6 +90,16 @@ class TestQuery < Minitest::Test
|
|
90
90
|
assert_equal(1, maps.size)
|
91
91
|
end
|
92
92
|
|
93
|
+
def test_deleting_nothing
|
94
|
+
maps = []
|
95
|
+
maps << { 'foo' => [42] }
|
96
|
+
maps << { 'bar' => [4, 5] }
|
97
|
+
maps << { 'bar' => 5 }
|
98
|
+
q = Factbase::Query.new(maps, Mutex.new, '(never)')
|
99
|
+
assert_equal(0, q.delete!)
|
100
|
+
assert_equal(3, maps.size)
|
101
|
+
end
|
102
|
+
|
93
103
|
def test_to_array
|
94
104
|
maps = []
|
95
105
|
maps << { 'foo' => [42] }
|
@@ -41,13 +41,12 @@ class TestSyntax < Minitest::Test
|
|
41
41
|
|
42
42
|
def test_simple_parsing
|
43
43
|
[
|
44
|
-
'()',
|
45
44
|
'(foo)',
|
46
45
|
'(foo (bar) (zz 77) )',
|
47
46
|
"(eq foo \n\n 'Hello, world!'\n)\n",
|
48
47
|
"(eq x 'Hello, \\' \n) \\' ( world!')",
|
49
48
|
"# this is a comment\n(eq foo # test\n 42)\n\n# another comment\n",
|
50
|
-
"(or ( a 4) (b 5) () (and () (c 5) \t\t(r 7 w8s w8is 'Foo')))"
|
49
|
+
"(or ( a 4) (b 5) (always) (and (always) (c 5) \t\t(r 7 w8s w8is 'Foo')))"
|
51
50
|
].each do |q|
|
52
51
|
Factbase::Syntax.new(q).to_term
|
53
52
|
end
|
@@ -67,7 +66,7 @@ class TestSyntax < Minitest::Test
|
|
67
66
|
'(eq t 2024-05-25T19:43:48Z)',
|
68
67
|
'(eq t 3.1415926)',
|
69
68
|
'(eq t 3.0e+21)',
|
70
|
-
"(foo (x (f (t (y 42 'Hey you'))) (
|
69
|
+
"(foo (x (f (t (y 42 'Hey you'))) (never) (r 3)) y z)"
|
71
70
|
].each do |q|
|
72
71
|
assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
|
73
72
|
end
|
@@ -91,6 +90,7 @@ class TestSyntax < Minitest::Test
|
|
91
90
|
def test_broken_syntax
|
92
91
|
[
|
93
92
|
'',
|
93
|
+
'()',
|
94
94
|
'(foo',
|
95
95
|
'(foo 1) (bar 2)',
|
96
96
|
'some text',
|
data/test/factbase/test_term.rb
CHANGED
@@ -82,8 +82,13 @@ class TestTerm < Minitest::Test
|
|
82
82
|
assert(!t.evaluate(fact('bar' => [100])))
|
83
83
|
end
|
84
84
|
|
85
|
+
def test_false_matching
|
86
|
+
t = Factbase::Term.new(:never, [])
|
87
|
+
assert(!t.evaluate(fact('foo' => [100])))
|
88
|
+
end
|
89
|
+
|
85
90
|
def test_not_matching
|
86
|
-
t = Factbase::Term.new(:not, [Factbase::Term.new(:
|
91
|
+
t = Factbase::Term.new(:not, [Factbase::Term.new(:always, [])])
|
87
92
|
assert(!t.evaluate(fact('foo' => [100])))
|
88
93
|
end
|
89
94
|
|
data/test/test_factbase.rb
CHANGED
@@ -107,7 +107,7 @@ class TestFactbase < Minitest::Test
|
|
107
107
|
|
108
108
|
def test_all_decorators
|
109
109
|
[
|
110
|
-
Factbase::Rules.new(Factbase.new, '()'),
|
110
|
+
Factbase::Rules.new(Factbase.new, '(always)'),
|
111
111
|
Factbase::Inv.new(Factbase.new) { |_, _| true },
|
112
112
|
Factbase::Pre.new(Factbase.new) { |_| true },
|
113
113
|
Factbase::Looged.new(Factbase.new, Loog::NULL),
|
@@ -126,7 +126,7 @@ class TestFactbase < Minitest::Test
|
|
126
126
|
end
|
127
127
|
d.import(d.export)
|
128
128
|
assert_equal(4, d.size)
|
129
|
-
assert_equal(4, d.query('()').each.to_a.size)
|
129
|
+
assert_equal(4, d.query('(always)').each.to_a.size)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|