tins 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/tins/null.rb +1 -1
- data/lib/tins/version.rb +1 -1
- data/lib/tins/xt.rb +1 -0
- data/tests/bijection_test.rb +19 -0
- data/tests/blank_full_test.rb +46 -0
- data/tests/count_by_test.rb +17 -0
- data/tests/deep_dup_test.rb +20 -0
- data/tests/{tins_file_binary_test.rb → file_binary_test.rb} +1 -1
- data/tests/generator_test.rb +47 -0
- data/tests/hash_symbolize_keys_recursive_test.rb +24 -0
- data/tests/hash_union_test.rb +42 -0
- data/tests/limited_test.rb +25 -0
- data/tests/{tins_lines_file_test.rb → lines_file_test.rb} +0 -0
- data/tests/{tins_memoize_test.rb → memoize_test.rb} +1 -1
- data/tests/minimize_test.rb +54 -0
- data/tests/module_group_test.rb +29 -0
- data/tests/named_test.rb +32 -0
- data/tests/null_test.rb +19 -0
- data/tests/partial_application_test.rb +30 -0
- data/tests/range_plus_test.rb +14 -0
- data/tests/require_maybe_test.rb +24 -0
- data/tests/round_test.rb +32 -0
- data/tests/{tins_secure_write_test.rb → secure_write_test.rb} +0 -0
- data/tests/shuffle_test.rb +30 -0
- data/tests/string_camelize_test.rb +21 -0
- data/tests/string_underscore_test.rb +11 -0
- data/tests/string_version_test.rb +31 -0
- data/tests/subhash_test.rb +29 -0
- data/tests/test_helper.rb +6 -2
- data/tests/time_dummy_test.rb +18 -0
- data/tests/try_test.rb +34 -0
- data/tests/uniq_by_test.rb +31 -0
- data/tins.gemspec +5 -5
- metadata +109 -60
- data/tests/tins_test.rb +0 -651
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ GemHadar do
|
|
11
11
|
description 'All the stuff that isn\'t good/big enough for a real library.'
|
12
12
|
test_dir 'tests'
|
13
13
|
test_files.concat Dir["#{test_dir}/*_test.rb"]
|
14
|
-
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc'
|
14
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage'
|
15
15
|
readme 'README.rdoc'
|
16
16
|
development_dependency 'test-unit', '~>2.3'
|
17
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
data/lib/tins/null.rb
CHANGED
data/lib/tins/version.rb
CHANGED
data/lib/tins/xt.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class BijectionTest < Test::Unit::TestCase
|
6
|
+
def test_bijection
|
7
|
+
assert_equal [ [ 1, 2 ], [ 3, 4 ] ], Tins::Bijection[ 1, 2, 3, 4 ].to_a.sort
|
8
|
+
assert_raise(ArgumentError) do
|
9
|
+
Tins::Bijection[1,2,3]
|
10
|
+
end
|
11
|
+
assert_raise(ArgumentError) do
|
12
|
+
Tins::Bijection[1,2,3,2]
|
13
|
+
end
|
14
|
+
assert_raise(ArgumentError) do
|
15
|
+
Tins::Bijection[1,2,1,3]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Tins
|
6
|
+
class BlankFullTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_blank
|
9
|
+
assert !true.blank?
|
10
|
+
assert false.blank?
|
11
|
+
assert nil.blank?
|
12
|
+
assert [].blank?
|
13
|
+
assert ![23].blank?
|
14
|
+
assert Set[].blank?
|
15
|
+
assert !Set[23].blank?
|
16
|
+
assert({}.blank?)
|
17
|
+
assert !{ :foo => 23 }.blank?
|
18
|
+
assert "".blank?
|
19
|
+
assert " ".blank?
|
20
|
+
assert !"foo".blank?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_full
|
24
|
+
assert_equal true, true.full?
|
25
|
+
assert_nil false.full?
|
26
|
+
assert_nil nil.full?
|
27
|
+
assert_nil [].full?
|
28
|
+
assert_equal [ 23 ], [ 23 ].full?
|
29
|
+
assert_nil Set[].full?
|
30
|
+
assert_equal Set[23], Set[23].full?
|
31
|
+
assert_nil({}.full?)
|
32
|
+
assert_equal({ :foo => 23 }, { :foo => 23 }.full?)
|
33
|
+
assert_nil "".full?
|
34
|
+
assert_nil " ".full?
|
35
|
+
assert_equal "foo", "foo".full?
|
36
|
+
assert_nil " ".full?(&:size)
|
37
|
+
assert_equal 3, "foo".full?(&:size)
|
38
|
+
assert_nil " ".full?(&:size)
|
39
|
+
assert_equal 3, "foo".full?(&:size)
|
40
|
+
assert_nil " ".full?(:size)
|
41
|
+
assert_equal 3, "foo".full?(:size)
|
42
|
+
assert_nil " ".full?(:size)
|
43
|
+
assert_equal 3, "foo".full?(:size)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class CountByTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_count_by
|
8
|
+
assert_equal 0, [].count_by { |x| x % 2 == 0 }
|
9
|
+
assert_equal 0, [ 1 ].count_by { |x| x % 2 == 0 }
|
10
|
+
assert_equal 1, [ 1 ].count_by { |x| x % 2 == 1 }
|
11
|
+
assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 0 }
|
12
|
+
assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 1 }
|
13
|
+
assert_equal 2, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 0 }
|
14
|
+
assert_equal 3, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 1 }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class DeepDupTest < Test::Unit::TestCase
|
6
|
+
def test_deep_dup
|
7
|
+
a = [1,2,3]
|
8
|
+
assert_equal a, a.deep_dup
|
9
|
+
assert_not_same a, a.deep_dup
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_deep_dup_proc
|
13
|
+
f = lambda { |x| 2 * x }
|
14
|
+
g = f.deep_dup
|
15
|
+
assert_equal f[3], g[3]
|
16
|
+
assert_equal f, g
|
17
|
+
assert_same f, g
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class GeneratorTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@numeric = [ 1, 2, 3 ]
|
8
|
+
@string = %w[a b c]
|
9
|
+
@chars = 'abc'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_generator
|
13
|
+
g = Tins::Generator[@numeric, @string]
|
14
|
+
assert_equal 2, g.size
|
15
|
+
g.add_dimension(@chars, :each_byte)
|
16
|
+
assert_equal 3, g.size
|
17
|
+
assert_equal\
|
18
|
+
[[1, "a", 97],
|
19
|
+
[1, "a", 98],
|
20
|
+
[1, "a", 99],
|
21
|
+
[1, "b", 97],
|
22
|
+
[1, "b", 98],
|
23
|
+
[1, "b", 99],
|
24
|
+
[1, "c", 97],
|
25
|
+
[1, "c", 98],
|
26
|
+
[1, "c", 99],
|
27
|
+
[2, "a", 97],
|
28
|
+
[2, "a", 98],
|
29
|
+
[2, "a", 99],
|
30
|
+
[2, "b", 97],
|
31
|
+
[2, "b", 98],
|
32
|
+
[2, "b", 99],
|
33
|
+
[2, "c", 97],
|
34
|
+
[2, "c", 98],
|
35
|
+
[2, "c", 99],
|
36
|
+
[3, "a", 97],
|
37
|
+
[3, "a", 98],
|
38
|
+
[3, "a", 99],
|
39
|
+
[3, "b", 97],
|
40
|
+
[3, "b", 98],
|
41
|
+
[3, "b", 99],
|
42
|
+
[3, "c", 97],
|
43
|
+
[3, "c", 98],
|
44
|
+
[3, "c", 99]], g.to_a
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class HashSymbolizeKeysRecursiveTest < Test::Unit::TestCase
|
6
|
+
require 'tins/xt/hash_symbolize_keys_recursive'
|
7
|
+
|
8
|
+
def test_symbolize
|
9
|
+
hash = {
|
10
|
+
'key' => [
|
11
|
+
{
|
12
|
+
'key' => {
|
13
|
+
'key' => true
|
14
|
+
}
|
15
|
+
}
|
16
|
+
],
|
17
|
+
}
|
18
|
+
hash2 = hash.symbolize_keys_recursive
|
19
|
+
assert hash2[:key][0][:key][:key]
|
20
|
+
hash.symbolize_keys_recursive!
|
21
|
+
assert hash[:key][0][:key][:key]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class HashUnionTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
class HashLike1
|
8
|
+
def to_hash
|
9
|
+
{ 'foo' => true }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class HashLike2
|
14
|
+
def to_h
|
15
|
+
{ 'foo' => true }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_union
|
20
|
+
defaults = { 'foo' => true, 'bar' => false, 'quux' => nil }
|
21
|
+
hash = { 'foo' => false }
|
22
|
+
assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
|
23
|
+
(hash | defaults).sort
|
24
|
+
hash |= defaults
|
25
|
+
assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
|
26
|
+
hash.sort
|
27
|
+
hash = { 'foo' => false }
|
28
|
+
hash |= {
|
29
|
+
'quux' => true,
|
30
|
+
'baz' => 23,
|
31
|
+
} | defaults
|
32
|
+
assert_equal [ ['bar', false], [ 'baz', 23 ], ['foo', false],
|
33
|
+
['quux', true] ],
|
34
|
+
hash.sort
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_hash_conversion
|
38
|
+
assert_equal({ 'foo' => true }, { } | HashLike1.new)
|
39
|
+
assert_equal({ 'foo' => true }, { } | HashLike2.new)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class LimitedTest < Test::Unit::TestCase
|
6
|
+
class ::Array
|
7
|
+
include Tins::Shuffle
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_limited
|
11
|
+
count = {}
|
12
|
+
limited = Tins::Limited.new(5)
|
13
|
+
5.times do
|
14
|
+
limited.execute do
|
15
|
+
count[Thread.current] = true
|
16
|
+
sleep
|
17
|
+
end
|
18
|
+
end
|
19
|
+
until count.size >= 5
|
20
|
+
sleep 0.1
|
21
|
+
end
|
22
|
+
assert_equal 5, count.keys.uniq.size
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class MinimizeTest < Test::Unit::TestCase
|
6
|
+
class ::Array
|
7
|
+
include Tins::Minimize
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_minimize
|
11
|
+
assert_equal [], [].minimize
|
12
|
+
assert_equal [ 1..1 ], [ 1 ].minimize
|
13
|
+
assert_equal [ 1..2 ], [ 1, 2 ].minimize
|
14
|
+
assert_equal [ 1..1, 7..7 ], [ 1, 7 ].minimize
|
15
|
+
assert_equal [ 1..3, 7..7, 11..14 ],
|
16
|
+
[ 1, 2, 3, 7, 11, 12, 13, 14 ].minimize
|
17
|
+
assert_equal [ 'A'..'C', 'G'..'G', 'K'..'M' ],
|
18
|
+
[ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ].minimize
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_minimize!
|
22
|
+
assert_equal [], [].minimize!
|
23
|
+
assert_equal [ 1..1 ], [ 1 ].minimize!
|
24
|
+
assert_equal [ 1..2 ], [ 1, 2 ].minimize!
|
25
|
+
assert_equal [ 1..1, 7..7 ], [ 1, 7 ].minimize!
|
26
|
+
assert_equal [ 1..3, 7..7, 11..14 ],
|
27
|
+
[ 1, 2, 3, 7, 11, 12, 13, 14 ].minimize!
|
28
|
+
assert_equal [ 'A'..'C', 'G'..'G', 'K'..'M' ],
|
29
|
+
[ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ].minimize!
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_unminimize
|
33
|
+
assert_equal [], [].unminimize
|
34
|
+
assert_equal [ 1 ], [ 1..1 ].unminimize
|
35
|
+
assert_equal [ 1, 2 ], [ 1..2 ].unminimize
|
36
|
+
assert_equal [ 1, 7 ], [ 1..1, 7..7 ].unminimize
|
37
|
+
assert_equal [ 1, 2, 3, 7, 11, 12, 13, 14 ],
|
38
|
+
[ 1..3, 7..7, 11..14 ].unminimize
|
39
|
+
assert_equal [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ],
|
40
|
+
[ 'A'..'C', 'G'..'G', 'K'..'M' ].unminimize
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_unminimize!
|
44
|
+
assert_equal [], [].unminimize!
|
45
|
+
assert_equal [ 1 ], [ 1..1 ].unminimize!
|
46
|
+
assert_equal [ 1, 2 ], [ 1..2 ].unminimize!
|
47
|
+
assert_equal [ 1, 7 ], [ 1..1, 7..7 ].unminimize!
|
48
|
+
assert_equal [ 1, 2, 3, 7, 11, 12, 13, 14 ],
|
49
|
+
[ 1..3, 7..7, 11..14 ].unminimize!
|
50
|
+
assert_equal [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ],
|
51
|
+
[ 'A'..'C', 'G'..'G', 'K'..'M' ].unminimize!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class ModuleGroupTest < Test::Unit::TestCase
|
6
|
+
MyClasses = Tins::ModuleGroup[ Array, String, Hash ]
|
7
|
+
|
8
|
+
def test_module_group
|
9
|
+
assert MyClasses === []
|
10
|
+
assert MyClasses === ""
|
11
|
+
assert MyClasses === {}
|
12
|
+
assert !(MyClasses === :nix)
|
13
|
+
case []
|
14
|
+
when MyClasses
|
15
|
+
assert true
|
16
|
+
when Array
|
17
|
+
assert false
|
18
|
+
end
|
19
|
+
case :nix
|
20
|
+
when MyClasses
|
21
|
+
assert false
|
22
|
+
when Array
|
23
|
+
assert false
|
24
|
+
when Symbol
|
25
|
+
assert true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/tests/named_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class NamedTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_named_simple
|
8
|
+
a = [ 1, 2, 3 ]
|
9
|
+
a.named(:plus1, :map) { |x| x + 1 }
|
10
|
+
assert_equal [ 2, 3, 4 ], a.plus1
|
11
|
+
Array.named(:odd, :select) { |x| x % 2 == 1 }
|
12
|
+
assert_equal [ 3 ], a.plus1.odd
|
13
|
+
end
|
14
|
+
|
15
|
+
if RUBY_VERSION >= '1.9'
|
16
|
+
def foo(x, y, &block)
|
17
|
+
block.call x * y
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_more_complex
|
21
|
+
Object.named(:foo_with_block, :foo) do |z|
|
22
|
+
z ** 2
|
23
|
+
end
|
24
|
+
assert_equal foo(2, 3) { |z| z ** 2 }, foo_with_block(2, 3)
|
25
|
+
Object.named(:foo_23, :foo, 2, 3)
|
26
|
+
assert_equal foo(2, 3) { |z| z ** 2 }, foo_23 { |z| z ** 2 }
|
27
|
+
Object.named(:foo_2, :foo, 2)
|
28
|
+
assert_equal foo(2, 3) { |z| z ** 2 }, foo_2(3) { |z| z ** 2 }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/tests/null_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class NullTest < Test::Unit::TestCase
|
6
|
+
require 'tins/xt/null'
|
7
|
+
|
8
|
+
def test_null
|
9
|
+
assert_equal NULL, NULL.foo
|
10
|
+
assert_equal NULL, NULL.foo.bar
|
11
|
+
assert_equal 'NULL', NULL.inspect
|
12
|
+
assert_equal '', NULL.to_s
|
13
|
+
assert_equal 1, Null(1)
|
14
|
+
assert_equal NULL, Null(nil)
|
15
|
+
assert_equal NULL, NULL::NULL
|
16
|
+
assert NULL.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|