aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-01-06 14:22:11 -0200
committerRafael França <rafaelmfranca@gmail.com>2016-01-06 14:22:11 -0200
commitb0338475babfb8388691c8f6b0af674707a6a70e (patch)
treede75f21653caf477e4059db9ea50a1c12ec391a7 /test/visitors
parentffc4b8e93af4356110c7a2573cc3340145baa02b (diff)
parentc22abda79b7f0fbee5f0ef0e9648d52d7d483902 (diff)
downloadrails-b0338475babfb8388691c8f6b0af674707a6a70e.tar.gz
rails-b0338475babfb8388691c8f6b0af674707a6a70e.tar.bz2
rails-b0338475babfb8388691c8f6b0af674707a6a70e.zip
Merge pull request #408 from sjaveed/bitwise_operations
Support for Bitwise Operations as InfixOperations
Diffstat (limited to 'test/visitors')
-rw-r--r--test/visitors/test_to_sql.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 4162d970b5..6da86c2dee 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -475,6 +475,31 @@ module Arel
compile(node).must_equal %("users"."name" || "users"."name")
end
+ it "should handle BitwiseAnd" do
+ node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) & 16
+ compile(node).must_equal %(("products"."bitmap" & 16))
+ end
+
+ it "should handle BitwiseOr" do
+ node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) | 16
+ compile(node).must_equal %(("products"."bitmap" | 16))
+ end
+
+ it "should handle BitwiseXor" do
+ node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) ^ 16
+ compile(node).must_equal %(("products"."bitmap" ^ 16))
+ end
+
+ it "should handle BitwiseShiftLeft" do
+ node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) << 4
+ compile(node).must_equal %(("products"."bitmap" << 4))
+ end
+
+ it "should handle BitwiseShiftRight" do
+ node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) >> 4
+ compile(node).must_equal %(("products"."bitmap" >> 4))
+ end
+
it "should handle arbitrary operators" do
node = Arel::Nodes::InfixOperation.new(
'&&',
@@ -485,6 +510,18 @@ module Arel
end
end
+ describe "Nodes::UnaryOperation" do
+ it "should handle BitwiseNot" do
+ node = ~ Arel::Attributes::Integer.new(Table.new(:products), :bitmap)
+ compile(node).must_equal %( ~ "products"."bitmap")
+ end
+
+ it "should handle arbitrary operators" do
+ node = Arel::Nodes::UnaryOperation.new('!', Arel::Attributes::String.new(Table.new(:products), :active))
+ compile(node).must_equal %( ! "products"."active")
+ end
+ end
+
describe "Nodes::NotIn" do
it "should know how to visit" do
node = @attr.not_in [1, 2, 3]