test/factbase/test_query.rb in factbase-0.0.50 vs test/factbase/test_query.rb in factbase-0.0.51
- old
+ new
@@ -42,13 +42,13 @@
)
end
def test_complex_parsing
maps = []
- maps << { 'num' => 42, 'name' => 'Jeff' }
- maps << { 'pi' => 3.14, 'num' => [42, 66, 0], 'name' => 'peter' }
- maps << { 'time' => Time.now - 100, 'num' => 0, 'hi' => [4], 'nome' => ['Walter'] }
+ maps << { 'num' => [42], 'name' => ['Jeff'] }
+ maps << { 'pi' => [3.14], 'num' => [42, 66, 0], 'name' => ['peter'] }
+ maps << { 'time' => [Time.now - 100], 'num' => [0], 'hi' => [4], 'nome' => ['Walter'] }
{
'(eq num 444)' => 0,
'(eq hi 4)' => 1,
'(eq time 0)' => 0,
'(gt num 60)' => 1,
@@ -63,10 +63,11 @@
'(unique num)' => 2,
'(unique name)' => 2,
'(unique pi)' => 1,
'(many num)' => 1,
'(one num)' => 2,
+ '(nil (agg (exists hello) (min num)))' => 3,
'(gt num (minus 1 (either (at 0 (prev num)) 0)))' => 3,
'(and (not (many num)) (eq num (plus 21 +21)))' => 1,
'(and (not (many num)) (eq num (minus -100 -142)))' => 1,
'(and (one num) (eq num (times 7 6)))' => 1,
'(and (one pi) (eq pi (div -6.28 -2)))' => 1,
@@ -82,39 +83,40 @@
'(lt num (agg (eq num 0) (max pi)))' => 2,
'(eq time (min time))' => 1,
'(and (absent time) (exists pi))' => 1,
"(and (exists time) (not (\t\texists pi)))" => 1,
'(undef something)' => 3,
- "(or (eq num +66) (lt time #{(Time.now - 200).utc.iso8601}))" => 1
+ "(or (eq num +66) (lt time #{(Time.now - 200).utc.iso8601}))" => 1,
+ '(eq 3 (agg (eq num $num) (count)))' => 1
}.each do |q, r|
assert_equal(r, Factbase::Query.new(maps, Mutex.new, q).each.to_a.size, q)
end
end
def test_simple_parsing_with_time
maps = []
now = Time.now.utc
- maps << { 'foo' => now }
+ maps << { 'foo' => [now] }
q = Factbase::Query.new(maps, Mutex.new, "(eq foo #{now.iso8601})")
assert_equal(1, q.each.to_a.size)
end
def test_simple_deleting
maps = []
maps << { 'foo' => [42] }
maps << { 'bar' => [4, 5] }
- maps << { 'bar' => 5 }
+ maps << { 'bar' => [5] }
q = Factbase::Query.new(maps, Mutex.new, '(eq bar 5)')
assert_equal(2, q.delete!)
assert_equal(1, maps.size)
end
def test_deleting_nothing
maps = []
maps << { 'foo' => [42] }
maps << { 'bar' => [4, 5] }
- maps << { 'bar' => 5 }
+ maps << { 'bar' => [5] }
q = Factbase::Query.new(maps, Mutex.new, '(never)')
assert_equal(0, q.delete!)
assert_equal(3, maps.size)
end
@@ -124,10 +126,23 @@
assert_equal(1, Factbase::Query.new(maps, Mutex.new, '(eq foo 42)').each.to_a.size)
end
def test_returns_int
maps = []
- maps << { 'foo' => 1 }
+ maps << { 'foo' => [1] }
q = Factbase::Query.new(maps, Mutex.new, '(eq foo 1)')
assert_equal(1, q.each(&:to_s))
+ end
+
+ def test_with_aliases
+ maps = []
+ maps << { 'foo' => [42] }
+ assert_equal(45, Factbase::Query.new(maps, Mutex.new, '(as bar (plus foo 3))').each.to_a[0].bar)
+ assert_equal(1, maps[0].size)
+ end
+
+ def test_with_nil_alias
+ maps = []
+ maps << { 'foo' => [42] }
+ assert(Factbase::Query.new(maps, Mutex.new, '(as bar (plus xxx 3))').each.to_a[0]['bar'].nil?)
end
end