Skip to content

Commit 6ff3f67

Browse files
committed
Cleanup encoding tests
1 parent 787462e commit 6ff3f67

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

test/helper.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ def silent
6161
end
6262
end
6363

64-
def with_external_encoding(encoding)
65-
original_encoding = Encoding.default_external
66-
67-
begin
68-
silent { Encoding.default_external = Encoding.find(encoding) }
69-
yield
70-
ensure
71-
silent { Encoding.default_external = original_encoding }
72-
end
73-
end
74-
7564
class Version
7665
include Comparable
7766

test/lint/strings.rb

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ def test_set_and_get_with_non_string_value
2727
end
2828

2929
def test_set_and_get_with_ascii_characters
30-
with_external_encoding("ASCII-8BIT") do
31-
(0..255).each do |i|
32-
str = "#{i.chr}---#{i.chr}"
33-
r.set("foo", str)
30+
(0..255).each do |i|
31+
str = "#{i.chr}---#{i.chr}"
32+
r.set("foo", str)
3433

35-
assert_equal str, r.get("foo")
36-
end
34+
assert_equal str, r.get("foo")
3735
end
3836
end
3937

@@ -363,23 +361,21 @@ def test_msetnx_mapped
363361
end
364362

365363
def test_bitop
366-
with_external_encoding('UTF-8') do
367-
r.set('foo{1}', 'a')
368-
r.set('bar{1}', 'b')
369-
370-
r.bitop(:and, 'foo&bar{1}', 'foo{1}', 'bar{1}')
371-
assert_equal "\x60", r.get('foo&bar{1}')
372-
373-
r.bitop(:and, 'foo&bar{1}', ['foo{1}', 'bar{1}'])
374-
assert_equal "\x60", r.get('foo&bar{1}')
375-
376-
r.bitop(:or, 'foo|bar{1}', 'foo{1}', 'bar{1}')
377-
assert_equal "\x63", r.get('foo|bar{1}')
378-
r.bitop(:xor, 'foo^bar{1}', 'foo{1}', 'bar{1}')
379-
assert_equal "\x03", r.get('foo^bar{1}')
380-
r.bitop(:not, '~foo{1}', 'foo{1}')
381-
assert_equal "\x9E".b, r.get('~foo{1}')
382-
end
364+
r.set('foo{1}', 'a')
365+
r.set('bar{1}', 'b')
366+
367+
r.bitop(:and, 'foo&bar{1}', 'foo{1}', 'bar{1}')
368+
assert_equal "\x60", r.get('foo&bar{1}')
369+
370+
r.bitop(:and, 'foo&bar{1}', ['foo{1}', 'bar{1}'])
371+
assert_equal "\x60", r.get('foo&bar{1}')
372+
373+
r.bitop(:or, 'foo|bar{1}', 'foo{1}', 'bar{1}')
374+
assert_equal "\x63", r.get('foo|bar{1}')
375+
r.bitop(:xor, 'foo^bar{1}', 'foo{1}', 'bar{1}')
376+
assert_equal "\x03", r.get('foo^bar{1}')
377+
r.bitop(:not, '~foo{1}', 'foo{1}')
378+
assert_equal "\x9E".b, r.get('~foo{1}')
383379
end
384380
end
385381
end

test/redis/encoding_test.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ class TestEncoding < Minitest::Test
66
include Helper::Client
77

88
def test_returns_properly_encoded_strings
9-
with_external_encoding("UTF-8") do
10-
r.set "foo", "שלום"
9+
r.set "foo", "שלום"
1110

12-
assert_equal "Shalom שלום", "Shalom #{r.get('foo')}"
13-
end
11+
assert_equal "Shalom שלום", "Shalom #{r.get('foo')}"
12+
13+
refute_predicate "\xFF", :valid_encoding?
14+
r.set("bar", "\xFF")
15+
bytes = r.get("bar")
16+
assert_equal "\xFF".b, bytes
17+
assert_predicate bytes, :valid_encoding?
1418
end
1519
end

0 commit comments

Comments
 (0)