shiritori 0.1.0 → 0.1.1

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: c3953c7d65fca3fcd00c26d87e33647e4cd76a03
4
- data.tar.gz: 4ec523006a421e0509c152b85c19af74076d82ef
3
+ metadata.gz: 6e1d00e135be74ec92b38bfb77a0bb4120920bdf
4
+ data.tar.gz: 57ef4e7de3270758c399916c915e966376036a85
5
5
  SHA512:
6
- metadata.gz: b89644c03cbd9eb73884cd926f891ee1909f6ead87a1de38232fbbefefe78deab0f68a0228fd50991802c75bfaf8472ba560e244179d8976b3355a017c13430b
7
- data.tar.gz: 01b5900e13312c33a0bc1772bc2b55bcfef01c49ddc2fad5651a9d105ae6c8f85b129857c941de5bf319c077c21b5e0e8bcde41d863be21d191bd2bbd61c3250
6
+ metadata.gz: 174a41a558282a29ed42129bac38dd96fc4f87af67f9fa0e7c0358f9db12d6e7a0ec6aa52f596a852c8a15e0705cf1dadc8307281803871981301d12f3de0104
7
+ data.tar.gz: 76e23bcd669717b9130325c766f99853c8f0e00e5e7c09a2c975ed7353dcfcda5f3a35f7ab4227144c9ea35d5f0d0e11e3941d1e9483fddbc711704bbac6b86c
data/lib/shiritori.rb CHANGED
@@ -5,5 +5,7 @@ require 'shiritori/convert'
5
5
  require "shiritori/shiritori"
6
6
 
7
7
  module Shiritori
8
- ENV = :production
8
+ def self.env
9
+ :production
10
+ end
9
11
  end
@@ -12,6 +12,10 @@ class NilClass
12
12
  end
13
13
  end
14
14
 
15
+ module Kernel
16
+ undef_method :exit
17
+ end
18
+
15
19
  class Object
16
20
  def to_ss
17
21
  inspect
@@ -21,7 +25,7 @@ end
21
25
  BasicObject.class_eval do
22
26
  def __binding__
23
27
  ::Kernel.binding
24
- end
28
+ end
25
29
  end
26
30
 
27
31
  class BasicObject
@@ -10,7 +10,7 @@ module Shiritori
10
10
  RED = 31
11
11
  GREEN = 32
12
12
 
13
- EXIT_PATTERN = /(exit|quit)/.freeze
13
+ EXIT_PATTERN = /\A(exit|quit)\Z/.freeze
14
14
  METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~|\@|\%|\&|]+/.freeze
15
15
 
16
16
  def start(option = [])
@@ -66,7 +66,7 @@ module Shiritori
66
66
  end
67
67
 
68
68
  def get_command
69
- if Shiritori::ENV == :development
69
+ if Shiritori.env == :development
70
70
  print "Please input first object > "
71
71
  $stdin.gets
72
72
  else
@@ -119,8 +119,13 @@ module Shiritori
119
119
  result = [ method_name ]
120
120
 
121
121
  # puts debug
122
+ # Bignumがエラーが出る
122
123
  # puts "Exec command #{[object.to_ss, command].join('.')}"
123
124
  # p method_name
125
+ # history 機能
126
+ # 時間制限はつける
127
+ # メモリ制限もつける
128
+ # hard modeの追加
124
129
 
125
130
  case command
126
131
  when EXIT_PATTERN
@@ -129,7 +134,9 @@ module Shiritori
129
134
  begin
130
135
  Thread.new do
131
136
  raise NoMethodError unless object.respond_to?(method_name)
132
- result << object.instance_eval{ eval("self."+command) }
137
+
138
+ #result << object.instance_eval{ eval("self."+command) }
139
+ result << eval("object."+command)
133
140
  end.join
134
141
  rescue Exception => ex
135
142
  puts ex.message
@@ -1,3 +1,3 @@
1
1
  module Shiritori
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shiritori test" do
4
+ let(:main){ Shiritori::Main.new }
5
+
6
+ describe "Bignum instance methods" do
7
+ let(:__instance__){ (1<<64) }
8
+ let(:same_object){ (1<<64) }
9
+
10
+ it { instance_check(:to_s) }
11
+ it { instance_check(:to_s, %q(2)) }
12
+ it { instance_check(:inspect) }
13
+ it { instance_check(:-@) }
14
+ it { instance_check(:-, %Q(3)) }
15
+ it { instance_check(:*, %Q(3)) }
16
+ it { instance_check(:/, %q(3)) }
17
+ it { instance_check(:div, %q(3)) }
18
+ it { instance_check(:%, %q(3)) }
19
+ it { instance_check(:modulo, %q(3)) }
20
+ it { instance_check(:divmod, %q(3)) }
21
+ it { instance_check(:fdiv, %q(3)) }
22
+ it { instance_check(:**, %q(7)) }
23
+ it { instance_check(:abs) }
24
+ it { instance_check(:magnitude) }
25
+ it { instance_check(:==, %Q(#{__instance__})) }
26
+ it { instance_check(:===, %Q(#{__instance__})) }
27
+ it { instance_check(:<=>, %Q(#{__instance__})) }
28
+ it { instance_check(:>, %Q(#{__instance__})) }
29
+ it { instance_check(:>=, %Q(#{__instance__})) }
30
+ it { instance_check(:<, %Q(#{__instance__})) }
31
+ it { instance_check(:<=, %Q(#{__instance__})) }
32
+ it { instance_check(:~) }
33
+ it { instance_check(:&, %q(-1)) }
34
+ it { instance_check(:|, %q(1)) }
35
+ it { instance_check(:^, %q(-1)) }
36
+ it { instance_check(:[], %q(0)) }
37
+ it { instance_check(:<<, %q(3)) }
38
+ it { instance_check(:>>, %q(3)) }
39
+ it { instance_check(:to_f) }
40
+ it { instance_check(:size) }
41
+ it { instance_check(:bit_length) }
42
+ it { instance_check(:zero?) }
43
+ it { instance_check(:odd?) }
44
+ it { instance_check(:even?) }
45
+ it { instance_check(:succ) }
46
+ end
47
+ end
@@ -46,5 +46,32 @@ describe "Shiritori test" do
46
46
  expect(shiritori.current_object).to eq TrueClass
47
47
  expect(shiritori.chain_count).to eq 3
48
48
  end
49
+
50
+ it "test play 4" do
51
+ fake_stdin(%w(18446744073709551616 times map collect find{true} gcd(1) succ chr encoding ==(Encoding::UTF_8)
52
+ to_s slice("s") force_encoding(Encoding::CP932) next next! gsub(/u/){BasicObject} chars take(0) reverse
53
+ reverse! <<("HelloRuby") pack('m') upcase downcase upcase! unpack('m') shift split('') first scan(/./)
54
+ unshift take_while{false} to_a +([]) join('o') each_line each dup max to_i pred class extend(Module.new)
55
+ is_a?(Fixnum) ===(false) inspect concat("false") =~(/[a-z]/) &(1) methods flatten pop intern to_proc arity
56
+ |(1) divmod(0.2) min -(-5) zero? singleton_methods sort sort_by{rand} push("HelloRuby") [](-1) downcase!
57
+ sub(/r/){binding} swapcase %([]) to_str delete('A-Z') to_f *(1) fdiv(1) /(0.0) -@ abs **(0) round floor ceil
58
+ freeze odd? object_id to_r eql?(0) method(:class) call superclass new singleton_class __id__ ord even?
59
+ instance_eval{(1..10)} begin div(1) ^(5) ! nil?)) do
60
+
61
+ shiritori.start
62
+ end
63
+
64
+ expect(shiritori.current_object).to eq false
65
+ expect(shiritori.chain_count).to eq 99
66
+ end
67
+
68
+ it "text play 5" do
69
+ fake_stdin(%w("hello" send(:exit) to_i)) do
70
+ shiritori.start
71
+ end
72
+
73
+ expect(shiritori.current_object).to eq 0
74
+ expect(shiritori.chain_count).to eq 1
75
+ end
49
76
  end
50
77
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  require 'shiritori'
2
2
 
3
3
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
- Shiritori::ENV = :development
4
+
5
+ module Shiritori
6
+ def self.env
7
+ :development
8
+ end
9
+ end
5
10
 
6
11
  module Helpers
7
12
  METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~|\@|\%|\&|]+/
8
13
 
9
14
  def fake_stdin(args)
15
+ p args
10
16
  begin
11
17
  $stdin = StringIO.new
12
18
  $stdin.puts(args.shift) until args.empty?
@@ -41,10 +47,11 @@ module Helpers
41
47
  ope = ope.to_s if ope.is_a?(Symbol)
42
48
 
43
49
  command = "#{ope}(#{args.join(',')})"
44
- #puts "self."+command
45
50
 
46
51
  __self__ = check(command, obj||__instance__)
47
- other = [ope.scan(METHOD_PATTERN).first.to_sym, test_obj.instance_eval{ eval("self."+command) } ]
52
+
53
+ #other = [ope.scan(METHOD_PATTERN).first.to_sym, test_obj.instance_eval{ eval("self."+command) } ]
54
+ other = [ope.scan(METHOD_PATTERN).first.to_sym, eval("test_obj."+command) ]
48
55
 
49
56
  compare_range(__self__, other) if [Range, Enumerator].include?(__self__.last.class)
50
57
 
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.1.0
4
+ version: 0.1.1
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-21 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,6 +105,7 @@ files:
105
105
  - lib/shiritori/view.rb
106
106
  - shiritori.gemspec
107
107
  - spec/shiritori/basic_object_method_spec.rb
108
+ - spec/shiritori/bignum_method_spec.rb
108
109
  - spec/shiritori/false_method_spec.rb
109
110
  - spec/shiritori/fixnum_method_spec.rb
110
111
  - spec/shiritori/nil_method_spec.rb
@@ -141,6 +142,7 @@ specification_version: 4
141
142
  summary: shiritori
142
143
  test_files:
143
144
  - spec/shiritori/basic_object_method_spec.rb
145
+ - spec/shiritori/bignum_method_spec.rb
144
146
  - spec/shiritori/false_method_spec.rb
145
147
  - spec/shiritori/fixnum_method_spec.rb
146
148
  - spec/shiritori/nil_method_spec.rb