rasel 0.1.0 → 1.0.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 -8
  3. data/rasel.gemspec +1 -1
  4. data/test.rb +22 -16
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77212c7620ca6230ba0c4562b45787671cffbb21
4
- data.tar.gz: ebdcac80864dffb0df2bebb02d2a7f15b5362f89
3
+ metadata.gz: 587ff1f458d557603238203069109e7515486684
4
+ data.tar.gz: 847fabdaaf7016f1b8992004ab1fc7b965e4addb
5
5
  SHA512:
6
- metadata.gz: 3bb914dd708affb43b1e49464e6309cfc1efc63a6836f32cde276cf84b6a2366a75832cf1eb25f84f15e48f5921427be7a36c2f32dcc871b6e70f83659927123
7
- data.tar.gz: 128a0eb852b51f588cc7d4eb9461e9be0321a9983a24bcc8e33ba0ce5e2a057102702ce052fcbb027239932d742a68f3d40dc3ecc039219a19b2e1e2c8fd886d
6
+ metadata.gz: 6594fb5176f5cf7e21d06bbc5cc1f376ad97917d1ff6a844ba850a5930350c893886176a1c5df904cbf6f212864ce77a138249a62ad934e66937affc48ef0633
7
+ data.tar.gz: 566dbc8e76fe9afa54a181051981a5f67f8009c75e67eb255f42caaf8086b10d43968ea54123173604b785717873e2473514970bc91fe780c3c4281404ceae5e
data/lib/rasel.rb CHANGED
@@ -5,7 +5,7 @@ def RASEL source, stdout = StringIO.new, stdin = STDIN
5
5
  lines = source.tap{ |_| fail "empty source" if _.empty? }.gsub(/ +$/,"").split(?\n)
6
6
  code = lines.map{ |_| _.ljust(lines.map(&:size).max).bytes }
7
7
  stack = []
8
- pop = ->{ stack.pop || 0r }
8
+ pop = ->{ stack.pop || 0 }
9
9
  dx, dy = 1, 0
10
10
  x, y = -1, 0
11
11
 
@@ -49,24 +49,24 @@ def RASEL source, stdout = StringIO.new, stdin = STDIN
49
49
  case char
50
50
  when ?\s
51
51
 
52
- when ?0..?9, ?A..?Z ; stack.push char.to_i(36).to_r
52
+ when ?0..?9, ?A..?Z ; stack.push char.to_i 36
53
53
  when ?" ; stringmode ^= true
54
54
  when ?# ; move[]
55
55
  when ?$ ; pop[]
56
56
  when ?: ; stack.concat [pop[]] * 2
57
57
  when ?- ; stack.push -(pop[] - pop[])
58
- when ?\\ ; stack.concat [pop[], pop[]]
59
- when ?/ ; b, a = pop[], pop[]; stack.push (b.zero? ? 0 : a / b)
60
- when ?% ; b, a = pop[], pop[]; stack.push (b.zero? ? 0 : a % b)
58
+ when ?/ ; b, a = pop[], pop[]; stack.push (b.zero? ? 0 : Rational(a) / b)
59
+ when ?% ; b, a = pop[], pop[]; stack.push (b.zero? ? 0 : Rational(a) % b)
61
60
  when ?v ; dx, dy = 0, 1
62
61
  when ?> ; dx, dy = 1, 0
63
62
  when ?^ ; dx, dy = 0, -1
64
63
  when ?< ; dx, dy = -1, 0
65
64
  when ?? ; move[] if pop[] > 0
66
- when ?a
65
+ when ?\\
67
66
  t = pop[]
68
- error[] if 0 > t || 1 != t.denominator
69
- stack.push t.zero? ? 0 : stack[-t] || 0
67
+ error[] if 1 != t.denominator
68
+ stack.unshift 0 until stack.size > t
69
+ stack[-t-1], stack[-1] = stack[-1], stack[-t-1] unless 0 > t
70
70
  when ?. ; stdout.print "#{_ = pop[]; 1 != _.denominator ? _.to_f : _.to_i} "
71
71
  when ?, ; stdout.print "#{_ = pop[]; 1 != _.denominator ? error[] : _ < 0 || _ > 255 ? error[] : _.to_i.chr}"
72
72
  when ?~ ; if _ = stdin.getbyte then stack.push _; move[] end
data/rasel.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rasel"
3
- spec.version = "0.1.0"
3
+ spec.version = "1.0.0"
4
4
  spec.summary = "Random Access Stack Esoteric Language"
5
5
 
6
6
  spec.author = "Victor Maslov aka Nakilon"
data/test.rb CHANGED
@@ -6,27 +6,33 @@ require_relative "lib/rasel"
6
6
 
7
7
  # TODO: assert that all RASEL() return with 0 exit code unless the opposite is expected
8
8
 
9
- describe "tests" do
10
- around{ |test| Timeout.timeout(1){ test.call } }
11
- def assert_stack expectation, *args
12
- result = RASEL *args
13
- assert_equal expectation.map(&:to_r), [*result.stack, result.exitcode]
14
- end
15
-
9
+ describe "bin" do
10
+ around{ |test| Timeout.timeout(RUBY_PLATFORM == "java" ? 4 : 1){ test.call } }
16
11
  describe "executable" do
17
12
  require "open3"
18
13
  [
14
+ ["cat.rasel < examples/cat.rasel", 0, File.read("examples/cat.rasel")],
19
15
  ["helloworld.rasel", 0, "Hello, World!\n"],
20
16
  ["naive_if_zero.rasel", 0, "false\nfalse\ntrue\nfalse\nfalse\n"],
21
17
  ["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|
18
+ ["factorial.rasel", 0, "120 ", "echo 5 | "],
19
+ ["fibonacci.rasel", 5, "3 ", "echo 5 | "],
20
+ ["project_euler/1.rasel", 0, "233168 ", "echo 1000 | "],
21
+ ].each do |cmd, expected_status, expected_stdout, prefix|
24
22
  it cmd do
25
- string, status = Open3.capture2e "./bin/rasel examples/#{cmd}"
23
+ string, status = Open3.capture2e "#{prefix}./bin/rasel examples/#{cmd}"
26
24
  assert_equal [expected_status, expected_stdout], [status.exitstatus, string]
27
25
  end
28
26
  end
29
27
  end
28
+ end
29
+
30
+ describe "lib" do
31
+ around{ |test| Timeout.timeout(1){ test.call } }
32
+ def assert_stack expectation, *args
33
+ result = RASEL *args
34
+ assert_equal expectation, [*result.stack, result.exitcode]
35
+ end
30
36
 
31
37
  describe "non-instructional" do
32
38
  it "trim spaces and empty lines" do
@@ -84,7 +90,6 @@ describe "tests" do
84
90
  it "0..9, A..Z" do assert_stack [*0..35], "#{[*0..9].join}#{[*?A..?Z].join}@" end
85
91
  it "$" do assert_stack [1], "$12$@" end
86
92
  it ":" do assert_stack [0, 0, 1, 1], ":1:@" end
87
- it ?\\ do assert_stack [0, 1, 0], "\\1\\@" end
88
93
  it "><^v" do
89
94
  assert_stack [1, 2, 3, 4],
90
95
  <<~HEREDOC
@@ -141,6 +146,12 @@ describe "tests" do
141
146
  assert_stack expectation, "^@1?#{code.reverse}".chars.zip.transpose.join(?\n)
142
147
  end
143
148
  end
149
+ it "\\" do assert_stack [2, 0, 4, 0], "4321001-02-\\\\\\\\\\@" end
150
+ it "exit status code 255 on non-integer \\ index" do
151
+ assert_equal 0, RASEL("01/\\@").exitcode
152
+ assert_equal 255, RASEL("12/\\@").exitcode
153
+ assert_equal 255, RASEL("12/-\\@").exitcode
154
+ end
144
155
  end
145
156
 
146
157
  describe "new" do
@@ -151,11 +162,6 @@ describe "tests" do
151
162
  it "exit status code 255 on non-integer jump" do
152
163
  assert_equal 255, RASEL("12/j@").exitcode
153
164
  end
154
- it "a:." do assert_equal "2 0 0 ", RASEL("21a:.a:.a:.@").stdout.string end
155
- it "exit status code 255 on negative 'take at' argument" do
156
- assert_equal 255, RASEL("1-a@").exitcode
157
- assert_equal 255, RASEL("12/a@").exitcode
158
- end
159
165
  end
160
166
 
161
167
  end
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.1.0
4
+ version: 1.0.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-17 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-around