shiritori 0.1.3 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +3 -0
  5. data/README.md +19 -2
  6. data/bin/shiritori +1 -1
  7. data/lib/shiritori/cli.rb +17 -0
  8. data/lib/shiritori/convert.rb +6 -5
  9. data/lib/shiritori/error.rb +8 -3
  10. data/lib/shiritori/search_method.rb +6 -8
  11. data/lib/shiritori/shiritori.rb +102 -50
  12. data/lib/shiritori/version.rb +1 -1
  13. data/lib/shiritori/view.rb +40 -20
  14. data/lib/shiritori/yaml/array.yaml +184 -0
  15. data/lib/shiritori/yaml/basic_object.yaml +11 -0
  16. data/lib/shiritori/yaml/bignum.yaml +35 -0
  17. data/lib/shiritori/yaml/binding.yaml +7 -0
  18. data/lib/shiritori/yaml/condition_variable.yaml +7 -0
  19. data/lib/shiritori/yaml/encoding.yaml +10 -0
  20. data/lib/shiritori/yaml/enumerator.yaml +13 -0
  21. data/lib/shiritori/yaml/exception.yaml +10 -0
  22. data/lib/shiritori/yaml/false.yaml +8 -0
  23. data/lib/shiritori/yaml/file.yaml +73 -0
  24. data/lib/shiritori/yaml/fixnum.yaml +37 -0
  25. data/lib/shiritori/yaml/match_data.yaml +22 -0
  26. data/lib/shiritori/yaml/method.yaml +19 -0
  27. data/lib/shiritori/yaml/module.yaml +40 -0
  28. data/lib/shiritori/yaml/mutex.yaml +11 -0
  29. data/lib/shiritori/yaml/nil.yaml +14 -0
  30. data/lib/shiritori/yaml/object.yaml +61 -0
  31. data/lib/shiritori/yaml/proc.yaml +17 -0
  32. data/lib/shiritori/yaml/queue.yaml +15 -0
  33. data/lib/shiritori/yaml/random.yaml +6 -0
  34. data/lib/shiritori/yaml/range.yaml +22 -0
  35. data/lib/shiritori/yaml/regexp.yaml +24 -0
  36. data/lib/shiritori/yaml/sized_queue.yaml +11 -0
  37. data/lib/shiritori/yaml/string.yaml +87 -0
  38. data/lib/shiritori/yaml/symbol.yaml +26 -0
  39. data/lib/shiritori/yaml/thread.yaml +43 -0
  40. data/lib/shiritori/yaml/true.yaml +8 -0
  41. data/lib/shiritori/yaml/unbound_method.yaml +15 -0
  42. data/lib/shiritori.rb +7 -3
  43. data/shiritori.gemspec +2 -0
  44. data/spec/shiritori/bignum_method_spec.rb +4 -1
  45. data/spec/shiritori/enumerator_method_spec.rb +9 -0
  46. data/spec/shiritori/fixnum_method_spec.rb +3 -1
  47. data/spec/shiritori/shiritori_spec.rb +49 -0
  48. data/spec/shiritori/string_method_spec.rb +4 -2
  49. data/spec/spec_helper.rb +16 -13
  50. metadata +49 -5
  51. data/lib/shiritori/command.rb +0 -6
@@ -0,0 +1,87 @@
1
+ :String:
2
+ :singleton_method:
3
+ :instance_method:
4
+ :to_s: [String]
5
+ :slice: [String, NilClass]
6
+ :slice!: [String, NilClass]
7
+ :b: [String]
8
+ :byteslice: [String, NilClass]
9
+ :chars: [String, Array]
10
+ :codepoints: [String, Array]
11
+ :count: [Integer]
12
+ :crypt: [String]
13
+ :delete: [String]
14
+ :delete!: [String, NilClass]
15
+ :downcase: [String]
16
+ :downcase!: [String, NilClass]
17
+ :dump: [String]
18
+ :each_byte: [String, Enumerator]
19
+ :each_char: [String, Enumerator]
20
+ :each_codepoint: [String, Enumerator]
21
+ :each_line: [String, Enumerator]
22
+ :empty?: [TrueClass, FalseClass]
23
+ :encode: [String]
24
+ :encode!: [String]
25
+ :encoding: [Encoding]
26
+ :end_with?: [TrueClass, FalseClass]
27
+ :eql?: [TrueClass, FalseClass]
28
+ :force_encoding: [String]
29
+ :getbyte: [Integer, NilClass]
30
+ :gsub: [String, Enumerator]
31
+ :gsub: [String, Enumerator, NilClass]
32
+ :hash: [Integer]
33
+ :hex: [Integer]
34
+ :include?: [TrueClass, FalseClass]
35
+ :insert: [String]
36
+ :inspect: [String]
37
+ :intern: [Symbol]
38
+ :to_sym: [Symbol]
39
+ :length: [Integer]
40
+ :size: [Integer]
41
+ :lines: [Array, String]
42
+ :ljust: [String]
43
+ :lstrip: [String]
44
+ :lstrip!: [String, NilClass]
45
+ :match: [MatchData, NilClass, Object]
46
+ :succ: [String]
47
+ :next: [String]
48
+ :succ!: [String]
49
+ :next!: [String]
50
+ :oct: [Integer]
51
+ :partition: [Array]
52
+ :prepend: [String]
53
+ :replace: [String]
54
+ :reverse: [String]
55
+ :reverse!: [String]
56
+ :rindex: [Integer, NilClass]
57
+ :rpartition: [Array]
58
+ :rstrip: [String]
59
+ :rstrip!: [String, NilClass]
60
+ :scan: [String, Array]
61
+ :scrub: [String]
62
+ :scrub!: [String]
63
+ :setbyte: [Integer]
64
+ :split: [Array]
65
+ :squeeze: [String]
66
+ :squeeze!: [String, NilClass]
67
+ :strip: [String]
68
+ :strip!: [String, NilClass]
69
+ :sub: [String]
70
+ :sub: [String, NilClass]
71
+ :sum: [Integer]
72
+ :swapcase: [String]
73
+ :swapcase!: [String, NilClass]
74
+ :to_c: [Complex]
75
+ :to_f: [Float]
76
+ :to_i: [Integer]
77
+ :to_r: [Rational]
78
+ :to_str: [String]
79
+ :tr: [String]
80
+ :tr!: [String, NilClass]
81
+ :tr_s: [String]
82
+ :tr_s!: [String, NilClass]
83
+ :unpack: [Array]
84
+ :unpack: [Array]
85
+ :upcase: [String]
86
+ :upcase!: [String, NilClass]
87
+ :valid_encoding?: [TrueClass, FalseClass]
@@ -0,0 +1,26 @@
1
+ :Symbol:
2
+ :singleton_method:
3
+ :instance_method:
4
+ :<=>: [Fixnum]
5
+ :==: [TrueClass, FalseClass]
6
+ :=~: [Integer, NilClass]
7
+ :match: [Integer, NilClass]
8
+ :[]: [String, NilClass]
9
+ :slice: [String, NilClass]
10
+ :capitalize: [Symbol]
11
+ :casecmp: [Fixnum]
12
+ :downcase: [Symbol]
13
+ :empty?: [TrueClass, FalseClass]
14
+ :encoding: [Encoding]
15
+ :id2name: [String]
16
+ :to_s: [String]
17
+ :inspect: [String]
18
+ :intern: [Symbol]
19
+ :to_sym: [Symbol]
20
+ :length: [Integer]
21
+ :size: [Integer]
22
+ :succ: [Symbol]
23
+ :next: [Symbol]
24
+ :swapcase: [Symbol]
25
+ :to_proc: [Proc]
26
+ :upcase: [Symbol]
@@ -0,0 +1,43 @@
1
+ Thread:
2
+ :singleton_method:
3
+ :DEBUG: [Integer]
4
+ :abort_on_exception: [TrueClass,FalseClass]
5
+ :current: [Thread]
6
+ :exclusive: [Object]
7
+ :start: [Thread]
8
+ :fork: [Thread]
9
+ :handle_interrupt: [Object]
10
+ :kill: [Thread]
11
+ :list: [Array]
12
+ :main: [Thread]
13
+ :new: [Thread]
14
+ :pass: [NilClass]
15
+ :pending_interrupt?: [TrueClass,FalseClass]
16
+ :stop: [NilClass]
17
+ :instance_method:
18
+ :[]: [Object,NilClass]
19
+ :abort_on_exception: [TrueClass, FalseClass]
20
+ :add_trace_func: [Proc]
21
+ :alive?: [TrueClass,FalseClass]
22
+ :backtrace: [Array,NilClass]
23
+ :backtrace_locations: [Array,NilClass]
24
+ :exit: [Thread]
25
+ :kill: [Thread]
26
+ :terminate: [Thread]
27
+ :group: [ThreadGroup,NilClass]
28
+ :inspect: [String]
29
+ :join: [Thread,NilClass]
30
+ :key?: [TrueClass,FalseClass]
31
+ :keys: [Array]
32
+ :pending_interrupt?: [TrueClass, FalseClass]
33
+ :priority: [Integer]
34
+ :run: [Thread]
35
+ :safe_level: [Integer]
36
+ :set_trace_func: [Proc,NilClass]
37
+ :status: [String, FalseClass, NilClass]
38
+ :stop?: [TrueClass,FalseClass]
39
+ :thread_variable?: [TrueClass,FalseClass]
40
+ :thread_variable_get: [Object,NilClass]
41
+ :thread_variable_set: [Object]
42
+ :value: [Object]
43
+ :wakeup: [Thread]
@@ -0,0 +1,8 @@
1
+ :TrueClass:
2
+ :singleton_method:
3
+ :instance_method:
4
+ :&: [TrueClass, FalseClass]
5
+ :^: [TrueClass, FalseClass]
6
+ :to_s: [String]
7
+ :inspect: [String]
8
+ :|: [TrueClass, FalseClass]
@@ -0,0 +1,15 @@
1
+ :UnboundMethod:
2
+ :singleton_method:
3
+ :instance_method:
4
+ :==: [TrueClass,FalseClass]
5
+ :eql?: [TrueClass,FalseClass]
6
+ :arity: [Integer]
7
+ :bind: [Method]
8
+ :clone: [Method]
9
+ :hash: [Integer]
10
+ :inspect: [String]
11
+ :to_s: [String]
12
+ :name: [Symbol]
13
+ :owner: [Class,Module]
14
+ :parameters: [Array]
15
+ :source_location: [Array,NilClass]
data/lib/shiritori.rb CHANGED
@@ -1,11 +1,15 @@
1
+ require "thor"
2
+
1
3
  require "shiritori/version"
2
4
  require "shiritori/search_method"
3
- require 'shiritori/view'
4
- require 'shiritori/convert'
5
+ require "shiritori/error"
6
+ require "shiritori/view"
7
+ require "shiritori/convert"
8
+ require "shiritori/cli"
5
9
  require "shiritori/shiritori"
6
10
 
7
11
  module Shiritori
8
12
  def self.env
9
13
  :production
10
14
  end
11
- end
15
+ end
data/shiritori.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "thor"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.6"
22
24
  spec.add_development_dependency "rake"
23
25
  spec.add_development_dependency "rspec"
@@ -38,10 +38,13 @@ describe "Shiritori test" do
38
38
  it { instance_check(:>>, %q(3)) }
39
39
  it { instance_check(:to_f) }
40
40
  it { instance_check(:size) }
41
- it { instance_check(:bit_length) }
42
41
  it { instance_check(:zero?) }
43
42
  it { instance_check(:odd?) }
44
43
  it { instance_check(:even?) }
45
44
  it { instance_check(:succ) }
45
+
46
+ if RUBY_VERSION >= "2.1.0"
47
+ it { instance_check(:bit_length) }
48
+ end
46
49
  end
47
50
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "Enumerator instance methods" do
7
+
8
+ end
9
+ end
@@ -38,10 +38,12 @@ describe "Shiritori test" do
38
38
  it { instance_check(:>>, %q(3)) }
39
39
  it { instance_check(:to_f) }
40
40
  it { instance_check(:size) }
41
- it { instance_check(:bit_length) }
42
41
  it { instance_check(:zero?) }
43
42
  it { instance_check(:odd?) }
44
43
  it { instance_check(:even?) }
45
44
  it { instance_check(:succ) }
45
+ if RUBY_VERSION >= "2.1.0"
46
+ it { instance_check(:bit_length) }
47
+ end
46
48
  end
47
49
  end
@@ -22,6 +22,54 @@ describe "Shiritori test" do
22
22
  end
23
23
  end
24
24
 
25
+ describe 'Timeout' do
26
+ context 'Timeout::Error occur' do
27
+ it 'first object sleep' do
28
+ fake_stdin(%w(sleep)) do
29
+ shiritori.start
30
+ end
31
+
32
+ expect(shiritori.current_object).to eq nil
33
+ expect(shiritori.error_count).to eq 0
34
+ end
35
+ end
36
+
37
+ context 'Timeout::Error occur' do
38
+ it 'sleep method limit' do
39
+ fake_stdin(%w(3 instance_eval{sleep(3)} to_s nil?)) do
40
+ shiritori.start
41
+ end
42
+
43
+ expect(shiritori.current_object).to eq false
44
+ expect(shiritori.chain_count).to eq 2
45
+ expect(shiritori.error_count).to eq 1
46
+ end
47
+ end
48
+
49
+ context 'Timeout::Error not occur' do
50
+ it 'sleep method' do
51
+ fake_stdin(%w(3 instance_eval{sleep(0)} to_s)) do
52
+ shiritori.start
53
+ end
54
+
55
+ expect(shiritori.current_object).to eq '0'
56
+ expect(shiritori.chain_count).to eq 2
57
+ expect(shiritori.error_count).to eq 0
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "Blank Input" do
63
+ it 'should blank' do
64
+ fake_stdin(%W("\n" 3 to_s)) do
65
+ shiritori.start
66
+ end
67
+
68
+ expect(shiritori.current_object).to eq '3'
69
+ expect(shiritori.chain_count).to eq 1
70
+ end
71
+ end
72
+
25
73
  describe "Example" do
26
74
  it "test play 1" do
27
75
  fake_stdin(%w(3 next to_s *(5) chars first instance_eval{(1..10)} each{|n|n*100} map{|n|n+100} inject(:+) class)) do
@@ -62,6 +110,7 @@ describe "Shiritori test" do
62
110
  end
63
111
 
64
112
  expect(shiritori.current_object).to eq false
113
+ expect(shiritori.error_count).to eq 0
65
114
  expect(shiritori.chain_count).to eq 99
66
115
  end
67
116
 
@@ -94,8 +94,6 @@ describe "Shiritori test" do
94
94
  it { instance_check("rstrip") }
95
95
  it { instance_check("rstrip!") }
96
96
  it { instance_check("scan", %Q(/./)) }
97
- it { instance_check("scrub") }
98
- it { instance_check("scrub!") }
99
97
  it { instance_check("setbyte", %Q(0, 67)) }
100
98
  it { instance_check("split", %Q(//)) }
101
99
  it { instance_check("squeeze") }
@@ -126,5 +124,9 @@ describe "Shiritori test" do
126
124
  expect(result.last.to_a).to eq 'A'.upto('Z').to_a
127
125
  end
128
126
 
127
+ if RUBY_VERSION >= "2.1.0"
128
+ it { instance_check("scrub") }
129
+ it { instance_check("scrub!") }
130
+ end
129
131
  end
130
132
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'shiritori'
2
+ require 'timeout'
3
+ require 'ripper'
4
+ require 'coveralls'
2
5
 
3
6
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
7
+ Coveralls.wear!
4
8
 
5
9
  module Shiritori
6
10
  def self.env
@@ -12,7 +16,6 @@ module Helpers
12
16
  METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~|\@|\%|\&|]+/
13
17
 
14
18
  def fake_stdin(args)
15
- p args
16
19
  begin
17
20
  $stdin = StringIO.new
18
21
  $stdin.puts(args.shift) until args.empty?
@@ -23,16 +26,16 @@ module Helpers
23
26
  end
24
27
  end
25
28
 
26
- def check( method, obj = same_object )
27
- main.exec_method_chain( method, obj )
29
+ def check(method, obj = same_object)
30
+ main.exec_method_chain(method, obj)
28
31
  end
29
32
 
30
- def compare_range( a, b )
33
+ def compare_range(a, b)
31
34
  a[1] = a[1].to_a
32
35
  b[1] = b[1].to_a
33
36
  end
34
37
 
35
- def instance_check(ope, *args, obj: __instance__)
38
+ def instance_check(operation, *args, obj: __instance__)
36
39
 
37
40
  begin
38
41
  if obj.is_a?(Class)
@@ -44,20 +47,20 @@ module Helpers
44
47
  test_obj = obj
45
48
  end
46
49
 
47
- ope = ope.to_s if ope.is_a?(Symbol)
50
+ operation = operation.to_s if operation.is_a?(Symbol)
48
51
 
49
- command = "#{ope}(#{args.join(',')})"
52
+ command = "#{operation}(#{args.join(',')})"
50
53
 
51
- __self__ = check(command, obj||__instance__)
54
+ __result__ = check(command, obj||__instance__)
52
55
 
53
- other = [ope.scan(METHOD_PATTERN).first.to_sym, eval("test_obj."+command) ]
54
-
55
- compare_range(__self__, other) if [Range, Enumerator].include?(__self__.last.class)
56
+ __expect__ = [operation.scan(METHOD_PATTERN).first.to_sym, eval("test_obj."+command) ]
56
57
 
57
- expect(__self__).to eq other
58
+ compare_range(__result__, __expect__) if [Range, Enumerator].include?(__result__.last.class)
59
+
60
+ expect(__result__).to eq __expect__
58
61
  end
59
62
  end
60
63
 
61
64
  RSpec.configure do |conf|
62
65
  conf.include(Helpers)
63
- end
66
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiritori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - siman-man
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,7 @@ extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - ".gitignore"
106
+ - ".travis.yml"
92
107
  - Gemfile
93
108
  - Guardfile
94
109
  - LICENSE.txt
@@ -96,16 +111,45 @@ files:
96
111
  - Rakefile
97
112
  - bin/shiritori
98
113
  - lib/shiritori.rb
99
- - lib/shiritori/command.rb
114
+ - lib/shiritori/cli.rb
100
115
  - lib/shiritori/convert.rb
101
116
  - lib/shiritori/error.rb
102
117
  - lib/shiritori/search_method.rb
103
118
  - lib/shiritori/shiritori.rb
104
119
  - lib/shiritori/version.rb
105
120
  - lib/shiritori/view.rb
121
+ - lib/shiritori/yaml/array.yaml
122
+ - lib/shiritori/yaml/basic_object.yaml
123
+ - lib/shiritori/yaml/bignum.yaml
124
+ - lib/shiritori/yaml/binding.yaml
125
+ - lib/shiritori/yaml/condition_variable.yaml
126
+ - lib/shiritori/yaml/encoding.yaml
127
+ - lib/shiritori/yaml/enumerator.yaml
128
+ - lib/shiritori/yaml/exception.yaml
129
+ - lib/shiritori/yaml/false.yaml
130
+ - lib/shiritori/yaml/file.yaml
131
+ - lib/shiritori/yaml/fixnum.yaml
132
+ - lib/shiritori/yaml/match_data.yaml
133
+ - lib/shiritori/yaml/method.yaml
134
+ - lib/shiritori/yaml/module.yaml
135
+ - lib/shiritori/yaml/mutex.yaml
136
+ - lib/shiritori/yaml/nil.yaml
137
+ - lib/shiritori/yaml/object.yaml
138
+ - lib/shiritori/yaml/proc.yaml
139
+ - lib/shiritori/yaml/queue.yaml
140
+ - lib/shiritori/yaml/random.yaml
141
+ - lib/shiritori/yaml/range.yaml
142
+ - lib/shiritori/yaml/regexp.yaml
143
+ - lib/shiritori/yaml/sized_queue.yaml
144
+ - lib/shiritori/yaml/string.yaml
145
+ - lib/shiritori/yaml/symbol.yaml
146
+ - lib/shiritori/yaml/thread.yaml
147
+ - lib/shiritori/yaml/true.yaml
148
+ - lib/shiritori/yaml/unbound_method.yaml
106
149
  - shiritori.gemspec
107
150
  - spec/shiritori/basic_object_method_spec.rb
108
151
  - spec/shiritori/bignum_method_spec.rb
152
+ - spec/shiritori/enumerator_method_spec.rb
109
153
  - spec/shiritori/false_method_spec.rb
110
154
  - spec/shiritori/fixnum_method_spec.rb
111
155
  - spec/shiritori/nil_method_spec.rb
@@ -136,13 +180,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
180
  version: '0'
137
181
  requirements: []
138
182
  rubyforge_project:
139
- rubygems_version: 2.2.2
183
+ rubygems_version: 2.4.5
140
184
  signing_key:
141
185
  specification_version: 4
142
186
  summary: shiritori
143
187
  test_files:
144
188
  - spec/shiritori/basic_object_method_spec.rb
145
189
  - spec/shiritori/bignum_method_spec.rb
190
+ - spec/shiritori/enumerator_method_spec.rb
146
191
  - spec/shiritori/false_method_spec.rb
147
192
  - spec/shiritori/fixnum_method_spec.rb
148
193
  - spec/shiritori/nil_method_spec.rb
@@ -153,4 +198,3 @@ test_files:
153
198
  - spec/shiritori/symbol_method_spec.rb
154
199
  - spec/shiritori/true_method_spec.rb
155
200
  - spec/spec_helper.rb
156
- has_rdoc:
@@ -1,6 +0,0 @@
1
- module Shiritori
2
- class Command
3
- def self.parse(argv)
4
- end
5
- end
6
- end