Added the .cr method to OutStream.

This commit is contained in:
Peter Camilleri 2015-01-25 14:35:39 -05:00
parent 312925af98
commit d217d59750
4 changed files with 17 additions and 8 deletions

View file

@ -25,29 +25,34 @@ class OutStreamLibraryTester < MiniTest::Unit::TestCase
end
def test_that_we_can_write
foorth_run($osfn + 'OutStream .create .close')
foorth_equal($osfn + 'OutStream .create .close')
assert(File.exists?($osfn[1...-2]))
do_cleanup
end
def test_that_we_can_write_stuff
foorth_run($osfn + 'OutStream .create dup 42 swap . .close')
foorth_equal($osfn + 'OutStream .create dup 42 swap . .close')
assert_equal(["42"], IO.readlines($osfn[1...-2]))
do_cleanup
end
def test_that_we_can_write_stuff_too
foorth_run($osfn + 'OutStream .create dup f"Hello World" .close')
foorth_equal($osfn + 'OutStream .create dup f"Hello World" .close')
assert_equal(["Hello World"], IO.readlines($osfn[1...-2]))
do_cleanup
end
def test_that_we_can_write_stuff_character
foorth_run($osfn + 'OutStream .create 65 over .emit .close')
foorth_equal($osfn + 'OutStream .create 65 over .emit .close')
assert_equal(["A"], IO.readlines($osfn[1...-2]))
do_cleanup
end
def test_that_we_can_write_out_lines
foorth_equal($osfn + 'OutStream .create dup f"Hello" dup .cr dup f"World" .close', [])
assert_equal(["Hello\n", "World"], IO.readlines($osfn[1...-2]))
do_cleanup
end
def do_cleanup
name = $osfn[1...-2]

View file

@ -24,7 +24,7 @@ class StdioLibraryTester < MiniTest::Unit::TestCase
end
def test_the_dot_cr
foorth_output('.cr', "\n")
foorth_output('cr', "\n")
end
def test_the_space

View file

@ -39,7 +39,7 @@ module XfOOrth
#[obj] . []; print out the object as a string to the OutStream instance.
#[obj an_outstream] . []; print out the object as a string to the OutStream instance.
out_stream.create_shared_method('.', TosSpec, [],
&lambda {|vm| file << vm.pop})
@ -53,5 +53,9 @@ module XfOOrth
out_stream.create_shared_method('.emit', TosSpec, [],
&lambda {|vm| file << vm.pop.to_foorth_c})
#[an_outstream] .cr []; print out a newline to the OutStream instance.
out_stream.create_shared_method('.cr', TosSpec, [],
&lambda {|vm| file << "\n"})
end

View file

@ -14,8 +14,8 @@ module XfOOrth
&lambda {|vm| print self.to_s})
#Force a new line.
# [] .cr []; prints a new line.
VirtualMachine.create_shared_method('.cr', MacroSpec,
# [] cr []; prints a new line.
VirtualMachine.create_shared_method('cr', MacroSpec,
[:macro, "puts; "])
#Force a space.