shiritori 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1afc7922a4ce5678d410b947bbe5fc1f61bb0f3
4
- data.tar.gz: c9166af59fd5be5f1e7f52c9d3c87e33cbd4126b
3
+ metadata.gz: 9cd66d45253179ee940a26b9ab8a2118da77076c
4
+ data.tar.gz: 7636fe7296de65035dc2e9be890df6218158101b
5
5
  SHA512:
6
- metadata.gz: f0c5096aed0f9111808d26129ae64ae5a35fb82e4407d401c188571fe847958e4583a1fdfdfc25e9bf0959c0fa4645517b66bd036b89de0905fa8649dc4176cd
7
- data.tar.gz: 3557e98e9f3595d77f5f95bf534bb269b4b354bdace41c3c84758d716ebe3f2d765ab5dca2c065ae78d402511a4aa31061de2e9dee5d4ea27a353c9021791e11
6
+ metadata.gz: 67337f2e8d2138f8a0269520c966d0d3a751ae385b3450d2d66545e1094da49a6238a5e2df1f519db3e5e2caecff5055baa04a83e824dd938cb0af0ad60b264c
7
+ data.tar.gz: 01fe817e01816040d01b0e66261217b8094c60b56193cba2aab5ceada7da9f2777a54d12f0b1647981e46404e63d70fdd643c3d8aa3aaa49849e5dc97b5784b4
@@ -18,6 +18,12 @@ class Object
18
18
  end
19
19
  end
20
20
 
21
+ BasicObject.class_eval do
22
+ def binding
23
+ ::Kernel.binding
24
+ end
25
+ end
26
+
21
27
  class BasicObject
22
28
  def to_ss
23
29
  self
@@ -28,7 +34,7 @@ class BasicObject
28
34
  end
29
35
 
30
36
  def eval(str)
31
- instance_eval{ instance_eval(str) }
37
+ ::Kernel.eval(str, binding)
32
38
  end
33
39
 
34
40
  alias :to_s :to_ss
@@ -1,12 +1,14 @@
1
1
  module Shiritori
2
2
  module SearchMethod
3
+ UNUSE_METHOD = [:exit]
4
+
3
5
  def get_all_method
4
6
  @check_list = Hash.new(false)
5
7
  @method_list = []
6
8
 
7
9
  scan_method
8
10
 
9
- @method_list
11
+ @method_list - UNUSE_METHOD
10
12
  end
11
13
 
12
14
  def singleton(klass)
@@ -15,7 +17,7 @@ module Shiritori
15
17
 
16
18
  def scan_method(klass = BasicObject)
17
19
  @check_list[klass] = true
18
- @method_list |= (klass.instance_methods - [:exit])
20
+ @method_list |= klass.instance_methods
19
21
 
20
22
  ObjectSpace.each_object(singleton(klass)) do |subclass|
21
23
  if klass != subclass
@@ -40,7 +40,7 @@ module Shiritori
40
40
  begin
41
41
  str = $stdin.gets.chomp
42
42
  @current_object = eval(str)
43
- @current_chain << @current_object.inspect
43
+ @current_chain << @current_object.to_ss
44
44
  rescue
45
45
  new_line
46
46
  $stdout.puts "Undefined object error"
@@ -79,6 +79,10 @@ module Shiritori
79
79
  method_name = command.scan(METHOD_PATTERN).first.to_sym
80
80
  result = [ method_name ]
81
81
 
82
+ # puts debug
83
+ # puts "Exec command #{[object.to_ss, command].join('.')}"
84
+ # p method_name
85
+
82
86
  case command
83
87
  when EXIT_PATTERN
84
88
  return [:exit]
@@ -1,3 +1,3 @@
1
1
  module Shiritori
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "BasicObject instance methods" do
7
+ let(:object){ BasicObject.new }
8
+
9
+ it { instance_check(:!) }
10
+ it { instance_check(:!=, %Q(Object.new)) }
11
+ it { instance_check(:==, %Q(Object.new)) }
12
+ it { instance_check(:__id__) }
13
+ it { instance_check(:__send__, %Q(:__id__)) }
14
+ it { instance_check(:instance_eval, %Q('BasicObject')) }
15
+ it { instance_check(:instance_exec, %Q(&->{ Fixnum })) }
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "FalseClass instance methods" do
7
+ let(:object){ false }
8
+
9
+ it { instance_check(:&, %Q(true)) }
10
+ it { instance_check(:^, %Q(true)) }
11
+ it { instance_check(:to_s) }
12
+ it { instance_check(:inspect) }
13
+ it { instance_check(:|, %Q(true)) }
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "NilClass instance methods" do
7
+ let(:object){ nil }
8
+
9
+ it { instance_check(:&, %Q(true)) }
10
+ it { instance_check(:^, %Q(true)) }
11
+ it { instance_check(:nil?) }
12
+ it { instance_check(:rationalize) }
13
+ it { instance_check(:to_a) }
14
+ it { instance_check(:to_c) }
15
+ it { instance_check(:to_f) }
16
+ it { instance_check(:to_i) }
17
+ it { instance_check(:to_r) }
18
+ it { instance_check(:to_s) }
19
+ it { instance_check(:|, %Q(true)) }
20
+ end
21
+ end
@@ -30,5 +30,12 @@ describe "Shiritori test" do
30
30
  end
31
31
  expect(shiritori.current_object).to eq Fixnum
32
32
  end
33
+
34
+ it "test play 3" do
35
+ fake_stdin(%w(BasicObject new !=(Object.new) class)) do
36
+ shiritori.start
37
+ end
38
+ expect(shiritori.current_object).to eq TrueClass
39
+ end
33
40
  end
34
41
  end
@@ -5,109 +5,120 @@ describe "Shiritori test" do
5
5
 
6
6
  describe "String instance methods" do
7
7
  let(:object){ "Ruby" }
8
+ let(:same_object){ "Ruby" }
8
9
  let(:object_int){ "100" }
10
+ let(:object_complex){ "3+3i" }
11
+ let(:object_float){ "3.14" }
12
+ let(:object_rational){ "5/11" }
9
13
  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
14
+
15
+ it { instance_check("to_s") }
16
+ it { instance_check("inspect") }
17
+ it { instance_check("hash") }
18
+ it { instance_check("<=>", %Q('#{object}')) }
19
+ it { instance_check("==", %Q('#{object}')) }
20
+ it { instance_check("===", %Q('#{object}')) }
21
+ it { instance_check("casecmp", %Q('#{object}')) }
22
+ it { instance_check("+", %Q('#{word}')) }
23
+ it { instance_check("*", %Q(3)) }
24
+ it { instance_check("%", %Q(3)) }
25
+ it { instance_check("[]", %Q(0)) }
26
+ it { instance_check("[]=", 0, %Q('P')) }
27
+ it { instance_check("insert", 0, %Q('Perl')) }
28
+ it { instance_check("length") }
29
+ it { instance_check("size") }
30
+ it { instance_check("bytesize") }
31
+ it { instance_check("empty?") }
32
+ it { instance_check("=~", %Q(/R/)) }
33
+ it { instance_check("match", %Q(/R/)) }
34
+ it { instance_check("succ") }
35
+ it { instance_check("succ!") }
36
+ it { instance_check("next") }
37
+ it { instance_check("next!") }
38
+ it { instance_check("index", %Q('R')) }
39
+ it { instance_check("rindex", %Q('R')) }
40
+ it { instance_check("replace", %Q('Python')) }
41
+ it { instance_check("ascii_only?") }
42
+ it { instance_check("bytes") }
43
+ it { instance_check("capitalize") }
44
+ it { instance_check("capitalize!") }
45
+ it { instance_check("center", %Q(10)) }
46
+ it { instance_check("chars") }
47
+ it { instance_check("chomp") }
48
+ it { instance_check("chomp!") }
49
+ it { instance_check("chop") }
50
+ it { instance_check("chop!") }
51
+ it { instance_check("clear") }
52
+ it { instance_check("codepoints") }
53
+ it { instance_check("concat", %Q('Python')) }
54
+ it { instance_check("count", %Q('R')) }
55
+ it { instance_check("crypt", %Q('siman')) }
56
+ it { instance_check("delete", %Q('R')) }
57
+ it { instance_check("delete!", %Q('R')) }
58
+ it { instance_check("downcase") }
59
+ it { instance_check("downcase!") }
60
+ it { instance_check("dump") }
61
+ it { instance_check("slice", %Q(0)) }
62
+ it { instance_check("slice!", %Q(0)) }
63
+ it { instance_check("byteslice", %Q(0)) }
64
+ it { instance_check("chr") }
65
+ it { instance_check("each_byte.to_a") }
66
+ it { instance_check("each_char.to_a") }
67
+ it { instance_check("each_codepoint.to_a") }
68
+ it { instance_check("each_line.to_a") }
69
+ it { instance_check("encode", %Q(Encoding::UTF_8)) }
70
+ it { instance_check("encode!", %Q(Encoding::UTF_8)) }
71
+ it { instance_check("encoding") }
72
+ it { instance_check("end_with?", %Q('y')) }
73
+ it { instance_check("eql?", %Q('Python')) }
74
+ it { instance_check("force_encoding", %Q('UTF-8')) }
75
+ it { instance_check("getbyte", %Q(0)) }
76
+ it { instance_check("gsub", %Q(/R/, 'P')) }
77
+ it { instance_check("gsub!", %Q(/R/, 'P')) }
78
+ it { instance_check("hex", obj: object_int) }
79
+ it { instance_check("include?", %Q('P')) }
80
+ it { instance_check("intern") }
81
+ it { instance_check("to_sym") }
82
+ it { instance_check("lines") }
83
+ it { instance_check("ljust", %Q(10)) }
84
+ it { instance_check("lstrip") }
85
+ it { instance_check("lstrip!") }
86
+ it { instance_check("oct", obj: object_int) }
87
+ it { instance_check("ord") }
88
+ it { instance_check("partition", %Q('u')) }
89
+ it { instance_check("prepend", %Q('Perl')) }
90
+ it { instance_check("reverse") }
91
+ it { instance_check("reverse!") }
92
+ it { instance_check("rjust", %Q(10)) }
93
+ it { instance_check("rpartition", %Q('u')) }
94
+ it { instance_check("rstrip") }
95
+ it { instance_check("rstrip!") }
96
+ it { instance_check("scan", %Q(/./)) }
97
+ it { instance_check("scrub") }
98
+ it { instance_check("scrub!") }
99
+ it { instance_check("setbyte", %Q(0, 67)) }
100
+ it { instance_check("split", %Q(//)) }
101
+ it { instance_check("squeeze") }
102
+ it { instance_check("squeeze!") }
103
+ it { instance_check("start_with?", %Q('R')) }
104
+ it { instance_check("strip") }
105
+ it { instance_check("strip!") }
106
+ it { instance_check("sub", %Q(/R/, '')) }
107
+ it { instance_check("sub!", %Q(/v/, '')) }
108
+ it { instance_check("sum") }
109
+ it { instance_check("swapcase") }
110
+ it { instance_check("swapcase!") }
111
+ it { instance_check("to_c", obj: object_complex) }
112
+ it { instance_check("to_f", obj: object_float) }
113
+ it { instance_check("to_i", obj: object_int) }
114
+ it { instance_check("to_r", obj: object_rational) }
115
+ it { instance_check("to_str") }
116
+ it { instance_check("tr", %Q('a-z','A-Z')) }
117
+ it { instance_check("tr!", %Q('0-9','A-Z')) }
118
+ it { instance_check("tr_s", %Q('a-z','A-Z')) }
119
+ it { instance_check("tr_s!", %Q('0-9','A-Z')) }
120
+ it { instance_check("unpack", %Q('a4')) }
121
+ it { instance_check("valid_encoding?") }
111
122
 
112
123
  it '#upto method' do
113
124
  result = check("upto('Z')","A")
@@ -115,12 +126,5 @@ describe "Shiritori test" do
115
126
  expect(result.last.to_a).to eq 'A'.upto('Z').to_a
116
127
  end
117
128
 
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
129
  end
126
130
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "TrueClass instance methods" do
7
+ let(:object){ true }
8
+
9
+ it { instance_check(:&, %Q(false)) }
10
+ it { instance_check(:^, %Q(false)) }
11
+ it { instance_check(:to_s) }
12
+ it { instance_check(:inspect) }
13
+ it { instance_check(:|, %Q(false)) }
14
+ end
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,8 @@ require 'shiritori'
3
3
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
4
 
5
5
  module Helpers
6
- # Replace standard input with faked one StringIO.
6
+ METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~|\@|\%|\&|]+/
7
+
7
8
  def fake_stdin(args)
8
9
  begin
9
10
  $stdin = StringIO.new
@@ -14,6 +15,25 @@ module Helpers
14
15
  $stdin = STDIN
15
16
  end
16
17
  end
18
+
19
+ def check( method, obj = same_object )
20
+ main.exec_method_chain( method, obj )
21
+ end
22
+
23
+ def instance_check(ope, *args, obj: object)
24
+
25
+ begin
26
+ test_obj = obj.dup
27
+ rescue Exception => ex
28
+ test_obj = obj
29
+ end
30
+
31
+ ope = ope.to_s if ope.is_a?(Symbol)
32
+
33
+ command = "#{ope}(#{args.join(',')})"
34
+ puts "self."+command
35
+ expect(check(command, obj||object)).to eq [ope.scan(METHOD_PATTERN).first.to_sym, test_obj.instance_eval{ eval("self."+command) } ]
36
+ end
17
37
  end
18
38
 
19
39
  RSpec.configure do |conf|
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.3
4
+ version: 0.0.4
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-17 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,9 +102,13 @@ files:
102
102
  - lib/shiritori/version.rb
103
103
  - lib/shiritori/view.rb
104
104
  - shiritori.gemspec
105
+ - spec/shiritori/basic_object_method_spec.rb
106
+ - spec/shiritori/false_method_spec.rb
105
107
  - spec/shiritori/fixnum_method_spec.rb
108
+ - spec/shiritori/nil_method_spec.rb
106
109
  - spec/shiritori/shiritori_spec.rb
107
110
  - spec/shiritori/string_method_spec.rb
111
+ - spec/shiritori/true_method_spec.rb
108
112
  - spec/spec_helper.rb
109
113
  homepage: https://github.com/siman-man/shiritori
110
114
  licenses:
@@ -131,7 +135,12 @@ signing_key:
131
135
  specification_version: 4
132
136
  summary: shiritori
133
137
  test_files:
138
+ - spec/shiritori/basic_object_method_spec.rb
139
+ - spec/shiritori/false_method_spec.rb
134
140
  - spec/shiritori/fixnum_method_spec.rb
141
+ - spec/shiritori/nil_method_spec.rb
135
142
  - spec/shiritori/shiritori_spec.rb
136
143
  - spec/shiritori/string_method_spec.rb
144
+ - spec/shiritori/true_method_spec.rb
137
145
  - spec/spec_helper.rb
146
+ has_rdoc: