Skip to content

Commit c4c3a81

Browse files
committed
[Rb] Implements non-matching in interpreter tests and file prims
1 parent fbe671c commit c4c3a81

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

rosetta-test-rb/interpreter-tests.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def matches(result, target)
6161
eval_result = error
6262
end
6363

64-
if matches(eval_result, entry["expected"])
64+
if not entry.member?("expected") or matches(eval_result, entry["expected"])
6565
puts "✅: #{input}"
6666
else
6767
if expected_failures.include?(input)

rosetta-test-rb/scheme.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def call(*args)
4949
end
5050
end
5151

52+
EOF_OBJECT = :"#<eof-object>"
53+
5254
GLOBAL_DICT = {
5355
:+ => proc { |a, b| a + b },
5456
:* => proc { |a, b| a * b },
@@ -98,14 +100,29 @@ def call(*args)
98100
:"string-split" => proc { |s, sep| s.split(sep) },
99101
:"string-trim" => proc { |s| s.strip },
100102
:"string-upcase" => proc { |s| s.upcase },
103+
:"eof-object?" => proc { |a| a == EOF_OBJECT },
101104
:symbol? => proc { |a| a.is_a?(Symbol) },
102105
:"with-exception-handler" => proc { |handler, body|
103106
begin
104107
body.call
105108
rescue => e
106109
handler.call(e)
107110
end
108-
}
111+
},
112+
:"open-output-file" => proc { |filename| [File.open(filename, "w"), "w"] },
113+
:"open-input-file" => proc { |filename| [File.open(filename, "r"), "r"] },
114+
:"close-port" => proc { |port_tuple | port_tuple[0].close },
115+
:"port?" => proc { |port_tuple| port_tuple[0].is_a?(File) },
116+
:"output-port?" => proc { |port_tuple| port_tuple[0].is_a?(File) && port_tuple[1] == "w" },
117+
:"input-port?" => proc { |port_tuple| port_tuple[0].is_a?(File) && port_tuple[1] == "r" },
118+
:"read-char" => proc { |port_tuple|
119+
begin
120+
port_tuple[0].readchar
121+
rescue EOFError
122+
EOF_OBJECT
123+
end},
124+
:"write-char" => proc { |char, port_tuple| port_tuple[0].write(char) }
125+
109126
}.entries.transpose
110127
GLOBAL_ENV = Environment.new(GLOBAL_DICT[0], GLOBAL_DICT[1])
111128

0 commit comments

Comments
 (0)