Skip to content

Commit 3fb09d1

Browse files
committed
Ignore external encoding when testing BITOP.
Should fix #345.
1 parent e211afa commit 3fb09d1

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

test/commands_on_strings_test.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,20 @@ def test_msetnx_mapped
8282
end
8383

8484
def test_bitop
85-
target_version "2.5.10" do
86-
r.set("foo", "a")
87-
r.set("bar", "b")
88-
89-
r.bitop(:and, "foo&bar", "foo", "bar")
90-
assert_equal "\x60", r.get("foo&bar")
91-
r.bitop(:or, "foo|bar", "foo", "bar")
92-
assert_equal "\x63", r.get("foo|bar")
93-
r.bitop(:xor, "foo^bar", "foo", "bar")
94-
assert_equal "\x03", r.get("foo^bar")
95-
r.bitop(:not, "~foo", "foo")
96-
assert_equal "\x9E", r.get("~foo")
85+
try_encoding("UTF-8") do
86+
target_version "2.5.10" do
87+
r.set("foo", "a")
88+
r.set("bar", "b")
89+
90+
r.bitop(:and, "foo&bar", "foo", "bar")
91+
assert_equal "\x60", r.get("foo&bar")
92+
r.bitop(:or, "foo|bar", "foo", "bar")
93+
assert_equal "\x63", r.get("foo|bar")
94+
r.bitop(:xor, "foo^bar", "foo", "bar")
95+
assert_equal "\x03", r.get("foo^bar")
96+
r.bitop(:not, "~foo", "foo")
97+
assert_equal "\x9E", r.get("~foo")
98+
end
9799
end
98100
end
99101
end

test/helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def with_external_encoding(encoding)
9191
end
9292
end
9393

94+
def try_encoding(encoding, &block)
95+
if defined?(Encoding)
96+
with_external_encoding(encoding, &block)
97+
else
98+
yield
99+
end
100+
end
101+
94102
class Version
95103

96104
include Comparable

0 commit comments

Comments
 (0)