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.
- checksums.yaml +7 -0
- data/.github/workflows/rspec.yml +15 -0
- data/.travis.yml +15 -0
- data/MIT-LICENSE.txt +2 -2
- data/README.md +13 -5
- data/Rakefile +4 -10
- data/bin/rpxem +14 -14
- data/lib/rpxem.rb +20 -20
- data/lib/rpxem/interpreter.rb +229 -232
- data/lib/rpxem/stack.rb +47 -47
- data/lib/rpxem/version.rb +1 -1
- data/rpxem.gemspec +14 -9
- data/spec/rpxem_helper.rb +13 -13
- data/spec/rpxem_spec.rb +201 -196
- metadata +45 -37
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
|
-
|
42
|
-
|
43
|
-
|
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
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.
|
6
|
-
gem.
|
7
|
-
gem.
|
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.
|
19
|
-
|
20
|
-
gem.
|
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.
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'RPxem.run => #<RPxem::Interpreter>.run' do
|
10
|
-
RPxem.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
|
20
|
-
expect{ @stack.push(
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should
|
24
|
-
expect{ @stack.push(-1) }.
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'can be zero' do
|
28
|
-
expect{ @stack.push(0) }.not_to raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it '
|
32
|
-
expect{ @stack.
|
33
|
-
end
|
34
|
-
|
35
|
-
it '
|
36
|
-
expect{
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
capture{ @pxem.
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'can
|
56
|
-
|
57
|
-
capture{ pxem.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@pxem.
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'can read
|
73
|
-
@pxem.run('a.
|
74
|
-
@pxem.
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
it '.
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
it '.
|
158
|
-
@pxem.run('a.t
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
it '
|
175
|
-
@pxem.run('ab
|
176
|
-
@pxem.run('ba
|
177
|
-
end
|
178
|
-
|
179
|
-
it '
|
180
|
-
@pxem.run('ab
|
181
|
-
@pxem.run('ba
|
182
|
-
end
|
183
|
-
|
184
|
-
it '
|
185
|
-
@pxem.run('ab
|
186
|
-
@pxem.run('ba
|
187
|
-
end
|
188
|
-
|
189
|
-
it '
|
190
|
-
@pxem.run('ab
|
191
|
-
@pxem.run('ba
|
192
|
-
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|