rpxem 0.0.2 → 0.0.7

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.
data/lib/rpxem/stack.rb CHANGED
@@ -1,47 +1,47 @@
1
- module RPxem
2
- class Stack < Array
3
- def initialize(*args, &block)
4
- super(*args, &block)
5
- simple_check(*self)
6
- end
7
-
8
- def push(*args, &block)
9
- simple_check(*args)
10
- super(*args, &block)
11
- end
12
-
13
- def unshift(*args, &block)
14
- simple_check(*args)
15
- super(*args, &block)
16
- end
17
-
18
- def <<(*args, &block)
19
- simple_check(*args)
20
- super(*args, &block)
21
- end
22
-
23
- def []=(*args, &block)
24
- super(*args, &block)
25
- simple_check(*self)
26
- end
27
-
28
- def insert(*args, &block)
29
- super(*args, &block)
30
- simple_check(*self)
31
- end
32
-
33
- def map!(*args, &block)
34
- super(*args, &block)
35
- simple_check(*self)
36
- end
37
-
38
- private
39
- def simple_check(*args)
40
- args.each do |arg|
41
- raise ArgumentError.new 'Argument must be Fixnum' if (arg.class != Fixnum)
42
- raise ArgumentError.new 'Argument must be positive' if (arg != arg.abs)
43
- raise ArgumentError.new 'Argument must be integer' if (!arg.integer?)
44
- end
45
- end
46
- end
47
- end
1
+ module RPxem
2
+ class Stack < Array
3
+ def initialize(*args, &block)
4
+ super(*args, &block)
5
+ simple_check(*self)
6
+ end
7
+
8
+ def push(*args, &block)
9
+ simple_check(*args)
10
+ super(*args, &block)
11
+ end
12
+
13
+ def unshift(*args, &block)
14
+ simple_check(*args)
15
+ super(*args, &block)
16
+ end
17
+
18
+ def <<(*args, &block)
19
+ simple_check(*args)
20
+ super(*args, &block)
21
+ end
22
+
23
+ def []=(*args, &block)
24
+ super(*args, &block)
25
+ simple_check(*self)
26
+ end
27
+
28
+ def insert(*args, &block)
29
+ super(*args, &block)
30
+ simple_check(*self)
31
+ end
32
+
33
+ def map!(*args, &block)
34
+ super(*args, &block)
35
+ simple_check(*self)
36
+ end
37
+
38
+ private
39
+ def simple_check(*args)
40
+ args.each do |arg|
41
+ if (!arg.is_a? Integer)
42
+ raise ArgumentError.new 'Argument must be Integer'
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/rpxem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RPxem
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.7'.freeze
3
3
  end
data/rpxem.gemspec CHANGED
@@ -1,21 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require File.expand_path('../lib/rpxem/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.authors = ['wktk']
6
- gem.email = ['wktk@wktk.in']
7
- gem.description = %q{RPxem is a Ruby implementation of Pxem, a esoteric programming language that enables you to create programs in 0-byte files.}
4
+ gem.name = 'rpxem'
5
+ gem.version = RPxem::VERSION
6
+ gem.authors = ['k.wakitani']
7
+ gem.email = ['k.wakitani@gmail.com']
8
+
8
9
  gem.summary = %q{Pxem implementation in Ruby}
10
+ gem.description = %q{RPxem is a Ruby implementation of Pxem, an esoteric programming language that enables you to create programs in 0-byte files.}
9
11
  gem.homepage = 'https://github.com/wktk/rpxem'
12
+ gem.license = 'MIT'
10
13
 
11
14
  gem.files = `git ls-files`.split($\)
12
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = 'rpxem'
15
17
  gem.require_paths = ['lib']
16
- gem.version = RPxem::VERSION
17
18
 
18
- gem.add_development_dependency 'rspec'
19
- gem.add_development_dependency 'rake'
20
- gem.add_development_dependency 'rdoc'
19
+ gem.required_ruby_version = '>= 2.0.0'
20
+
21
+ gem.add_dependency 'scanf' if RUBY_VERSION > '2.7'
22
+
23
+ gem.add_development_dependency 'bundler'
24
+ gem.add_development_dependency 'rspec', '~> 3.8'
25
+ gem.add_development_dependency 'rake', '~> 12.3'
21
26
  end
data/spec/rpxem_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
- require 'rpxem'
2
- require 'rspec'
3
- require 'stringio'
4
-
5
- def capture
6
- begin
7
- $stdout = result = StringIO.new
8
- yield
9
- ensure
10
- $stdout = STDOUT
11
- end
12
- result.string
13
- end
1
+ require 'rpxem'
2
+ require 'rspec'
3
+ require 'stringio'
4
+
5
+ def capture
6
+ begin
7
+ $stdout = result = StringIO.new
8
+ yield
9
+ ensure
10
+ $stdout = STDOUT
11
+ end
12
+ result.string
13
+ end
data/spec/rpxem_spec.rb CHANGED
@@ -1,196 +1,201 @@
1
- require 'rpxem_helper'
2
-
3
- describe RPxem do
4
- describe 'delegation' do
5
- it 'RPxem.new => RPxem::Interpreter.new' do
6
- RPxem.new.class.should == RPxem::Interpreter.new.class
7
- end
8
-
9
- it 'RPxem.run => #<RPxem::Interpreter>.run' do
10
- RPxem.run('hoge.d').should == RPxem::Interpreter.new.run('hoge.d')
11
- end
12
- end
13
-
14
- describe RPxem::Stack do
15
- before do
16
- @stack = RPxem::Stack.new
17
- end
18
-
19
- it 'should be Fixnum' do
20
- expect{ @stack.push('a') }.to raise_error ArgumentError
21
- end
22
-
23
- it 'should be positive' do
24
- expect{ @stack.push(-1) }.to raise_error ArgumentError
25
- end
26
-
27
- it 'can be zero' do
28
- expect{ @stack.push(0) }.not_to raise_error
29
- end
30
-
31
- it 'should be integer' do
32
- expect{ @stack.unshift(0.1) }.to raise_error ArgumentError
33
- end
34
-
35
- it 'can check in #new' do
36
- expect{ RPxem::Stack.new([1, 2, 'san']) }.to raise_error ArgumentError
37
- end
38
- end
39
-
40
- describe RPxem::Interpreter do
41
- before do
42
- @pxem = RPxem.new
43
- end
44
-
45
- describe 'initializing' do
46
- it 'can set initial stack' do
47
- capture{ @pxem.run('.p', '', RPxem::Stack.new([99, 98, 97])) }.should == 'abc'
48
- end
49
-
50
- it 'can open file' do
51
- testfile = File.join(File.dirname(__FILE__), 'world!.fHello,.pxe')
52
- capture{ @pxem.open(testfile) }.should == 'Hello, Pxem world!'
53
- end
54
-
55
- it 'can merge command mapping' do
56
- pxem = RPxem.new({'q' => 'output_all', 'c' => 'output_all'})
57
- capture{ pxem.run('Hi.q') }.should == 'Hi'
58
- capture{ pxem.run('Hi.c') }.should == 'Hi'
59
- end
60
- end
61
-
62
- describe 'get result' do
63
- it 'should return remaining stack' do
64
- @pxem.run('Hi.d').should == [105, 72]
65
- end
66
-
67
- it 'can read stack' do
68
- @pxem.run('a.d')
69
- @pxem.stack.should == [97]
70
- end
71
-
72
- it 'can read temp area' do
73
- @pxem.run('a.t')
74
- @pxem.temp.should == 97
75
- end
76
- end
77
-
78
- describe 'Pxem commands' do
79
- describe 'I/O' do
80
- it '.p' do
81
- capture{ @pxem.run('Hello, world!.p') }.should == 'Hello, world!'
82
- end
83
-
84
- it '.o' do
85
- capture{ @pxem.run('Hi.o') }.should == 'H'
86
- end
87
-
88
- it '.n' do
89
- capture{ @pxem.run('Hi.n') }.should == '72'
90
- end
91
-
92
- #it '.i' do
93
- #end
94
-
95
- #it '._' do
96
- #end
97
- end
98
-
99
- describe 'Stack' do
100
- it '.c' do
101
- @pxem.run('Hi.c').should == [105, 72, 72]
102
- end
103
-
104
- it '.s' do
105
- @pxem.run('Hi.s').should == [105]
106
- end
107
-
108
- it '.v' do
109
- @pxem.run('Hi.v').should == [72, 105]
110
- end
111
- end
112
-
113
- describe 'File' do
114
- it '.f' do
115
- @pxem.run('.f', 'File').should == [101, 108, 105, 70]
116
- end
117
-
118
- it '.e' do
119
- @pxem.run('.e', 'File.d').should == [101, 108, 105, 70]
120
- end
121
- end
122
-
123
- describe 'Rand' do
124
- it '.r' do
125
- @pxem.run('d.r').first.should be_within(100).of(0)
126
- end
127
- end
128
-
129
- describe 'Loop' do
130
- it '.w' do
131
- capture{ @pxem.run('a.whoge.paa.-.a') }.should == 'hoge'
132
- end
133
-
134
- it '.x' do
135
- capture{ @pxem.run('e.xhog.pba.a') }.should == 'hoge'
136
- end
137
-
138
- it '.y' do
139
- capture{ @pxem.run('e.yhog.pab.a') }.should == 'hoge'
140
- end
141
-
142
- it '.z' do
143
- capture{ @pxem.run('e.zhog.paa.a') }.should == 'hoge'
144
- end
145
-
146
- it '.a' do
147
- capture{ @pxem.run('e.zhog.pe.zhog.paa.aaa.a') } == 'hogehoge'
148
- end
149
- end
150
-
151
- describe 'Temporary area' do
152
- it '.t' do
153
- @pxem.run('a.t')
154
- @pxem.temp.should == 97
155
- end
156
-
157
- it '.m' do
158
- @pxem.run('a.t.m.m').should == [97, 97]
159
- end
160
- end
161
-
162
- describe '.d' do
163
- it '.d' do
164
- @pxem.run('Hi.d').should == [105, 72]
165
- end
166
- end
167
-
168
- describe 'Math' do
169
- it '.+' do
170
- @pxem.run('ab.+').should == [98 + 97]
171
- @pxem.run('ba.+').should == [98 + 97]
172
- end
173
-
174
- it '.-' do
175
- @pxem.run('ab.-').should == [98 - 97]
176
- @pxem.run('ba.-').should == [98 - 97]
177
- end
178
-
179
- it '.!' do
180
- @pxem.run('ab.!').should == [98 * 97]
181
- @pxem.run('ba.!').should == [98 * 97]
182
- end
183
-
184
- it '.$' do
185
- @pxem.run('ab.$').should == [98 / 97]
186
- @pxem.run('ba.$').should == [98 / 97]
187
- end
188
-
189
- it '.%' do
190
- @pxem.run('ab.%').should == [98 % 97]
191
- @pxem.run('ba.%').should == [98 % 97]
192
- end
193
- end
194
- end
195
- end
196
- end
1
+ require 'rpxem_helper'
2
+
3
+ describe RPxem do
4
+ describe 'delegation' do
5
+ it 'RPxem.new => RPxem::Interpreter.new' do
6
+ expect(RPxem.new.class).to eq(RPxem::Interpreter.new.class)
7
+ end
8
+
9
+ it 'RPxem.run => #<RPxem::Interpreter>.run' do
10
+ expect(RPxem.run('hoge.d')).to eq(RPxem::Interpreter.new.run('hoge.d'))
11
+ end
12
+ end
13
+
14
+ describe RPxem::Stack do
15
+ before do
16
+ @stack = RPxem::Stack.new
17
+ end
18
+
19
+ it 'should accept a positive integer' do
20
+ expect{ @stack.push(1) }.not_to raise_error
21
+ end
22
+
23
+ it 'should accept a negative integer' do
24
+ expect{ @stack.push(-1) }.not_to raise_error
25
+ end
26
+
27
+ it 'can be zero' do
28
+ expect{ @stack.push(0) }.not_to raise_error
29
+ end
30
+
31
+ it 'can be Bignum' do
32
+ expect{ @stack.push(13**13) }.not_to raise_error
33
+ end
34
+
35
+ it 'should be integer' do
36
+ expect{ @stack << 'a' }.to raise_error ArgumentError
37
+ expect{ @stack << 0.1 }.to raise_error ArgumentError
38
+ end
39
+
40
+ it 'can check in #new' do
41
+ expect{ RPxem::Stack.new([1, 2, 'san']) }.to raise_error ArgumentError
42
+ end
43
+ end
44
+
45
+ describe RPxem::Interpreter do
46
+ before do
47
+ @pxem = RPxem.new
48
+ end
49
+
50
+ describe 'initializing' do
51
+ it 'can set initial stack' do
52
+ expect(capture{ @pxem.run('.p', '', RPxem::Stack.new([99, 98, 97])) }).to eq('abc')
53
+ end
54
+
55
+ it 'can open file' do
56
+ testfile = File.join(File.dirname(__FILE__), 'world!.fHello,.pxe')
57
+ expect(capture{ @pxem.open(testfile) }).to eq('Hello, Pxem world!')
58
+ end
59
+
60
+ it 'can merge command mapping' do
61
+ pxem = RPxem.new({'q' => 'output_all', 'c' => 'output_all'})
62
+ expect(capture{ pxem.run('Hi.q') }).to eq('Hi')
63
+ expect(capture{ pxem.run('Hi.c') }).to eq('Hi')
64
+ end
65
+ end
66
+
67
+ describe 'get result' do
68
+ it 'should return remaining stack' do
69
+ expect(@pxem.run('Hi.d')).to eq([105, 72])
70
+ end
71
+
72
+ it 'can read stack' do
73
+ @pxem.run('a.d')
74
+ expect(@pxem.stack).to eq([97])
75
+ end
76
+
77
+ it 'can read temp area' do
78
+ @pxem.run('a.t')
79
+ expect(@pxem.temp).to eq(97)
80
+ end
81
+ end
82
+
83
+ describe 'Pxem commands' do
84
+ describe 'I/O' do
85
+ it '.p' do
86
+ expect(capture{ @pxem.run('Hello, world!.p') }).to eq('Hello, world!')
87
+ end
88
+
89
+ it '.o' do
90
+ expect(capture{ @pxem.run('Hi.o') }).to eq('H')
91
+ end
92
+
93
+ it '.n' do
94
+ expect(capture{ @pxem.run('Hi.n') }).to eq('72')
95
+ end
96
+
97
+ #it '.i' do
98
+ #end
99
+
100
+ #it '._' do
101
+ #end
102
+ end
103
+
104
+ describe 'Stack' do
105
+ it '.c' do
106
+ expect(@pxem.run('Hi.c')).to eq([105, 72, 72])
107
+ end
108
+
109
+ it '.s' do
110
+ expect(@pxem.run('Hi.s')).to eq([105])
111
+ end
112
+
113
+ it '.v' do
114
+ expect(@pxem.run('Hi.v')).to eq([72, 105])
115
+ end
116
+ end
117
+
118
+ describe 'File' do
119
+ it '.f' do
120
+ expect(@pxem.run('.f', 'File')).to eq([101, 108, 105, 70])
121
+ end
122
+
123
+ it '.e' do
124
+ expect(@pxem.run('.e', 'File.d')).to eq([101, 108, 105, 70])
125
+ end
126
+ end
127
+
128
+ describe 'Rand' do
129
+ it '.r' do
130
+ expect(@pxem.run('d.r').first).to be_within(100).of(0)
131
+ end
132
+ end
133
+
134
+ describe 'Loop' do
135
+ it '.w' do
136
+ expect(capture{ @pxem.run('a.whoge.paa.-.a') }).to eq('hoge')
137
+ end
138
+
139
+ it '.x' do
140
+ expect(capture{ @pxem.run('e.xhog.pba.a') }).to eq('hoge')
141
+ end
142
+
143
+ it '.y' do
144
+ expect(capture{ @pxem.run('e.yhog.pab.a') }).to eq('hoge')
145
+ end
146
+
147
+ it '.z' do
148
+ expect(capture{ @pxem.run('e.zhog.paa.a') }).to eq('hoge')
149
+ end
150
+
151
+ it '.a' do
152
+ capture{ @pxem.run('e.zhog.pe.zhog.paa.aaa.a') } == 'hogehoge'
153
+ end
154
+ end
155
+
156
+ describe 'Temporary area' do
157
+ it '.t' do
158
+ @pxem.run('a.t')
159
+ expect(@pxem.temp).to eq(97)
160
+ end
161
+
162
+ it '.m' do
163
+ expect(@pxem.run('a.t.m.m')).to eq([97, 97])
164
+ end
165
+ end
166
+
167
+ describe '.d' do
168
+ it '.d' do
169
+ expect(@pxem.run('Hi.d.hello.p')).to eq([105, 72])
170
+ end
171
+ end
172
+
173
+ describe 'Math' do
174
+ it '.+' do
175
+ expect(@pxem.run('ab.+')).to eq([98 + 97])
176
+ expect(@pxem.run('ba.+')).to eq([98 + 97])
177
+ end
178
+
179
+ it '.-' do
180
+ expect(@pxem.run('ab.-')).to eq([98 - 97])
181
+ expect(@pxem.run('ba.-')).to eq([98 - 97])
182
+ end
183
+
184
+ it '.!' do
185
+ expect(@pxem.run('ab.!')).to eq([98 * 97])
186
+ expect(@pxem.run('ba.!')).to eq([98 * 97])
187
+ end
188
+
189
+ it '.$' do
190
+ expect(@pxem.run('ab.$')).to eq([98 / 97])
191
+ expect(@pxem.run('ba.$')).to eq([98 / 97])
192
+ end
193
+
194
+ it '.%' do
195
+ expect(@pxem.run('ab.%')).to eq([98 % 97])
196
+ expect(@pxem.run('ba.%')).to eq([98 % 97])
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end