From d217d597503a098b65ea7820b1c93e65e3f98025 Mon Sep 17 00:00:00 2001 From: Peter Camilleri Date: Sun, 25 Jan 2015 14:35:39 -0500 Subject: [PATCH] Added the .cr method to OutStream. --- integration/out_stream_library_tests.rb | 13 +++++++++---- integration/stdio_library_tests.rb | 2 +- lib/fOOrth/library/out_stream_library.rb | 6 +++++- lib/fOOrth/library/stdio_library.rb | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/integration/out_stream_library_tests.rb b/integration/out_stream_library_tests.rb index bf3e27c..aae0bbc 100644 --- a/integration/out_stream_library_tests.rb +++ b/integration/out_stream_library_tests.rb @@ -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] diff --git a/integration/stdio_library_tests.rb b/integration/stdio_library_tests.rb index 9599837..d517595 100644 --- a/integration/stdio_library_tests.rb +++ b/integration/stdio_library_tests.rb @@ -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 diff --git a/lib/fOOrth/library/out_stream_library.rb b/lib/fOOrth/library/out_stream_library.rb index b077a0e..e89661d 100644 --- a/lib/fOOrth/library/out_stream_library.rb +++ b/lib/fOOrth/library/out_stream_library.rb @@ -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 diff --git a/lib/fOOrth/library/stdio_library.rb b/lib/fOOrth/library/stdio_library.rb index 1a5825c..afc88b3 100644 --- a/lib/fOOrth/library/stdio_library.rb +++ b/lib/fOOrth/library/stdio_library.rb @@ -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.