public
Description: a Scheme written in Ruby, but implemented on the bus!
Homepage: http://bus-scheme.rubyforge.org
Clone URL: git://github.com/technomancy/bus-scheme.git
implemented (read "filename") for reading files from disk
JackDanger (author)
Sun Jun 01 15:21:25 -0700 2008
commit  5dcfdbff04360b26e1cbc6efdf4c692c7a1d817d
tree    d380cfbdbf1f06d2394fb9d0292447c6b35f5d72
parent  db9043eadfcf42ccae7234c84156a08fe4ec79f4
...
26
27
28
29
 
 
30
31
32
...
26
27
28
 
29
30
31
32
33
0
@@ -26,7 +26,8 @@ module BusScheme
0
   define 'now', primitive { Time.now }
0
   define 'regex', primitive { |r| Regexp.new(Regexp.escape(r)) }
0
 
0
- define 'read', primitive { gets }
0
+ define 'read', primitive {|*args| args.empty? ? gets : File.read(args.first) }
0
+ # TODO: give read and write the same interface
0
   define 'write', primitive { |obj| puts obj.inspect; 0 }
0
   define 'display', primitive { |obj| puts obj }
0
   
...
1
2
 
3
4
5
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
1
2
3
4
5
6
...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
0
@@ -1,5 +1,6 @@
0
 $LOAD_PATH << File.dirname(__FILE__)
0
 require 'test_helper'
0
+require 'stringio'
0
 
0
 class PrimitivesTest < Test::Unit::TestCase
0
   def test_test_framework
0
@@ -46,6 +47,18 @@ class PrimitivesTest < Test::Unit::TestCase
0
     assert_evals_to false, "(and #f (assert #f))"
0
     assert_evals_to true, "(or #t (assert #f))"
0
   end
0
+
0
+ def test_read_with_filename_reads_file_into_a_string
0
+ filename = File.join(File.dirname(__FILE__), '..', 'COPYING')
0
+ assert_equal File.read(filename), eval!("(read \"#{filename}\")")
0
+ end
0
+
0
+ def test_read_without_filename_gets_from_stdin
0
+ $stdin = StringIO.new('gets test')
0
+ assert_equal 'gets test', eval!("(read)")
0
+ ensure
0
+ $stdin = STDIN
0
+ end
0
 
0
   def test_booleans
0
     assert_evals_to false, '#f'

Comments

    No one has commented yet.