rpxem 0.0.4 → 0.0.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2bacef5ec429991e8efb5c8c66dcf611a8f5c131126e966a4011d9812bf06393
4
+ data.tar.gz: 5dd82593827ad40ed9116f46cb415a262ab75db652ddb9b1f04d11e8cd61a3a5
5
+ SHA512:
6
+ metadata.gz: 71d11f62f35da4261e0bdc744a12a599150902f5f093ace19d891a59c7998d98cf050e24bf06989f5453c6bc20aa2c26613a3019dc4882f30781d99af40a43dc
7
+ data.tar.gz: 2915e99940dd7cbf8300854722c43cb4554278c511540c052ac01f76916e4a032f71fad5b0b7ce0dae0be7983dcc19e78f23310e8044e0f5e3c286d0ab7e6c77
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ cache:
11
+ directories: vendor/bundle
12
+ before_install:
13
+ - gem update --system
14
+ - gem --version
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # RPxem
2
2
 
3
- [![Build Status](https://travis-ci.org/wktk/rpxem.png)](https://travis-ci.org/wktk/rpxem)
3
+ [![Build Status](https://travis-ci.org/wktk/rpxem.svg?branch=master)](https://travis-ci.org/wktk/rpxem)
4
4
 
5
5
  RPxem is a Ruby implementation of [Pxem], an esoteric programming language that
6
6
  enables you to create programs in 0-byte files.
7
- [Pxem]: http://cfs.maxn.jp/neta/pxem.php
7
+
8
+ [Pxem]: https://web.archive.org/web/20120605223423/http://cfs.maxn.jp/neta/pxem.php
8
9
 
9
10
  ## Installation
10
11
 
@@ -73,3 +74,8 @@ Hello, world!
73
74
 
74
75
  Copyright (c) 2012 wktk. This software is distributed under the
75
76
  MIT License. See `MIT-LICENSE.txt` for details.
77
+
78
+ ## See also
79
+
80
+ - Original resource: https://web.archive.org/web/20120605223423/http://cfs.maxn.jp/neta/pxem.php
81
+ - Esolang wiki: https://esolangs.org/wiki/Pxem
data/Rakefile CHANGED
@@ -1,12 +1,6 @@
1
- #!/usr/bin/env rake
2
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- task :default => [:spec]
5
- begin
6
- require 'rspec/core/rake_task'
7
- RSpec::Core::RakeTask.new(:spec) do |spec|
8
- spec.pattern = 'spec/**/*_spec.rb'
9
- spec.rspec_opts = ['-cfs']
10
- end
11
- rescue LoadError => e
12
- end
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/rpxem CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- if (!ARGV[0] || /^-/ =~ ARGV[0] && !File.exist?(ARGV[0]))
4
- require 'rpxem/version'
5
- puts "RPxem (#{RPxem::VERSION}) https://github.com/wktk/rpxem"
6
- puts 'Usage: rpxem path-to-pxem-file.pxe'
7
- puts 'Report bugs to <https://github.com/wktk/rpxem/issues>.'
8
- elsif (!File.exist?(ARGV[0]) || !source = open(ARGV[0]).read)
9
- puts "Can't load file: #{ARGV[0]}"
10
- puts "Try `rpxem --help' for more infomation."
11
- else
12
- require 'rpxem'
13
- RPxem.run(File::basename(ARGV[0]), source)
14
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ if (!ARGV[0] || /^-/ =~ ARGV[0] && !File.exist?(ARGV[0]))
4
+ require 'rpxem/version'
5
+ puts "RPxem (#{RPxem::VERSION}) https://github.com/wktk/rpxem"
6
+ puts 'Usage: rpxem path-to-pxem-file.pxe'
7
+ puts 'Report bugs to <https://github.com/wktk/rpxem/issues>.'
8
+ elsif (!File.exist?(ARGV[0]) || !source = open(ARGV[0]).read)
9
+ puts "Can't load file: #{ARGV[0]}"
10
+ puts "Try `rpxem --help' for more infomation."
11
+ else
12
+ require 'rpxem'
13
+ RPxem.run(File::basename(ARGV[0]), source)
14
+ end
@@ -1,232 +1,233 @@
1
- require 'rpxem/stack'
2
- require 'rpxem/version'
3
- require 'scanf'
4
-
5
- module RPxem
6
- class Interpreter
7
- attr_accessor :mapping
8
- attr_reader :stack, :temp
9
-
10
- def initialize(mapping={})
11
- @mapping = default_mapping().merge(mapping)
12
- end
13
-
14
- # Open and execute a Pxem file
15
- def open(file, stack=RPxem::Stack.new, temp=nil)
16
- run(File.basename(file), File.open(file).read, stack, temp)
17
- end
18
-
19
- # Execute a Pxem code
20
- def run(filename, source='', stack=RPxem::Stack.new, temp=nil)
21
- @filename, @source, @stack, @temp = filename.each_byte.to_a, source, stack, temp
22
- buffer, @cursor, length = RPxem::Stack.new, 0, @filename.length
23
-
24
- while (@cursor < length)
25
- char = @filename[@cursor]
26
- @cursor += 1
27
- if (@cursor < length && 46 == char && name = @mapping[@filename[@cursor].chr.downcase])
28
- @stack.push(*buffer)
29
- buffer = RPxem::Stack.new
30
- __send__(name)
31
- @cursor += 1
32
- else
33
- buffer.unshift(char)
34
- end
35
- end
36
-
37
- return @stack
38
- end
39
-
40
- def default_mapping
41
- {
42
- # I/O
43
- 'p' => 'output_all',
44
- 'o' => 'output',
45
- 'n' => 'output_num',
46
- 'i' => 'input',
47
- '_' => 'input_num',
48
-
49
- # Stack
50
- 'c' => 'copy',
51
- 's' => 'throw_away',
52
- 'v' => 'reverse',
53
-
54
- # File contents
55
- 'f' => 'read_file',
56
- 'e' => 'emurate',
57
-
58
- # Rand
59
- 'r' => 'rand',
60
-
61
- # Loop
62
- 'w' => 'w',
63
- 'x' => 'x',
64
- 'y' => 'y',
65
- 'z' => 'z',
66
- 'a' => 'a',
67
-
68
- # Temporary area
69
- 't' => 'to_temp',
70
- 'm' => 'from_temp',
71
-
72
- # Do nothing
73
- 'd' => 'void',
74
-
75
- # Math
76
- '+' => 'addition',
77
- '-' => 'subtraction',
78
- '!' => 'multiplication',
79
- '$' => 'quotient',
80
- '%' => 'surplus',
81
- }
82
- end
83
-
84
- private
85
-
86
- # .p:
87
- def output_all
88
- while output; end
89
- end
90
-
91
- # .o:
92
- def output
93
- putc @stack.pop unless @stack.empty?
94
- end
95
-
96
- # .n:
97
- def output_num
98
- print @stack.pop
99
- end
100
-
101
- # .i:
102
- def input
103
- @stack.push(*STDIN.getc.ord)
104
- end
105
-
106
- # ._:
107
- def input_num
108
- @stack.push(*scanf('%d'))
109
- end
110
-
111
- # .c:
112
- def copy
113
- @stack.push(@stack.last)
114
- end
115
-
116
- # .s:
117
- def throw_away
118
- @stack.pop
119
- end
120
-
121
- # .v:
122
- def reverse
123
- @stack.reverse!
124
- end
125
-
126
- # .f:
127
- def read_file
128
- @stack.push(*@source.each_byte.to_a.reverse)
129
- end
130
-
131
- # .e:
132
- def emurate
133
- @stack.push(*clone.run(@source, @source, @stack.clone))
134
- end
135
-
136
- # .r:
137
- def rand
138
- @stack.push((super * @stack.pop).to_i)
139
- end
140
-
141
- # .w:
142
- def w
143
- jump if (!@stack.empty? && 0 == @stack.pop)
144
- end
145
-
146
- # .x:
147
- def x
148
- jump if (2 <= @stack.size && @stack.pop >= @stack.pop)
149
- end
150
-
151
- # .y:
152
- def y
153
- jump if (2 <= @stack.size && @stack.pop <= @stack.pop)
154
- end
155
-
156
- # .z:
157
- def z
158
- jump if (2 <= @stack.size && @stack.pop == @stack.pop)
159
- end
160
-
161
- # Jump forward to correspondent .a
162
- def jump
163
- count = 1
164
- while (count.nonzero?)
165
- @cursor += 1
166
- if (46 == @filename[@cursor])
167
- if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
168
- count += 1
169
- elsif ('a' == @filename[@cursor+1].chr.downcase)
170
- count -= 1
171
- end
172
- end
173
- end
174
- @cursor += 1
175
- end
176
-
177
- # .a:
178
- def a
179
- @cursor -= 2
180
- count = -1
181
- while (count.nonzero?)
182
- if (46 == @filename[@cursor])
183
- if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
184
- count += 1
185
- elsif ('a' == @filename[@cursor+1].chr.downcase)
186
- count -= 1
187
- end
188
- end
189
- @cursor -= 1
190
- end
191
- end
192
-
193
- # .t:
194
- def to_temp
195
- @temp = @stack.pop
196
- end
197
-
198
- # .m:
199
- def from_temp
200
- @stack.push(@temp) if @temp
201
- end
202
-
203
- # .d:
204
- def void
205
- end
206
-
207
- # .+:
208
- def addition
209
- @stack.push(@stack.pop + @stack.pop) if 2 <= @stack.size
210
- end
211
-
212
- # .-:
213
- def subtraction
214
- @stack.push((@stack.pop - @stack.pop).abs) if 2 <= @stack.size
215
- end
216
-
217
- # .!:
218
- def multiplication
219
- @stack.push(@stack.pop * @stack.pop) if 2 <= @stack.size
220
- end
221
-
222
- # .$:
223
- def quotient
224
- @stack.push((f=@stack.pop)>(s=@stack.pop)? f/s : s/f) if 2 <= @stack.size
225
- end
226
-
227
- # .%:
228
- def surplus
229
- @stack.push((f=@stack.pop)>(s=@stack.pop)? f%s : s%f) if 2 <= @stack.size
230
- end
231
- end
232
- end
1
+ require 'rpxem/stack'
2
+ require 'rpxem/version'
3
+ require 'scanf'
4
+
5
+ module RPxem
6
+ class Interpreter
7
+ attr_accessor :mapping
8
+ attr_reader :stack, :temp
9
+
10
+ def initialize(mapping={})
11
+ @mapping = default_mapping().merge(mapping)
12
+ end
13
+
14
+ # Open and execute a Pxem file
15
+ def open(file, stack=RPxem::Stack.new, temp=nil)
16
+ run(File.basename(file), File.open(file).read, stack, temp)
17
+ end
18
+
19
+ # Execute a Pxem code
20
+ def run(filename, source='', stack=RPxem::Stack.new, temp=nil)
21
+ @filename, @source, @stack, @temp = filename.each_byte.to_a, source, stack, temp
22
+ buffer, @cursor, length = RPxem::Stack.new, 0, @filename.length
23
+
24
+ while (@cursor < length)
25
+ char = @filename[@cursor]
26
+ @cursor += 1
27
+ if (@cursor < length && 46 == char && name = @mapping[@filename[@cursor].chr.downcase])
28
+ @stack.push(*buffer)
29
+ buffer = RPxem::Stack.new
30
+ __send__(name)
31
+ @cursor += 1
32
+ else
33
+ buffer.unshift(char)
34
+ end
35
+ end
36
+
37
+ return @stack
38
+ end
39
+
40
+ def default_mapping
41
+ {
42
+ # I/O
43
+ 'p' => 'output_all',
44
+ 'o' => 'output',
45
+ 'n' => 'output_num',
46
+ 'i' => 'input',
47
+ '_' => 'input_num',
48
+
49
+ # Stack
50
+ 'c' => 'copy',
51
+ 's' => 'throw_away',
52
+ 'v' => 'reverse',
53
+
54
+ # File contents
55
+ 'f' => 'read_file',
56
+ 'e' => 'emurate',
57
+
58
+ # Rand
59
+ 'r' => 'rand',
60
+
61
+ # Loop
62
+ 'w' => 'w',
63
+ 'x' => 'x',
64
+ 'y' => 'y',
65
+ 'z' => 'z',
66
+ 'a' => 'a',
67
+
68
+ # Temporary area
69
+ 't' => 'to_temp',
70
+ 'm' => 'from_temp',
71
+
72
+ # Do nothing
73
+ 'd' => 'void',
74
+
75
+ # Math
76
+ '+' => 'addition',
77
+ '-' => 'subtraction',
78
+ '!' => 'multiplication',
79
+ '$' => 'quotient',
80
+ '%' => 'surplus',
81
+ }
82
+ end
83
+
84
+ private
85
+
86
+ # .p:
87
+ def output_all
88
+ while output; end
89
+ end
90
+
91
+ # .o:
92
+ def output
93
+ putc @stack.pop unless @stack.empty?
94
+ end
95
+
96
+ # .n:
97
+ def output_num
98
+ print @stack.pop
99
+ end
100
+
101
+ # .i:
102
+ def input
103
+ stdin = STDIN.getc
104
+ @stack.push(stdin ? stdin.ord : -1)
105
+ end
106
+
107
+ # ._:
108
+ def input_num
109
+ @stack.push(*scanf('%d'))
110
+ end
111
+
112
+ # .c:
113
+ def copy
114
+ @stack.push(@stack.last)
115
+ end
116
+
117
+ # .s:
118
+ def throw_away
119
+ @stack.pop
120
+ end
121
+
122
+ # .v:
123
+ def reverse
124
+ @stack.reverse!
125
+ end
126
+
127
+ # .f:
128
+ def read_file
129
+ @stack.push(*@source.each_byte.to_a.reverse)
130
+ end
131
+
132
+ # .e:
133
+ def emurate
134
+ @stack.push(*clone.run(@source, @source, @stack.clone))
135
+ end
136
+
137
+ # .r:
138
+ def rand
139
+ @stack.push((super * @stack.pop).to_i)
140
+ end
141
+
142
+ # .w:
143
+ def w
144
+ jump if (!@stack.empty? && 0 == @stack.pop)
145
+ end
146
+
147
+ # .x:
148
+ def x
149
+ jump if (2 <= @stack.size && @stack.pop >= @stack.pop)
150
+ end
151
+
152
+ # .y:
153
+ def y
154
+ jump if (2 <= @stack.size && @stack.pop <= @stack.pop)
155
+ end
156
+
157
+ # .z:
158
+ def z
159
+ jump if (2 <= @stack.size && @stack.pop == @stack.pop)
160
+ end
161
+
162
+ # Jump forward to correspondent .a
163
+ def jump
164
+ count = 1
165
+ while (count.nonzero?)
166
+ @cursor += 1
167
+ if (46 == @filename[@cursor])
168
+ if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
169
+ count += 1
170
+ elsif ('a' == @filename[@cursor+1].chr.downcase)
171
+ count -= 1
172
+ end
173
+ end
174
+ end
175
+ @cursor += 1
176
+ end
177
+
178
+ # .a:
179
+ def a
180
+ @cursor -= 2
181
+ count = -1
182
+ while (count.nonzero?)
183
+ if (46 == @filename[@cursor])
184
+ if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
185
+ count += 1
186
+ elsif ('a' == @filename[@cursor+1].chr.downcase)
187
+ count -= 1
188
+ end
189
+ end
190
+ @cursor -= 1
191
+ end
192
+ end
193
+
194
+ # .t:
195
+ def to_temp
196
+ @temp = @stack.pop
197
+ end
198
+
199
+ # .m:
200
+ def from_temp
201
+ @stack.push(@temp) if @temp
202
+ end
203
+
204
+ # .d:
205
+ def void
206
+ end
207
+
208
+ # .+:
209
+ def addition
210
+ @stack.push(@stack.pop + @stack.pop) if 2 <= @stack.size
211
+ end
212
+
213
+ # .-:
214
+ def subtraction
215
+ @stack.push((@stack.pop - @stack.pop).abs) if 2 <= @stack.size
216
+ end
217
+
218
+ # .!:
219
+ def multiplication
220
+ @stack.push(@stack.pop * @stack.pop) if 2 <= @stack.size
221
+ end
222
+
223
+ # .$:
224
+ def quotient
225
+ @stack.push((f=@stack.pop)>(s=@stack.pop)? f/s : s/f) if 2 <= @stack.size
226
+ end
227
+
228
+ # .%:
229
+ def surplus
230
+ @stack.push((f=@stack.pop)>(s=@stack.pop)? f%s : s%f) if 2 <= @stack.size
231
+ end
232
+ end
233
+ end
data/lib/rpxem/stack.rb CHANGED
@@ -1,49 +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
- if (!arg.is_a? Integer)
42
- raise ArgumentError.new 'Argument must be Integer'
43
- elsif (arg != arg.abs)
44
- raise ArgumentError.new 'Argument must be positive'
45
- end
46
- end
47
- end
48
- end
49
- 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.4'
2
+ VERSION = '0.0.5'.freeze
3
3
  end
data/lib/rpxem.rb CHANGED
@@ -1,20 +1,20 @@
1
- require 'rpxem/interpreter'
2
- require 'rpxem/version'
3
-
4
- module RPxem
5
- class << self
6
- def new(options={})
7
- RPxem::Interpreter.new(options)
8
- end
9
-
10
- private
11
- def method_missing(name, *args, &block)
12
- return super unless new.respond_to?(name)
13
- new.__send__(name, *args, &block)
14
- end
15
-
16
- def respond_to?(name)
17
- new.respond_to?(name) || super(name)
18
- end
19
- end
20
- end
1
+ require 'rpxem/interpreter'
2
+ require 'rpxem/version'
3
+
4
+ module RPxem
5
+ class << self
6
+ def new(options={})
7
+ RPxem::Interpreter.new(options)
8
+ end
9
+
10
+ private
11
+ def method_missing(name, *args, &block)
12
+ return super unless new.respond_to?(name)
13
+ new.__send__(name, *args, &block)
14
+ end
15
+
16
+ def respond_to?(name)
17
+ new.respond_to?(name) || super(name)
18
+ end
19
+ end
20
+ end
data/rpxem.gemspec CHANGED
@@ -2,20 +2,23 @@
2
2
  require File.expand_path('../lib/rpxem/version', __FILE__)
3
3
 
4
4
  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, an esoteric programming language that enables you to create programs in 0-byte files.}
5
+ gem.name = 'rpxem'
6
+ gem.version = RPxem::VERSION
7
+ gem.authors = ['k.wakitani']
8
+ gem.email = ['k.wakitani@gmail.com']
9
+
8
10
  gem.summary = %q{Pxem implementation in Ruby}
11
+ 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
12
  gem.homepage = 'https://github.com/wktk/rpxem'
13
+ gem.license = 'MIT'
10
14
 
11
15
  gem.files = `git ls-files`.split($\)
12
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = 'rpxem'
15
18
  gem.require_paths = ['lib']
16
- gem.version = RPxem::VERSION
17
19
 
18
- gem.add_development_dependency 'rspec'
19
- gem.add_development_dependency 'rake'
20
- gem.add_development_dependency 'rdoc'
20
+ gem.add_development_dependency 'bundler', '~> 1.16'
21
+ gem.add_development_dependency 'rspec', '~> 3.8'
22
+ gem.add_development_dependency 'rake', '~> 10.0'
23
+ gem.add_development_dependency 'rdoc', '~> 6.0'
21
24
  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,197 +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 positive' do
20
- expect{ @stack.push(-1) }.to raise_error ArgumentError
21
- end
22
-
23
- it 'can be zero' do
24
- expect{ @stack.push(0) }.not_to raise_error
25
- end
26
-
27
- it 'can be Bignum' do
28
- expect{ @stack.push(13**13) }.not_to raise_error
29
- end
30
-
31
- it 'should be integer' do
32
- expect{ @stack << 'a' }.to raise_error ArgumentError
33
- expect{ @stack << 0.1 }.to raise_error ArgumentError
34
- end
35
-
36
- it 'can check in #new' do
37
- expect{ RPxem::Stack.new([1, 2, 'san']) }.to raise_error ArgumentError
38
- end
39
- end
40
-
41
- describe RPxem::Interpreter do
42
- before do
43
- @pxem = RPxem.new
44
- end
45
-
46
- describe 'initializing' do
47
- it 'can set initial stack' do
48
- capture{ @pxem.run('.p', '', RPxem::Stack.new([99, 98, 97])) }.should == 'abc'
49
- end
50
-
51
- it 'can open file' do
52
- testfile = File.join(File.dirname(__FILE__), 'world!.fHello,.pxe')
53
- capture{ @pxem.open(testfile) }.should == 'Hello, Pxem world!'
54
- end
55
-
56
- it 'can merge command mapping' do
57
- pxem = RPxem.new({'q' => 'output_all', 'c' => 'output_all'})
58
- capture{ pxem.run('Hi.q') }.should == 'Hi'
59
- capture{ pxem.run('Hi.c') }.should == 'Hi'
60
- end
61
- end
62
-
63
- describe 'get result' do
64
- it 'should return remaining stack' do
65
- @pxem.run('Hi.d').should == [105, 72]
66
- end
67
-
68
- it 'can read stack' do
69
- @pxem.run('a.d')
70
- @pxem.stack.should == [97]
71
- end
72
-
73
- it 'can read temp area' do
74
- @pxem.run('a.t')
75
- @pxem.temp.should == 97
76
- end
77
- end
78
-
79
- describe 'Pxem commands' do
80
- describe 'I/O' do
81
- it '.p' do
82
- capture{ @pxem.run('Hello, world!.p') }.should == 'Hello, world!'
83
- end
84
-
85
- it '.o' do
86
- capture{ @pxem.run('Hi.o') }.should == 'H'
87
- end
88
-
89
- it '.n' do
90
- capture{ @pxem.run('Hi.n') }.should == '72'
91
- end
92
-
93
- #it '.i' do
94
- #end
95
-
96
- #it '._' do
97
- #end
98
- end
99
-
100
- describe 'Stack' do
101
- it '.c' do
102
- @pxem.run('Hi.c').should == [105, 72, 72]
103
- end
104
-
105
- it '.s' do
106
- @pxem.run('Hi.s').should == [105]
107
- end
108
-
109
- it '.v' do
110
- @pxem.run('Hi.v').should == [72, 105]
111
- end
112
- end
113
-
114
- describe 'File' do
115
- it '.f' do
116
- @pxem.run('.f', 'File').should == [101, 108, 105, 70]
117
- end
118
-
119
- it '.e' do
120
- @pxem.run('.e', 'File.d').should == [101, 108, 105, 70]
121
- end
122
- end
123
-
124
- describe 'Rand' do
125
- it '.r' do
126
- @pxem.run('d.r').first.should be_within(100).of(0)
127
- end
128
- end
129
-
130
- describe 'Loop' do
131
- it '.w' do
132
- capture{ @pxem.run('a.whoge.paa.-.a') }.should == 'hoge'
133
- end
134
-
135
- it '.x' do
136
- capture{ @pxem.run('e.xhog.pba.a') }.should == 'hoge'
137
- end
138
-
139
- it '.y' do
140
- capture{ @pxem.run('e.yhog.pab.a') }.should == 'hoge'
141
- end
142
-
143
- it '.z' do
144
- capture{ @pxem.run('e.zhog.paa.a') }.should == 'hoge'
145
- end
146
-
147
- it '.a' do
148
- capture{ @pxem.run('e.zhog.pe.zhog.paa.aaa.a') } == 'hogehoge'
149
- end
150
- end
151
-
152
- describe 'Temporary area' do
153
- it '.t' do
154
- @pxem.run('a.t')
155
- @pxem.temp.should == 97
156
- end
157
-
158
- it '.m' do
159
- @pxem.run('a.t.m.m').should == [97, 97]
160
- end
161
- end
162
-
163
- describe '.d' do
164
- it '.d' do
165
- @pxem.run('Hi.d').should == [105, 72]
166
- end
167
- end
168
-
169
- describe 'Math' do
170
- it '.+' do
171
- @pxem.run('ab.+').should == [98 + 97]
172
- @pxem.run('ba.+').should == [98 + 97]
173
- end
174
-
175
- it '.-' do
176
- @pxem.run('ab.-').should == [98 - 97]
177
- @pxem.run('ba.-').should == [98 - 97]
178
- end
179
-
180
- it '.!' do
181
- @pxem.run('ab.!').should == [98 * 97]
182
- @pxem.run('ba.!').should == [98 * 97]
183
- end
184
-
185
- it '.$' do
186
- @pxem.run('ab.$').should == [98 / 97]
187
- @pxem.run('ba.$').should == [98 / 97]
188
- end
189
-
190
- it '.%' do
191
- @pxem.run('ab.%').should == [98 % 97]
192
- @pxem.run('ba.%').should == [98 % 97]
193
- end
194
- end
195
- end
196
- end
197
- 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')).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
metadata CHANGED
@@ -1,74 +1,82 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpxem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
- - wktk
7
+ - k.wakitani
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-08 00:00:00.000000000 Z
11
+ date: 2018-09-15 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: rspec
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
- version: '0'
33
+ version: '3.8'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
- version: '0'
40
+ version: '3.8'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - "~>"
36
46
  - !ruby/object:Gem::Version
37
- version: '0'
47
+ version: '10.0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - "~>"
44
53
  - !ruby/object:Gem::Version
45
- version: '0'
54
+ version: '10.0'
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: rdoc
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - "~>"
52
60
  - !ruby/object:Gem::Version
53
- version: '0'
61
+ version: '6.0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - "~>"
60
67
  - !ruby/object:Gem::Version
61
- version: '0'
68
+ version: '6.0'
62
69
  description: RPxem is a Ruby implementation of Pxem, an esoteric programming language
63
70
  that enables you to create programs in 0-byte files.
64
71
  email:
65
- - wktk@wktk.in
72
+ - k.wakitani@gmail.com
66
73
  executables:
67
74
  - rpxem
68
75
  extensions: []
69
76
  extra_rdoc_files: []
70
77
  files:
71
- - .gitignore
78
+ - ".gitignore"
79
+ - ".travis.yml"
72
80
  - Gemfile
73
81
  - MIT-LICENSE.txt
74
82
  - README.md
@@ -83,28 +91,28 @@ files:
83
91
  - spec/rpxem_spec.rb
84
92
  - spec/world!.fHello,.pxe
85
93
  homepage: https://github.com/wktk/rpxem
86
- licenses: []
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
87
97
  post_install_message:
88
98
  rdoc_options: []
89
99
  require_paths:
90
100
  - lib
91
101
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
102
  requirements:
94
- - - ! '>='
103
+ - - ">="
95
104
  - !ruby/object:Gem::Version
96
105
  version: '0'
97
106
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
107
  requirements:
100
- - - ! '>='
108
+ - - ">="
101
109
  - !ruby/object:Gem::Version
102
110
  version: '0'
103
111
  requirements: []
104
112
  rubyforge_project:
105
- rubygems_version: 1.8.23
113
+ rubygems_version: 2.7.6
106
114
  signing_key:
107
- specification_version: 3
115
+ specification_version: 4
108
116
  summary: Pxem implementation in Ruby
109
117
  test_files:
110
118
  - spec/rpxem_helper.rb