rasel 0.0.1 → 0.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rasel.rb +8 -13
  3. data/rasel.gemspec +1 -1
  4. data/test.rb +15 -17
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cae44ed33f59f745a94923f22d89396ab952da24
4
- data.tar.gz: 9eb3e3ee26db600781c4086cacfa7455a44dbdd2
3
+ metadata.gz: 77212c7620ca6230ba0c4562b45787671cffbb21
4
+ data.tar.gz: ebdcac80864dffb0df2bebb02d2a7f15b5362f89
5
5
  SHA512:
6
- metadata.gz: c18aa154e357e510ad159b108ed639454f30bcafe5b3cd9ef9d9b7002c2464632851180be9edf8d83424e1418f3f6058f2043c9291b020fb12b5bf7f388715ce
7
- data.tar.gz: 0c4160519d76732eb8487a05582e6a22a7bbb6ed2487bfdc4f40676129ce410afae3fa99019ba6a899574c2aac053e4e9a29dbbe7294a5879c46caeb5db1995d
6
+ metadata.gz: 3bb914dd708affb43b1e49464e6309cfc1efc63a6836f32cde276cf84b6a2366a75832cf1eb25f84f15e48f5921427be7a36c2f32dcc871b6e70f83659927123
7
+ data.tar.gz: 128a0eb852b51f588cc7d4eb9461e9be0321a9983a24bcc8e33ba0ce5e2a057102702ce052fcbb027239932d742a68f3d40dc3ecc039219a19b2e1e2c8fd886d
@@ -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 c = stdin.getbyte then stack.push c else reverse[] end
72
+ when ?~ ; if _ = stdin.getbyte then stack.push _; move[] end
72
73
  when ?&
73
- getc = ->{ stdin.getc or (reverse[]; throw nil) }
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[] ; c << cc end
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
- if 0 < t
84
- y = (y + dy * t.to_i) % code.size
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rasel"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.1.0"
4
4
  spec.summary = "Random Access Stack Esoteric Language"
5
5
 
6
6
  spec.author = "Victor Maslov aka Nakilon"
data/test.rb CHANGED
@@ -14,19 +14,17 @@ describe "tests" do
14
14
  end
15
15
 
16
16
  describe "executable" do
17
- it "hello world" do
18
- require "open3"
19
- require "tempfile"
20
- begin
21
- file = Tempfile.new "temp.rasel"
22
- file.write 'A"!dlroW ,olleH">:?@,Hj'
23
- file.flush
24
- string, status = Open3.capture2e "./bin/rasel #{file.path}"
25
- ensure
26
- file.close
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 [2], "~1@2", StringIO.new, StringIO.new
122
- assert_stack [0, 10, 255, 0], "~~~~@", StringIO.new,
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 [2], "&1@2", StringIO.new, StringIO.new
124
+ assert_stack [1], "&1@2", StringIO.new, StringIO.new
127
125
  [0, 10, 255].each do |c|
128
- assert_stack [12, 34, c], "&&~@", StringIO.new,
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.1
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-16 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-around