shiritori 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +24 -0
- data/bin/shiritori +1 -1
- data/lib/shiritori/convert.rb +10 -10
- data/lib/shiritori/search_method.rb +1 -1
- data/lib/shiritori/shiritori.rb +39 -26
- data/lib/shiritori/version.rb +1 -1
- data/lib/shiritori/view.rb +3 -2
- data/lib/shiritori.rb +1 -1
- data/shiritori.gemspec +3 -0
- data/spec/shiritori/fixnum_method_spec.rb +168 -0
- data/spec/shiritori/shiritori_spec.rb +34 -0
- data/spec/shiritori/string_method_spec.rb +126 -0
- data/spec/spec_helper.rb +21 -0
- metadata +54 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1afc7922a4ce5678d410b947bbe5fc1f61bb0f3
|
4
|
+
data.tar.gz: c9166af59fd5be5f1e7f52c9d3c87e33cbd4126b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c5096aed0f9111808d26129ae64ae5a35fb82e4407d401c188571fe847958e4583a1fdfdfc25e9bf0959c0fa4645517b66bd036b89de0905fa8649dc4176cd
|
7
|
+
data.tar.gz: 3557e98e9f3595d77f5f95bf534bb269b4b354bdace41c3c84758d716ebe3f2d765ab5dca2c065ae78d402511a4aa31061de2e9dee5d4ea27a353c9021791e11
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/bin/shiritori
CHANGED
data/lib/shiritori/convert.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
class String
|
2
|
-
|
3
|
-
|
2
|
+
BLANK_PATTERN = /\A\s*\z/
|
3
|
+
|
4
|
+
def blank?
|
5
|
+
BLANK_PATTERN === self
|
4
6
|
end
|
5
7
|
end
|
6
8
|
|
7
9
|
class NilClass
|
8
|
-
def
|
10
|
+
def to_ss
|
9
11
|
"nil"
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
class
|
14
|
-
def
|
15
|
+
class Object
|
16
|
+
def to_ss
|
15
17
|
inspect
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
class BasicObject
|
20
|
-
def
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
22
|
+
def to_ss
|
25
23
|
self
|
26
24
|
end
|
27
25
|
|
@@ -32,4 +30,6 @@ class BasicObject
|
|
32
30
|
def eval(str)
|
33
31
|
instance_eval{ instance_eval(str) }
|
34
32
|
end
|
33
|
+
|
34
|
+
alias :to_s :to_ss
|
35
35
|
end
|
@@ -15,7 +15,7 @@ module Shiritori
|
|
15
15
|
|
16
16
|
def scan_method(klass = BasicObject)
|
17
17
|
@check_list[klass] = true
|
18
|
-
@method_list |= klass.instance_methods
|
18
|
+
@method_list |= (klass.instance_methods - [:exit])
|
19
19
|
|
20
20
|
ObjectSpace.each_object(singleton(klass)) do |subclass|
|
21
21
|
if klass != subclass
|
data/lib/shiritori/shiritori.rb
CHANGED
@@ -2,23 +2,24 @@ require 'pp'
|
|
2
2
|
|
3
3
|
module Shiritori
|
4
4
|
class Main
|
5
|
+
attr_reader :current_object, :chain_count
|
5
6
|
include SearchMethod
|
6
7
|
include View
|
7
8
|
|
8
9
|
EXIT_PATTERN = /(exit|quit)/.freeze
|
9
|
-
METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]
|
10
|
+
METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~|\@|\%|\&|]+/.freeze
|
10
11
|
|
11
|
-
def
|
12
|
-
@all_method = get_all_method
|
13
|
-
@current_object = nil
|
14
|
-
@current_class = Object
|
15
|
-
@current_chain = []
|
16
|
-
@chain_count = 0
|
12
|
+
def start
|
17
13
|
init
|
18
14
|
run
|
19
15
|
end
|
20
16
|
|
21
|
-
def update
|
17
|
+
def update(result = nil)
|
18
|
+
if result
|
19
|
+
@all_method.delete(result.first)
|
20
|
+
@current_object = result.last
|
21
|
+
end
|
22
|
+
|
22
23
|
begin
|
23
24
|
@current_class = @current_object.class
|
24
25
|
rescue Exception => ex
|
@@ -28,6 +29,13 @@ module Shiritori
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def init
|
32
|
+
@all_method = get_all_method
|
33
|
+
p @all_method.include?(:exit)
|
34
|
+
@current_object = nil
|
35
|
+
@current_class = Object
|
36
|
+
@current_chain = []
|
37
|
+
@chain_count = 0
|
38
|
+
|
31
39
|
$stdout.print "Please input first object > "
|
32
40
|
begin
|
33
41
|
str = $stdin.gets.chomp
|
@@ -42,18 +50,24 @@ module Shiritori
|
|
42
50
|
|
43
51
|
def run
|
44
52
|
loop do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
show_status
|
54
|
+
|
55
|
+
print "Please input next method > "
|
56
|
+
command = $stdin.gets
|
57
|
+
|
58
|
+
break if command.nil?
|
59
|
+
redo if command.blank?
|
60
|
+
|
61
|
+
command = command.chomp.sub(/^\./,"")
|
62
|
+
|
63
|
+
puts "Exec command #{[@current_object.to_ss, command].join('.')}"
|
64
|
+
|
65
|
+
if result = exec_method_chain(command, @current_object)
|
66
|
+
if @all_method.include?(result.first)
|
67
|
+
update(result)
|
68
|
+
@current_chain << command
|
69
|
+
elsif result.first == :exit
|
70
|
+
break
|
57
71
|
else
|
58
72
|
$stdout.puts "Already used method."
|
59
73
|
end
|
@@ -61,19 +75,18 @@ module Shiritori
|
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
64
|
-
def
|
78
|
+
def exec_method_chain(command, object)
|
65
79
|
method_name = command.scan(METHOD_PATTERN).first.to_sym
|
80
|
+
result = [ method_name ]
|
66
81
|
|
67
82
|
case command
|
68
83
|
when EXIT_PATTERN
|
69
|
-
exit
|
84
|
+
return [:exit]
|
70
85
|
else
|
71
86
|
begin
|
72
|
-
puts "Exec command #{[object.to_s, command].join('.')}"
|
73
|
-
|
74
87
|
Thread.new do
|
75
88
|
raise NoMethodError unless object.respond_to?(method_name)
|
76
|
-
object.instance_eval{ eval("self."+command) }
|
89
|
+
result << object.instance_eval{ eval("self."+command) }
|
77
90
|
end.join
|
78
91
|
rescue Exception => ex
|
79
92
|
puts ex.message
|
@@ -81,7 +94,7 @@ module Shiritori
|
|
81
94
|
end
|
82
95
|
end
|
83
96
|
|
84
|
-
|
97
|
+
result
|
85
98
|
end
|
86
99
|
end
|
87
100
|
end
|
data/lib/shiritori/version.rb
CHANGED
data/lib/shiritori/view.rb
CHANGED
@@ -6,7 +6,7 @@ module Shiritori
|
|
6
6
|
$stdout.puts "\n"*num
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def show_status
|
10
10
|
new_line
|
11
11
|
chain = "#{@current_chain.join('.')}"
|
12
12
|
chain_size = [chain.size+PADDING, 22].max
|
@@ -18,7 +18,7 @@ module Shiritori
|
|
18
18
|
$stdout.puts "+#{'-'*chain_size}+"
|
19
19
|
|
20
20
|
cls = "#{@current_class}"
|
21
|
-
obj = "#{@current_object.
|
21
|
+
obj = "#{@current_object.to_ss}"
|
22
22
|
cls_size = ["#{@current_class}".size, 13].max+PADDING
|
23
23
|
obj_size = ["#{@current_object}".size, 14].max+PADDING
|
24
24
|
|
@@ -29,6 +29,7 @@ module Shiritori
|
|
29
29
|
$stdout.puts "|#{cls.center(cls_size)}|#{obj.center(obj_size)}|"
|
30
30
|
$stdout.puts "+#{'-'*(cls_size)}+#{'-'*(obj_size)}+"
|
31
31
|
new_line
|
32
|
+
puts "Current Chain Count: #{@chain_count}"
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
data/lib/shiritori.rb
CHANGED
data/shiritori.gemspec
CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
23
26
|
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Shiritori test" do
|
4
|
+
let(:main){ Shiritori::Main.new }
|
5
|
+
|
6
|
+
describe "Fixnum instance methods" do
|
7
|
+
let(:object){ 16 }
|
8
|
+
|
9
|
+
def check( method )
|
10
|
+
main.exec_method_chain( method, object )
|
11
|
+
end
|
12
|
+
|
13
|
+
it '#to_s method' do
|
14
|
+
expect(check("to_s")).to eq [:to_s, object.to_s]
|
15
|
+
expect(check("to_s(2)")).to eq [:to_s, object.to_s(2)]
|
16
|
+
expect(check("to_s(8)")).to eq [:to_s, object.to_s(8)]
|
17
|
+
expect(check("to_s(16)")).to eq [:to_s, object.to_s(16)]
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#inspect method' do
|
21
|
+
expect(check("inspect")).to eq [:inspect, object.inspect]
|
22
|
+
end
|
23
|
+
|
24
|
+
it '#-@ method' do
|
25
|
+
expect(check("-@")).to eq [:-@, object.-@]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#+ method" do
|
29
|
+
expect(check("+(3)")).to eq [:+, object.+(3)]
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#- method' do
|
33
|
+
expect(check("-(3)")).to eq [:-, object.-(3)]
|
34
|
+
end
|
35
|
+
|
36
|
+
it '#* method' do
|
37
|
+
expect(check("*(3)")).to eq [:*, object.*(3)]
|
38
|
+
end
|
39
|
+
|
40
|
+
it '#/ method' do
|
41
|
+
expect(check("/(3)")).to eq [:/, object./(3)]
|
42
|
+
end
|
43
|
+
|
44
|
+
it '#div method' do
|
45
|
+
expect(check("div(3)")).to eq [:div, object.div(3)]
|
46
|
+
end
|
47
|
+
|
48
|
+
it '#% method' do
|
49
|
+
expect(check("%(3)")).to eq [:%, object.%(3)]
|
50
|
+
end
|
51
|
+
|
52
|
+
it '#modulo method' do
|
53
|
+
expect(check("modulo(3)")).to eq [:modulo, object.modulo(3)]
|
54
|
+
end
|
55
|
+
|
56
|
+
it '#divmod method' do
|
57
|
+
expect(check("divmod(3)")).to eq [:divmod, object.divmod(3)]
|
58
|
+
end
|
59
|
+
|
60
|
+
it '#fdiv method' do
|
61
|
+
expect(check("fdiv(3)")).to eq [:fdiv, object.fdiv(3)]
|
62
|
+
end
|
63
|
+
|
64
|
+
it '#** method' do
|
65
|
+
expect(check("**(7)")).to eq [:**, object.**(7)]
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#abs method' do
|
69
|
+
expect(check("abs")).to eq [:abs, object.abs]
|
70
|
+
end
|
71
|
+
|
72
|
+
it '#magnitude method' do
|
73
|
+
expect(check("magnitude")).to eq [:magnitude, object.magnitude]
|
74
|
+
end
|
75
|
+
|
76
|
+
it '#== method' do
|
77
|
+
expect(check("==(#{object})")).to eq [:==, object.==(object)]
|
78
|
+
expect(check("==(#{object-1})")).to eq [:==, object.==(object-1)]
|
79
|
+
end
|
80
|
+
|
81
|
+
it '#=== method' do
|
82
|
+
expect(check("===(#{object})")).to eq [:===, object.===(object)]
|
83
|
+
expect(check("===(#{object-1})")).to eq [:===, object.===(object-1)]
|
84
|
+
end
|
85
|
+
|
86
|
+
it '#<=> method' do
|
87
|
+
expect(check("<=>(#{object})")).to eq [:<=>, object.<=>(object)]
|
88
|
+
expect(check("<=>(#{object+1})")).to eq [:<=>, object.<=>(object+1)]
|
89
|
+
expect(check("<=>(#{object-1})")).to eq [:<=>, object.<=>(object-1)]
|
90
|
+
end
|
91
|
+
|
92
|
+
it '#> method' do
|
93
|
+
expect(check(">(#{object})")).to eq [:>, object.>(object)]
|
94
|
+
expect(check(">(#{object-1})")).to eq [:>, object.>(object-1)]
|
95
|
+
end
|
96
|
+
|
97
|
+
it '#>= method' do
|
98
|
+
expect(check(">=(#{object})")).to eq [:>=, object.>=(object)]
|
99
|
+
expect(check(">=(#{object-2})")).to eq [:>=, object.>=(object-2)]
|
100
|
+
end
|
101
|
+
|
102
|
+
it '#< method' do
|
103
|
+
expect(check("<(#{object})")).to eq [:<, object.<(object)]
|
104
|
+
expect(check("<(#{object+1})")).to eq [:<, object.<(object+1)]
|
105
|
+
end
|
106
|
+
|
107
|
+
it '#<= method' do
|
108
|
+
expect(check("<=(#{object})")).to eq [:<=, object.<=(object)]
|
109
|
+
expect(check("<=(#{object+2})")).to eq [:<=, object.<=(object+2)]
|
110
|
+
end
|
111
|
+
|
112
|
+
it '#~ method' do
|
113
|
+
expect(check("~")).to eq [:~, object.~]
|
114
|
+
end
|
115
|
+
|
116
|
+
it '#& method' do
|
117
|
+
expect(check("&(-1)")).to eq [:&, object.&(-1)]
|
118
|
+
end
|
119
|
+
|
120
|
+
it '#| method' do
|
121
|
+
expect(check("|(1)")).to eq [:|, object.|(1)]
|
122
|
+
end
|
123
|
+
|
124
|
+
it '#^ method' do
|
125
|
+
expect(check("^(-1)")).to eq [:^, object.^(-1)]
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#[] method' do
|
129
|
+
expect(check("[](0)")).to eq [:[], object.[](0)]
|
130
|
+
end
|
131
|
+
|
132
|
+
it '#<< method' do
|
133
|
+
expect(check("<<(3)")).to eq [:<<, object.<<(3)]
|
134
|
+
end
|
135
|
+
|
136
|
+
it '#>> method' do
|
137
|
+
expect(check(">>(3)")).to eq [:>>, object.>>(3)]
|
138
|
+
end
|
139
|
+
|
140
|
+
it '#to_f method' do
|
141
|
+
expect(check("to_f")).to eq [:to_f, object.to_f]
|
142
|
+
end
|
143
|
+
|
144
|
+
it '#size method' do
|
145
|
+
expect(check("size")).to eq [:size, object.size]
|
146
|
+
end
|
147
|
+
|
148
|
+
it '#bit_length method' do
|
149
|
+
expect(check("bit_length")).to eq [:bit_length, object.bit_length]
|
150
|
+
end
|
151
|
+
|
152
|
+
it '#zero? method' do
|
153
|
+
expect(check("zero?")).to eq [:zero?, object.zero?]
|
154
|
+
end
|
155
|
+
|
156
|
+
it '#odd? method' do
|
157
|
+
expect(check("odd?")).to eq [:odd?, object.odd?]
|
158
|
+
end
|
159
|
+
|
160
|
+
it '#even? method' do
|
161
|
+
expect(check("even?")).to eq [:even?, object.even?]
|
162
|
+
end
|
163
|
+
|
164
|
+
it '#succ method' do
|
165
|
+
expect(check("succ")).to eq [:succ, object.succ]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe "Shiritori test" do
|
5
|
+
describe "Game Init" do
|
6
|
+
it "Game start init" do
|
7
|
+
shiritori = Shiritori::Main.new
|
8
|
+
fake_stdin(%w("Ruby" chars)) do
|
9
|
+
shiritori.start
|
10
|
+
end
|
11
|
+
expect(shiritori.current_object).to eq ["R", "u", "b", "y"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Example " do
|
16
|
+
|
17
|
+
let(:shiritori){ Shiritori::Main.new }
|
18
|
+
|
19
|
+
|
20
|
+
it "test play 1" do
|
21
|
+
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
|
22
|
+
shiritori.start
|
23
|
+
end
|
24
|
+
expect(shiritori.current_object).to eq Fixnum
|
25
|
+
end
|
26
|
+
|
27
|
+
it "test play 2" do
|
28
|
+
fake_stdin(%w(BasicObject new __id__ class)) do
|
29
|
+
shiritori.start
|
30
|
+
end
|
31
|
+
expect(shiritori.current_object).to eq Fixnum
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Shiritori test" do
|
4
|
+
let(:main){ Shiritori::Main.new }
|
5
|
+
|
6
|
+
describe "String instance methods" do
|
7
|
+
let(:object){ "Ruby" }
|
8
|
+
let(:object_int){ "100" }
|
9
|
+
let(:word){ "Hello" }
|
10
|
+
let(:num){ 100 }
|
11
|
+
|
12
|
+
def check( method, obj = object )
|
13
|
+
main.exec_method_chain( method, obj )
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#to_s method' do
|
17
|
+
expect(check("to_s")).to eq [:to_s, object.to_s]
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#inspect method' do
|
21
|
+
expect(check("inspect")).to eq [:inspect, object.inspect]
|
22
|
+
end
|
23
|
+
|
24
|
+
it '#<=> method' do
|
25
|
+
expect(check("<=>('#{object}')")).to eq [:<=>, object.<=>(object)]
|
26
|
+
end
|
27
|
+
|
28
|
+
it '#== method' do
|
29
|
+
expect(check("==('#{object}')")).to eq [:==, object.==(object)]
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#=== method' do
|
33
|
+
expect(check("===('#{object}')")).to eq [:===, object.===(object)]
|
34
|
+
end
|
35
|
+
|
36
|
+
it '#eql? method' do
|
37
|
+
expect(check("eql?('#{object}')")).to eq [:eql?, object.eql?(object)]
|
38
|
+
end
|
39
|
+
|
40
|
+
it '#hash method' do
|
41
|
+
expect(check("hash")).to eq [:hash, object.hash]
|
42
|
+
end
|
43
|
+
|
44
|
+
it '#casecmp method' do
|
45
|
+
expect(check("casecmp('#{object}')")).to eq [:casecmp, object.casecmp(object)]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#+ method" do
|
49
|
+
expect(check("+('#{word}')")).to eq [:+, object.+(word)]
|
50
|
+
end
|
51
|
+
|
52
|
+
it '#* method' do
|
53
|
+
expect(check("*(3)")).to eq [:*, object.*(3)]
|
54
|
+
end
|
55
|
+
|
56
|
+
it '#% method' do
|
57
|
+
expect(check("%(3)")).to eq [:%, object.%(3)]
|
58
|
+
end
|
59
|
+
|
60
|
+
it '#[] method' do
|
61
|
+
expect(check("[](0)")).to eq [:[], object.[](0)]
|
62
|
+
end
|
63
|
+
|
64
|
+
it '#[]= method' do
|
65
|
+
expect(check("[]=(0, 'P')")).to eq [:[]=, object.[]=(0, 'P')]
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#insert method' do
|
69
|
+
expect(check("insert(0, 'Perl')")).to eq [:insert, object.insert(0, 'Perl')]
|
70
|
+
end
|
71
|
+
|
72
|
+
it '#length method' do
|
73
|
+
expect(check("length")).to eq [:length, object.length]
|
74
|
+
end
|
75
|
+
|
76
|
+
it '#size method' do
|
77
|
+
expect(check("size")).to eq [:size, object.size]
|
78
|
+
end
|
79
|
+
|
80
|
+
it '#bytesize method' do
|
81
|
+
expect(check("bytesize")).to eq [:bytesize, object.bytesize]
|
82
|
+
end
|
83
|
+
|
84
|
+
it '#empty? method' do
|
85
|
+
expect(check("empty?")).to eq [:empty?, object.empty?]
|
86
|
+
end
|
87
|
+
|
88
|
+
it '#=~ method' do
|
89
|
+
expect(check("=~(/R/)")).to eq [:=~, object.=~(/R/)]
|
90
|
+
end
|
91
|
+
|
92
|
+
it '#match method' do
|
93
|
+
expect(check("match(/R/)")).to eq [:match, object.match(/R/)]
|
94
|
+
end
|
95
|
+
|
96
|
+
it '#succ method' do
|
97
|
+
expect(check("succ")).to eq [:succ, object.succ]
|
98
|
+
end
|
99
|
+
|
100
|
+
it '#succ! method' do
|
101
|
+
expect(check("succ!")).to eq [:succ!, object.succ!]
|
102
|
+
end
|
103
|
+
|
104
|
+
it '#next method' do
|
105
|
+
expect(check("next")).to eq [:next, object.next]
|
106
|
+
end
|
107
|
+
|
108
|
+
it '#next! method' do
|
109
|
+
expect(check("next!")).to eq [:next!, object.next!]
|
110
|
+
end
|
111
|
+
|
112
|
+
it '#upto method' do
|
113
|
+
result = check("upto('Z')","A")
|
114
|
+
expect(result.first).to eq :upto
|
115
|
+
expect(result.last.to_a).to eq 'A'.upto('Z').to_a
|
116
|
+
end
|
117
|
+
|
118
|
+
it '#index method' do
|
119
|
+
expect(check("index('R')")).to eq [:index, object.index('R')]
|
120
|
+
end
|
121
|
+
|
122
|
+
it '#rindex method' do
|
123
|
+
expect(check("index('R')")).to eq [:index, object.index('R')]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'shiritori'
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
module Helpers
|
6
|
+
# Replace standard input with faked one StringIO.
|
7
|
+
def fake_stdin(args)
|
8
|
+
begin
|
9
|
+
$stdin = StringIO.new
|
10
|
+
$stdin.puts(args.shift) until args.empty?
|
11
|
+
$stdin.rewind
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
$stdin = STDIN
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |conf|
|
20
|
+
conf.include(Helpers)
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiritori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
description: shiritori
|
42
84
|
email:
|
43
85
|
- k128585@ie.u-ryukyu.ac.jp
|
@@ -48,6 +90,7 @@ extra_rdoc_files: []
|
|
48
90
|
files:
|
49
91
|
- ".gitignore"
|
50
92
|
- Gemfile
|
93
|
+
- Guardfile
|
51
94
|
- LICENSE.txt
|
52
95
|
- README.md
|
53
96
|
- Rakefile
|
@@ -59,6 +102,10 @@ files:
|
|
59
102
|
- lib/shiritori/version.rb
|
60
103
|
- lib/shiritori/view.rb
|
61
104
|
- shiritori.gemspec
|
105
|
+
- spec/shiritori/fixnum_method_spec.rb
|
106
|
+
- spec/shiritori/shiritori_spec.rb
|
107
|
+
- spec/shiritori/string_method_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
62
109
|
homepage: https://github.com/siman-man/shiritori
|
63
110
|
licenses:
|
64
111
|
- MIT
|
@@ -83,4 +130,8 @@ rubygems_version: 2.2.2
|
|
83
130
|
signing_key:
|
84
131
|
specification_version: 4
|
85
132
|
summary: shiritori
|
86
|
-
test_files:
|
133
|
+
test_files:
|
134
|
+
- spec/shiritori/fixnum_method_spec.rb
|
135
|
+
- spec/shiritori/shiritori_spec.rb
|
136
|
+
- spec/shiritori/string_method_spec.rb
|
137
|
+
- spec/spec_helper.rb
|