tins 1.32.0 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.contexts/code_comment.rb +23 -0
- data/.contexts/full.rb +31 -0
- data/.contexts/lib.rb +24 -0
- data/.contexts/yard.md +92 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/CHANGES.md +194 -0
- data/README.md +161 -90
- data/Rakefile +23 -19
- data/examples/let.rb +8 -40
- data/examples/mail.rb +0 -1
- data/examples/ones_difference.stm +0 -1
- data/examples/turing.rb +3 -1
- data/lib/tins/alias.rb +1 -0
- data/lib/tins/annotate.rb +37 -27
- data/lib/tins/ask_and_send.rb +41 -0
- data/lib/tins/attempt.rb +39 -0
- data/lib/tins/bijection.rb +34 -0
- data/lib/tins/case_predicate.rb +21 -0
- data/lib/tins/complete.rb +16 -0
- data/lib/tins/concern.rb +100 -0
- data/lib/tins/date_dummy.rb +36 -4
- data/lib/tins/date_time_dummy.rb +34 -2
- data/lib/tins/deep_dup.rb +9 -2
- data/lib/tins/deprecate.rb +27 -0
- data/lib/tins/dslkit.rb +563 -59
- data/lib/tins/duration.rb +160 -3
- data/lib/tins/expose.rb +54 -5
- data/lib/tins/extract_last_argument_options.rb +9 -0
- data/lib/tins/file_binary.rb +108 -25
- data/lib/tins/find.rb +114 -11
- data/lib/tins/generator.rb +10 -2
- data/lib/tins/go.rb +81 -4
- data/lib/tins/hash_bfs.rb +69 -0
- data/lib/tins/hash_symbolize_keys_recursive.rb +62 -4
- data/lib/tins/hash_union.rb +47 -2
- data/lib/tins/if_predicate.rb +31 -0
- data/lib/tins/implement.rb +50 -0
- data/lib/tins/limited.rb +105 -29
- data/lib/tins/lines_file.rb +81 -2
- data/lib/tins/lru_cache.rb +54 -17
- data/lib/tins/memoize.rb +86 -58
- data/lib/tins/method_description.rb +87 -4
- data/lib/tins/minimize.rb +39 -11
- data/lib/tins/module_group.rb +27 -2
- data/lib/tins/named_set.rb +20 -0
- data/lib/tins/null.rb +86 -15
- data/lib/tins/once.rb +61 -4
- data/lib/tins/p.rb +44 -8
- data/lib/tins/partial_application.rb +66 -7
- data/lib/tins/proc_compose.rb +58 -1
- data/lib/tins/proc_prelude.rb +97 -10
- data/lib/tins/range_plus.rb +30 -2
- data/lib/tins/require_maybe.rb +36 -0
- data/lib/tins/responding.rb +39 -0
- data/lib/tins/secure_write.rb +25 -5
- data/lib/tins/sexy_singleton.rb +46 -48
- data/lib/tins/string_byte_order_mark.rb +33 -2
- data/lib/tins/string_camelize.rb +31 -2
- data/lib/tins/string_named_placeholders.rb +70 -0
- data/lib/tins/string_underscore.rb +33 -2
- data/lib/tins/string_version.rb +183 -10
- data/lib/tins/subhash.rb +35 -10
- data/lib/tins/temp_io.rb +7 -0
- data/lib/tins/temp_io_enum.rb +19 -0
- data/lib/tins/terminal.rb +34 -12
- data/lib/tins/thread_local.rb +69 -11
- data/lib/tins/time_dummy.rb +47 -21
- data/lib/tins/to.rb +15 -0
- data/lib/tins/to_proc.rb +17 -4
- data/lib/tins/token.rb +61 -2
- data/lib/tins/unit.rb +288 -149
- data/lib/tins/version.rb +1 -1
- data/lib/tins/write.rb +14 -3
- data/lib/tins/xt/blank.rb +81 -2
- data/lib/tins/xt/concern.rb +51 -0
- data/lib/tins/xt/deep_dup.rb +4 -2
- data/lib/tins/xt/deprecate.rb +5 -0
- data/lib/tins/xt/full.rb +56 -11
- data/lib/tins/xt/hash_bfs.rb +7 -0
- data/lib/tins/xt/irb.rb +46 -2
- data/lib/tins/xt/method_description.rb +0 -12
- data/lib/tins/xt/minimize.rb +7 -0
- data/lib/tins/xt/named.rb +71 -16
- data/lib/tins/xt/proc_compose.rb +4 -0
- data/lib/tins/xt/secure_write.rb +0 -4
- data/lib/tins/xt/string.rb +1 -0
- data/lib/tins/xt/string_camelize.rb +4 -2
- data/lib/tins/xt/string_named_placeholders.rb +7 -0
- data/lib/tins/xt/string_underscore.rb +4 -2
- data/lib/tins/xt/subhash.rb +11 -0
- data/lib/tins/xt/time_freezer.rb +43 -6
- data/lib/tins/xt/write.rb +0 -4
- data/lib/tins/xt.rb +3 -3
- data/lib/tins.rb +19 -3
- data/tests/annotate_test.rb +0 -1
- data/tests/bijection_test.rb +0 -1
- data/tests/concern_test.rb +63 -4
- data/tests/date_dummy_test.rb +0 -1
- data/tests/date_time_dummy_test.rb +0 -1
- data/tests/delegate_test.rb +0 -1
- data/tests/deprecate_test.rb +41 -0
- data/tests/dslkit_test.rb +15 -1
- data/tests/duration_test.rb +23 -2
- data/tests/dynamic_scope_test.rb +0 -1
- data/tests/extract_last_argument_options_test.rb +0 -1
- data/tests/find_test.rb +0 -1
- data/tests/from_module_test.rb +30 -3
- data/tests/generator_test.rb +0 -1
- data/tests/go_test.rb +0 -1
- data/tests/hash_bfs_test.rb +34 -0
- data/tests/hash_symbolize_keys_recursive_test.rb +0 -1
- data/tests/implement_test.rb +6 -9
- data/tests/limited_test.rb +12 -12
- data/tests/lines_file_test.rb +2 -1
- data/tests/lru_cache_test.rb +12 -1
- data/tests/memoize_test.rb +0 -1
- data/tests/method_description_test.rb +14 -20
- data/tests/minimize_test.rb +0 -1
- data/tests/module_group_test.rb +0 -1
- data/tests/named_set_test.rb +0 -1
- data/tests/null_test.rb +0 -1
- data/tests/partial_application_test.rb +4 -0
- data/tests/proc_prelude_test.rb +1 -1
- data/tests/require_maybe_test.rb +0 -1
- data/tests/scope_test.rb +1 -2
- data/tests/secure_write_test.rb +6 -1
- data/tests/sexy_singleton_test.rb +1 -1
- data/tests/string_named_placeholders.rb +109 -0
- data/tests/string_version_test.rb +3 -1
- data/tests/subhash_test.rb +0 -1
- data/tests/test_helper.rb +4 -7
- data/tests/time_dummy_test.rb +0 -1
- data/tests/time_freezer_test.rb +1 -1
- data/tests/to_test.rb +6 -6
- data/tests/token_test.rb +0 -1
- data/tests/unit_test.rb +0 -1
- data/tins.gemspec +18 -30
- metadata +55 -38
- data/lib/tins/count_by.rb +0 -8
- data/lib/tins/deep_const_get.rb +0 -50
- data/lib/tins/timed_cache.rb +0 -51
- data/lib/tins/uniq_by.rb +0 -10
- data/lib/tins/xt/count_by.rb +0 -11
- data/lib/tins/xt/deep_const_get.rb +0 -7
- data/lib/tins/xt/uniq_by.rb +0 -15
- data/tests/count_by_test.rb +0 -17
- data/tests/deep_const_get_test.rb +0 -37
- data/tests/uniq_by_test.rb +0 -31
- /data/{COPYING → LICENSE} +0 -0
data/lib/tins/xt.rb
CHANGED
@@ -3,7 +3,6 @@ require 'tins'
|
|
3
3
|
module Tins
|
4
4
|
require 'tins/xt/attempt'
|
5
5
|
require 'tins/xt/blank'
|
6
|
-
require 'tins/xt/count_by'
|
7
6
|
require 'tins/xt/deep_dup'
|
8
7
|
require 'tins/xt/file_binary'
|
9
8
|
require 'tins/xt/full'
|
@@ -22,12 +21,10 @@ module Tins
|
|
22
21
|
require 'tins/xt/time_dummy'
|
23
22
|
require 'tins/xt/date_dummy'
|
24
23
|
require 'tins/xt/date_time_dummy'
|
25
|
-
require 'tins/xt/uniq_by'
|
26
24
|
require 'tins/xt/write'
|
27
25
|
require 'tins/xt/if_predicate'
|
28
26
|
require 'tins/xt/ask_and_send'
|
29
27
|
require 'tins/xt/extract_last_argument_options'
|
30
|
-
require 'tins/xt/deep_const_get'
|
31
28
|
require 'tins/xt/responding'
|
32
29
|
require 'tins/xt/proc_compose'
|
33
30
|
require 'tins/xt/proc_prelude'
|
@@ -42,4 +39,7 @@ module Tins
|
|
42
39
|
require 'tins/xt/complete'
|
43
40
|
require 'tins/xt/expose'
|
44
41
|
require 'tins/xt/temp_io'
|
42
|
+
require 'tins/xt/deprecate'
|
43
|
+
require 'tins/xt/hash_bfs'
|
44
|
+
require 'tins/xt/minimize'
|
45
45
|
end
|
data/lib/tins.rb
CHANGED
@@ -1,7 +1,22 @@
|
|
1
|
+
# Tins is a collection of useful Ruby utilities and tools that provide
|
2
|
+
# common functionality without requiring external dependencies. It's designed
|
3
|
+
# to be a lightweight, drop-in library that enhances Ruby's standard library
|
4
|
+
# with practical conveniences.
|
5
|
+
#
|
6
|
+
# @example Basic usage
|
7
|
+
# require 'tins'
|
8
|
+
#
|
9
|
+
# Tins::Once.only_once { puts "Only one instance" }
|
10
|
+
#
|
11
|
+
# @example Automatic class extensions
|
12
|
+
# require 'tins/xt'
|
13
|
+
#
|
14
|
+
# # Automatically extends core classes with useful methods
|
15
|
+
# "foo".full? # => "foo"
|
16
|
+
# " ".full? # => nil
|
1
17
|
module Tins
|
2
18
|
require 'tins/attempt'
|
3
19
|
require 'tins/bijection'
|
4
|
-
require 'tins/count_by'
|
5
20
|
require 'tins/deep_dup'
|
6
21
|
require 'tins/file_binary'
|
7
22
|
require 'tins/find'
|
@@ -25,16 +40,15 @@ module Tins
|
|
25
40
|
require 'tins/string_camelize'
|
26
41
|
require 'tins/string_underscore'
|
27
42
|
require 'tins/string_version'
|
43
|
+
require 'tins/string_named_placeholders'
|
28
44
|
require 'tins/subhash'
|
29
45
|
require 'tins/time_dummy'
|
30
46
|
require 'tins/date_dummy'
|
31
47
|
require 'tins/date_time_dummy'
|
32
48
|
require 'tins/to_proc'
|
33
|
-
require 'tins/uniq_by'
|
34
49
|
require 'tins/version'
|
35
50
|
require 'tins/write'
|
36
51
|
require 'tins/extract_last_argument_options'
|
37
|
-
require 'tins/deep_const_get'
|
38
52
|
require 'tins/responding'
|
39
53
|
require 'tins/proc_compose'
|
40
54
|
require 'tins/proc_prelude'
|
@@ -58,5 +72,7 @@ module Tins
|
|
58
72
|
require 'tins/temp_io'
|
59
73
|
require 'tins/temp_io_enum'
|
60
74
|
require 'tins/lru_cache'
|
75
|
+
require 'tins/deprecate'
|
76
|
+
require 'tins/hash_bfs'
|
61
77
|
end
|
62
78
|
require 'tins/alias'
|
data/tests/annotate_test.rb
CHANGED
data/tests/bijection_test.rb
CHANGED
data/tests/concern_test.rb
CHANGED
@@ -1,35 +1,94 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
class ConcernTest < Test::Unit::TestCase
|
5
|
-
module
|
4
|
+
module C1
|
6
5
|
extend Tins::Concern
|
7
6
|
|
8
7
|
included do
|
9
8
|
$included = self
|
10
9
|
end
|
11
10
|
|
11
|
+
prepended do
|
12
|
+
$prepended = self
|
13
|
+
end
|
14
|
+
|
12
15
|
def foo
|
13
16
|
:foo
|
14
17
|
end
|
15
18
|
|
19
|
+
class_methods do
|
20
|
+
def baz1
|
21
|
+
:baz1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
module ClassMethods
|
17
26
|
def bar
|
18
27
|
:bar
|
19
28
|
end
|
20
29
|
end
|
30
|
+
|
31
|
+
class_methods do
|
32
|
+
def baz2
|
33
|
+
:baz2
|
34
|
+
end
|
35
|
+
end
|
21
36
|
end
|
22
37
|
|
23
38
|
$included = nil
|
39
|
+
$prepended = nil
|
40
|
+
|
41
|
+
module C2
|
42
|
+
extend Tins::Concern
|
43
|
+
|
44
|
+
def foo
|
45
|
+
:'prepended-foo'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
24
49
|
|
25
50
|
class A
|
26
|
-
include
|
51
|
+
include C1
|
52
|
+
end
|
53
|
+
|
54
|
+
class B
|
55
|
+
prepend C1
|
56
|
+
end
|
57
|
+
|
58
|
+
class C
|
59
|
+
def foo
|
60
|
+
:foo
|
61
|
+
end
|
27
62
|
end
|
28
63
|
|
29
|
-
def
|
64
|
+
def test_concern_include
|
30
65
|
a = A.new
|
31
66
|
assert_equal A, $included
|
32
67
|
assert_equal :foo, a.foo
|
33
68
|
assert_equal :bar, A.bar
|
69
|
+
assert_equal :baz1, A.baz1
|
70
|
+
assert_equal :baz2, A.baz2
|
71
|
+
assert_raise(StandardError) do
|
72
|
+
C1.module_eval { included {} }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_concern_prepend
|
77
|
+
b = B.new
|
78
|
+
assert_equal B, $prepended
|
79
|
+
assert_equal :foo, b.foo
|
80
|
+
assert_equal :bar, B.bar
|
81
|
+
assert_equal :baz1, B.baz1
|
82
|
+
assert_equal :baz2, B.baz2
|
83
|
+
assert_raise(StandardError) do
|
84
|
+
C1.module_eval { prepended {} }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_prepended_method
|
89
|
+
c = C.new
|
90
|
+
assert_equal :foo, c.foo
|
91
|
+
C.class_eval { prepend C2 }
|
92
|
+
assert_equal :'prepended-foo', c.foo
|
34
93
|
end
|
35
94
|
end
|
data/tests/date_dummy_test.rb
CHANGED
data/tests/delegate_test.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tins
|
4
|
+
class DeprecateTest < Test::Unit::TestCase
|
5
|
+
class A < Array
|
6
|
+
attr_reader :warned
|
7
|
+
|
8
|
+
def warn(message)
|
9
|
+
@warned = message if message =~ /DEPRECATION/
|
10
|
+
end
|
11
|
+
|
12
|
+
extend Tins::Deprecate
|
13
|
+
deprecate method:
|
14
|
+
def zum_felde
|
15
|
+
to_a
|
16
|
+
end,
|
17
|
+
new_method: :to_a
|
18
|
+
|
19
|
+
extend Tins::Deprecate
|
20
|
+
deprecate method:
|
21
|
+
def zum_vektor
|
22
|
+
to_a
|
23
|
+
end,
|
24
|
+
message: '[DEPRECATION] method `%{method}` is obsolete.'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_deprecate
|
28
|
+
a = A[ 1, 2 ]
|
29
|
+
assert_nil a.warned
|
30
|
+
assert_equal [ 1, 2 ], a.zum_felde
|
31
|
+
assert_match(/zum_felde` is deprecated/, a.warned)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_deprecate_with_message
|
35
|
+
a = A[ 1, 2 ]
|
36
|
+
assert_nil a.warned
|
37
|
+
assert_equal [ 1, 2 ], a.zum_vektor
|
38
|
+
assert_match(/zum_vektor` is obsolete/, a.warned)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/tests/dslkit_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
class TL
|
5
4
|
def initialize
|
@@ -66,6 +65,12 @@ class DA
|
|
66
65
|
end
|
67
66
|
|
68
67
|
dsl_reader :abc, *%w[a b c]
|
68
|
+
|
69
|
+
dsl_lazy_accessor :lazy do
|
70
|
+
:foo
|
71
|
+
end
|
72
|
+
|
73
|
+
dsl_lazy_accessor :lazy_no_default
|
69
74
|
end
|
70
75
|
|
71
76
|
class I
|
@@ -221,6 +226,15 @@ class PoliteTest < Test::Unit::TestCase
|
|
221
226
|
assert_equal %w[a b c], @da.abc
|
222
227
|
end
|
223
228
|
|
229
|
+
def test_lazy_accessor
|
230
|
+
assert_equal :foo, @da.lazy
|
231
|
+
@da.lazy { :bar }
|
232
|
+
assert_equal :bar, @da.lazy
|
233
|
+
assert_equal nil, @da.lazy_no_default
|
234
|
+
@da.lazy_no_default { :bar }
|
235
|
+
assert_equal :bar, @da.lazy_no_default
|
236
|
+
end
|
237
|
+
|
224
238
|
def test_dsl_accessor_multiple
|
225
239
|
assert_nil @da.foo
|
226
240
|
assert_equal :bar, @da.bar
|
data/tests/duration_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
module Tins
|
5
4
|
class DurationTest < Test::Unit::TestCase
|
@@ -23,6 +22,10 @@ module Tins
|
|
23
22
|
assert_equal '0+00:11:06.123456', Tins::Duration.new(666.123456).format
|
24
23
|
end
|
25
24
|
|
25
|
+
def test_format_percentage
|
26
|
+
assert_equal '11%06', Tins::Duration.new(666.123456).format('%m%%%s')
|
27
|
+
end
|
28
|
+
|
26
29
|
def test_smart_format
|
27
30
|
assert_equal '00:11:06.123', Tins::Duration.new(666.123456).format('%D')
|
28
31
|
assert_equal '7+17:11:06.123', Tins::Duration.new(666666.123456).format('%D')
|
@@ -76,6 +79,24 @@ module Tins
|
|
76
79
|
assert_true duration.negative?
|
77
80
|
assert_false Tins::Duration.new(42).negative?
|
78
81
|
end
|
82
|
+
|
83
|
+
def test_parse_roundtrip
|
84
|
+
duration_string = '6+05:04:03.210'
|
85
|
+
seconds = Tins::Duration.parse(duration_string)
|
86
|
+
assert_equal duration_string, Tins::Duration.new(seconds).to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_parse_duration_instance
|
90
|
+
duration_string = '6+05:04:03.210'
|
91
|
+
duration = Tins::Duration.new(536643.21)
|
92
|
+
seconds = Tins::Duration.parse(duration)
|
93
|
+
assert_equal duration_string, Tins::Duration.new(seconds).to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_parse_percentage
|
97
|
+
duration_string = '1%2'
|
98
|
+
seconds = Tins::Duration.parse(duration_string, template: '%h%%%m')
|
99
|
+
assert_equal seconds, 3720
|
100
|
+
end
|
79
101
|
end
|
80
102
|
end
|
81
|
-
|
data/tests/dynamic_scope_test.rb
CHANGED
data/tests/find_test.rb
CHANGED
data/tests/from_module_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
class FromModuleTest < Test::Unit::TestCase
|
5
4
|
module MyIncludedModule
|
@@ -12,6 +11,16 @@ class FromModuleTest < Test::Unit::TestCase
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
14
|
+
module MyIncludedModule2
|
15
|
+
def foo
|
16
|
+
:foo2
|
17
|
+
end
|
18
|
+
|
19
|
+
def bar
|
20
|
+
:bar2
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
class MyKlass
|
16
25
|
def foo
|
17
26
|
:original_foo
|
@@ -36,14 +45,17 @@ class FromModuleTest < Test::Unit::TestCase
|
|
36
45
|
def bar
|
37
46
|
:original_bar
|
38
47
|
end
|
48
|
+
|
49
|
+
def baz
|
50
|
+
:original_baz
|
51
|
+
end
|
39
52
|
include MyIncludedModule
|
40
53
|
end
|
41
54
|
|
42
55
|
class AnotherDerivedKlass
|
43
|
-
include MyModule
|
44
|
-
|
45
56
|
extend Tins::FromModule
|
46
57
|
|
58
|
+
include MyModule
|
47
59
|
include from module: MyIncludedModule, methods: :foo
|
48
60
|
end
|
49
61
|
|
@@ -58,4 +70,19 @@ class FromModuleTest < Test::Unit::TestCase
|
|
58
70
|
assert_equal :foo, c.foo
|
59
71
|
assert_equal :original_bar, c.bar
|
60
72
|
end
|
73
|
+
|
74
|
+
class MixedClass
|
75
|
+
extend Tins::FromModule
|
76
|
+
|
77
|
+
include MyModule
|
78
|
+
include from module: MyIncludedModule, methods: :foo
|
79
|
+
include from module: MyIncludedModule2, methods: :bar
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_mixed_klass
|
83
|
+
c = MixedClass.new
|
84
|
+
assert_equal :foo, c.foo
|
85
|
+
assert_equal :bar2, c.bar
|
86
|
+
assert_equal :original_baz, c.baz
|
87
|
+
end
|
61
88
|
end
|
data/tests/generator_test.rb
CHANGED
data/tests/go_test.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tins/xt/hash_bfs'
|
3
|
+
|
4
|
+
module Tins
|
5
|
+
class HashBFSTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@hash = { a: 'foo', b: [ { c: 'baz' }, { d: 'quux' }, [ 'blub' ] ] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_without_nodes
|
11
|
+
results = []
|
12
|
+
@hash.bfs { |*a| results.push(a) }
|
13
|
+
assert_equal [[:a, "foo"], [:c, "baz"], [:d, "quux"], [0, "blub"]], results
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_with_nodes
|
17
|
+
results = []
|
18
|
+
@hash.bfs(visit_internal: true) { |*a| results.push(a) }
|
19
|
+
assert_equal(
|
20
|
+
[[nil, {a:"foo", b:[{c:"baz"}, {d:"quux"}, ["blub"]]}], [:a, "foo"],
|
21
|
+
[:b, [{c:"baz"}, {d:"quux"}, ["blub"]]], [0, {c:"baz"}], [1, {d:"quux"}],
|
22
|
+
[2, ["blub"]], [:c, "baz"], [:d, "quux"], [0, "blub"]], results
|
23
|
+
)
|
24
|
+
assert_equal 9, results.size
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_with_nodes_with_circle
|
28
|
+
results = []
|
29
|
+
@hash[:b].last << @hash
|
30
|
+
@hash.bfs(visit_internal: true) { |*a| results.push(a) }
|
31
|
+
assert_equal 9, results.size
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/tests/implement_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
module Tins
|
5
4
|
class ImplementTest < Test::Unit::TestCase
|
@@ -54,14 +53,12 @@ module Tins
|
|
54
53
|
assert_equal('blab', error_message { A.new.quux })
|
55
54
|
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
)
|
64
|
-
end
|
56
|
+
def test_implement_def_subclass
|
57
|
+
assert_equal(
|
58
|
+
'method foobar(arg1,arg2:…) has to be '\
|
59
|
+
'implemented in subclasses of Tins::ImplementTest::A',
|
60
|
+
error_message { A.new.foobar }
|
61
|
+
)
|
65
62
|
end
|
66
63
|
|
67
64
|
private
|
data/tests/limited_test.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
module Tins
|
5
4
|
class LimitedTest < Test::Unit::TestCase
|
6
|
-
def
|
5
|
+
def test_process_with
|
7
6
|
count = {}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
Tins::Limited.new(5, name: 'sleeper').process do |limited|
|
8
|
+
10.times do
|
9
|
+
limited.execute do
|
10
|
+
count[Thread.current] = true
|
11
|
+
sleep 1
|
12
|
+
end
|
13
13
|
end
|
14
|
+
until count.size >= 10
|
15
|
+
sleep 0.1
|
16
|
+
end
|
17
|
+
limited.stop
|
14
18
|
end
|
15
|
-
|
16
|
-
sleep 0.1
|
17
|
-
end
|
18
|
-
assert_equal 5, count.keys.uniq.size
|
19
|
-
assert_equal 5, limited.wait.size
|
19
|
+
assert_equal 10, count.keys.uniq.size
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/tests/lines_file_test.rb
CHANGED
data/tests/lru_cache_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'tins'
|
3
2
|
|
4
3
|
module Tins
|
5
4
|
class LRUCacheTest < Test::Unit::TestCase
|
@@ -7,6 +6,18 @@ module Tins
|
|
7
6
|
@cache = LRUCache.new(3)
|
8
7
|
end
|
9
8
|
|
9
|
+
def test_too_low_capacity
|
10
|
+
assert_raise ArgumentError do
|
11
|
+
LRUCache.new(0)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_wrong_capacity_type
|
16
|
+
assert_raise TypeError do
|
17
|
+
LRUCache.new(:foo)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
def test_can_be_filled_to_capacity
|
11
22
|
assert_equal 0, @cache.size
|
12
23
|
@cache[1] = 1
|
data/tests/memoize_test.rb
CHANGED
@@ -12,10 +12,8 @@ module Tins
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_static_nonstatic
|
15
|
-
assert_equal 'Tins::MethodDescriptionTest::A#foo()', A.instance_method(:foo).
|
16
|
-
assert_equal '
|
17
|
-
assert_equal 'Tins::MethodDescriptionTest::A.foo()', A.method(:foo).to_s
|
18
|
-
assert_equal '#<Method: Tins::MethodDescriptionTest::A.foo()>', A.method(:foo).inspect
|
15
|
+
assert_equal 'Tins::MethodDescriptionTest::A#foo()', A.instance_method(:foo).description
|
16
|
+
assert_equal 'Tins::MethodDescriptionTest::A.foo()', A.method(:foo).description
|
19
17
|
end
|
20
18
|
|
21
19
|
class B
|
@@ -33,12 +31,12 @@ module Tins
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def test_standard_parameters_namespace
|
36
|
-
assert_equal 'Tins::MethodDescriptionTest::B#foo(x,y
|
37
|
-
B.instance_method(:foo).
|
34
|
+
assert_equal 'Tins::MethodDescriptionTest::B#foo(x,y=…,*r,&b)',
|
35
|
+
B.instance_method(:foo).description
|
38
36
|
end
|
39
37
|
|
40
38
|
def test_standard_parameters_name
|
41
|
-
assert_equal 'foo(x,y
|
39
|
+
assert_equal 'foo(x,y=…,*r,&b)',
|
42
40
|
B.instance_method(:foo).description(style: :name)
|
43
41
|
end
|
44
42
|
|
@@ -84,21 +82,17 @@ module Tins
|
|
84
82
|
end
|
85
83
|
|
86
84
|
def test_keyword_parameters
|
87
|
-
assert_equal 'Tins::MethodDescriptionTest::C#foo(x,k
|
88
|
-
assert_equal 'Tins::MethodDescriptionTest::C#bar(x,**k,&b)', C.instance_method(:bar).
|
85
|
+
assert_equal 'Tins::MethodDescriptionTest::C#foo(x,k:…,&b)', C.instance_method(:foo).description
|
86
|
+
assert_equal 'Tins::MethodDescriptionTest::C#bar(x,**k,&b)', C.instance_method(:bar).description
|
89
87
|
end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
def test_keyword_parameters_required
|
99
|
-
assert_equal 'Tins::MethodDescriptionTest::D#foo(x,k:,&b)', D.instance_method(:foo).to_s
|
100
|
-
end
|
101
|
-
}
|
89
|
+
class D
|
90
|
+
def foo(x, k:, &b)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_keyword_parameters_required
|
95
|
+
assert_equal 'Tins::MethodDescriptionTest::D#foo(x,k:,&b)', D.instance_method(:foo).description
|
102
96
|
end
|
103
97
|
end
|
104
98
|
end
|
data/tests/minimize_test.rb
CHANGED
data/tests/module_group_test.rb
CHANGED
data/tests/named_set_test.rb
CHANGED
data/tests/null_test.rb
CHANGED
@@ -13,9 +13,13 @@ module Tins
|
|
13
13
|
|
14
14
|
def test_proc
|
15
15
|
mul = lambda { |x, y| x * y }
|
16
|
+
assert_equal 2, mul.arity
|
16
17
|
klon = mul.partial
|
18
|
+
assert_equal 2, klon.arity
|
17
19
|
dup = mul.partial(2)
|
20
|
+
assert_equal 1, dup.arity
|
18
21
|
trip = mul.partial(3)
|
22
|
+
assert_equal 1, trip.arity
|
19
23
|
assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], mul[4, 3] ]
|
20
24
|
assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], klon[4, 3] ]
|
21
25
|
assert_raise(ArgumentError) do
|