rasel 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasel.rb +8 -13
- data/rasel.gemspec +1 -1
- data/test.rb +15 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77212c7620ca6230ba0c4562b45787671cffbb21
|
4
|
+
data.tar.gz: ebdcac80864dffb0df2bebb02d2a7f15b5362f89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb914dd708affb43b1e49464e6309cfc1efc63a6836f32cde276cf84b6a2366a75832cf1eb25f84f15e48f5921427be7a36c2f32dcc871b6e70f83659927123
|
7
|
+
data.tar.gz: 128a0eb852b51f588cc7d4eb9461e9be0321a9983a24bcc8e33ba0ce5e2a057102702ce052fcbb027239932d742a68f3d40dc3ecc039219a19b2e1e2c8fd886d
|
data/lib/rasel.rb
CHANGED
@@ -40,6 +40,7 @@ def RASEL source, stdout = StringIO.new, stdin = STDIN
|
|
40
40
|
byte = code[y][x]
|
41
41
|
char = byte.chr
|
42
42
|
STDERR.puts [char, stringmode, (stack.last Integer ENV["DEBUG"] rescue stack)].inspect if ENV.key? "DEBUG"
|
43
|
+
|
43
44
|
next stack.push byte if stringmode && char != ?"
|
44
45
|
return Struct.new(:stdout, :stack, :exitcode).new stdout, stack, (
|
45
46
|
t = pop[]
|
@@ -68,27 +69,21 @@ def RASEL source, stdout = StringIO.new, stdin = STDIN
|
|
68
69
|
stack.push t.zero? ? 0 : stack[-t] || 0
|
69
70
|
when ?. ; stdout.print "#{_ = pop[]; 1 != _.denominator ? _.to_f : _.to_i} "
|
70
71
|
when ?, ; stdout.print "#{_ = pop[]; 1 != _.denominator ? error[] : _ < 0 || _ > 255 ? error[] : _.to_i.chr}"
|
71
|
-
when ?~ ; if
|
72
|
+
when ?~ ; if _ = stdin.getbyte then stack.push _; move[] end
|
72
73
|
when ?&
|
73
|
-
getc = ->{ stdin.getc or
|
74
|
+
getc = ->{ stdin.getc or throw nil }
|
74
75
|
catch nil do
|
75
76
|
nil until (?0..?9).include? c = getc[]
|
76
|
-
while (?0..?9).include? cc = getc
|
77
|
-
stdin.ungetbyte cc
|
77
|
+
while (?0..?9).include? cc = stdin.getc ; c << cc end
|
78
|
+
stdin.ungetbyte cc if cc
|
78
79
|
stack.push c.to_i
|
80
|
+
move[]
|
79
81
|
end
|
80
82
|
when ?j
|
81
83
|
t = pop[]
|
82
84
|
error[] if 1 != t.denominator
|
83
|
-
|
84
|
-
|
85
|
-
x = (x + dx * t.to_i) % code[y].size
|
86
|
-
else
|
87
|
-
reverse[]
|
88
|
-
y = (y - dy * t.to_i) % code.size
|
89
|
-
x = (x - dx * t.to_i) % code[y].size
|
90
|
-
reverse[]
|
91
|
-
end
|
85
|
+
y = (y + dy * t.to_i) % code.size
|
86
|
+
x = (x + dx * t.to_i) % code[y].size
|
92
87
|
|
93
88
|
else ; error[]
|
94
89
|
end
|
data/rasel.gemspec
CHANGED
data/test.rb
CHANGED
@@ -14,19 +14,17 @@ describe "tests" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "executable" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
file.unlink
|
17
|
+
require "open3"
|
18
|
+
[
|
19
|
+
["helloworld.rasel", 0, "Hello, World!\n"],
|
20
|
+
["naive_if_zero.rasel", 0, "false\nfalse\ntrue\nfalse\nfalse\n"],
|
21
|
+
["short_if_zero.rasel", 0, "false\nfalse\ntrue\nfalse\nfalse\n"],
|
22
|
+
["cat.rasel < examples/cat.rasel", 0, File.read("examples/cat.rasel")],
|
23
|
+
].each do |cmd, expected_status, expected_stdout|
|
24
|
+
it cmd do
|
25
|
+
string, status = Open3.capture2e "./bin/rasel examples/#{cmd}"
|
26
|
+
assert_equal [expected_status, expected_stdout], [status.exitstatus, string]
|
28
27
|
end
|
29
|
-
assert_equal [0, "Hello, World!\n"], [status.exitstatus, string]
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
@@ -118,15 +116,15 @@ describe "tests" do
|
|
118
116
|
assert_equal 255, RASEL("12/@").exitcode
|
119
117
|
end
|
120
118
|
it "~" do
|
121
|
-
assert_stack [
|
122
|
-
assert_stack [0, 10, 255, 0], "
|
119
|
+
assert_stack [1], "~1@2", StringIO.new, StringIO.new
|
120
|
+
assert_stack [0, 10, 255, 0], "~0~0~0~0@", StringIO.new,
|
123
121
|
StringIO.new.tap{ |s| [0, 10, 255, 0].reverse_each &s.method(:ungetbyte) }
|
124
122
|
end
|
125
123
|
it "&" do
|
126
|
-
assert_stack [
|
124
|
+
assert_stack [1], "&1@2", StringIO.new, StringIO.new
|
127
125
|
[0, 10, 255].each do |c|
|
128
|
-
assert_stack [12, 34, c], "
|
129
|
-
StringIO.new.tap{ |s| "#{c.chr}-12#{c.chr}-34#{c.chr}".bytes.reverse_each &s.method(:ungetbyte) }
|
126
|
+
assert_stack [12, 34, c, 56], "&0&0~0&0@", StringIO.new,
|
127
|
+
StringIO.new.tap{ |s| "#{c.chr}-12#{c.chr}-34#{c.chr}-56".bytes.reverse_each &s.method(:ungetbyte) }
|
130
128
|
end
|
131
129
|
end
|
132
130
|
[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest-around
|