-
Notifications
You must be signed in to change notification settings - Fork 0
/
ease64_test.rb
98 lines (85 loc) · 2.21 KB
/
ease64_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'minitest/autorun'
require 'minitest/pride' # Optional.
require_relative 'ease64'
class Ease64Test < Minitest::Test
# ENCODE TESTS
def test_encode_one_char
# skip
enc = Ease64.encode64('A')
assert_equal 'HH', enc
end
def test_encode_word
# skip
enc = Ease64.encode64('Hello')
assert_equal 'IAeMalMx', enc
end
# DECODE TESTS
def test_decode_one_char
# skip
plain = Ease64.decode64('HH')
assert_equal 'A', plain
end
def test_decode_word
# skip
plain = Ease64.decode64('IAeMalMx')
assert_equal 'Hello', plain
end
def test_decode_anything
# skip
plain = Ease64.decode64('anything')
assert_equal "\r\xB9\xA5)t\a", plain
end
# ENCODE + DECODE TESTS
def test_handle_one_null_char
# skip
plain = "\x00"
enc = Ease64.encode64(plain)
assert_equal plain, Ease64.decode64(enc)
end
def test_handle_null_chars
# skip
null_char = "\x00"
6.times do |n|
plain = null_char * (n + 1)
enc = Ease64.encode64(plain)
assert_equal plain, Ease64.decode64(enc)
end
end
def test_handle_visible_ascii_chars
# skip
ascii_string = [*' '..'~'].shuffle.join
enc = Ease64.encode64(ascii_string)
assert_equal ascii_string, Ease64.decode64(enc)
end
def test_handle_accents
# skip
plain = 'áéíóúâêîôûäëïöüâàèìòùñ¡'
enc = Ease64.encode64(plain)
assert_equal plain.encoding, Ease64.decode64(enc).encoding
assert_equal plain, Ease64.decode64(enc)
end
def test_unicode
# skip
plain = "Two robots: 🤖\u{1f916}"
enc = Ease64.encode64(plain)
assert_equal Encoding::UTF_8, Ease64.decode64(enc).encoding
assert_equal plain, Ease64.decode64(enc)
end
def test_handle_data
# skip
data = ''
256.times { data.concat rand(256).chr }
enc = Ease64.encode64(data)
assert_equal data.force_encoding('UTF-8'), Ease64.decode64(enc)
end
def test_handle_arbitrary_sized_data
# skip
16.times do |i|
data = ''
i.times { data.concat rand(256).chr }
enc = Ease64.encode64(data)
assert_equal data.force_encoding('UTF-8'), Ease64.decode64(enc),
"Ease64 should handle data of size #{i}."
end
end
end