Anonymous avatar Anonymous committed c58f2c8

move test.rb to test directory, even if it is not run

Comments (0)

Files changed (4)

example/reverse.spl

+Outputting Input Reversedly.
+
+Othello, a stacky man.
+Lady Macbeth, who pushes him around till he pops.
+
+
+                    Act I: The one and only.
+
+                    Scene I: In the beginning, there was nothing.
+
+[Enter Othello and Lady Macbeth]
+
+Othello:
+ You are nothing!
+
+                    Scene II: Pushing to the very end.
+
+Lady Macbeth:
+ Open your mind! Remember yourself.
+
+Othello:
+ You are as hard as the sum of yourself and a stone wall. Am I as
+ horrid as a flirt-gill?
+
+Lady Macbeth:
+ If not, let us return to scene II. Recall your imminent death!
+
+Othello:
+ You are as small as the difference between yourself and a hair!
+
+                    Scene III: Once you pop, you can't stop!
+
+Lady Macbeth:
+ Recall your unhappy childhood. Speak your mind!
+
+Othello:
+ You are as vile as the sum of yourself and a toad! Are you better
+ than nothing?
+
+Lady Macbeth:
+ If so, let us return to scene III.
+
+                    Scene IV: The end.
+
+[Exeunt]

src/builtins/say.pir

 .sub 'open_mind'
     $P0 = 'find_other'()
     $P1 = getstdin
-    readline $S1, $P1
+    read $S1, 1
+    if ''==$S1 goto empty
     $I1 = ord $S1
+    goto end
+  empty:
+    $I1 = -1
+  end:
     'valset'($P0,$I1)
 .end
 
 
 use lib qw( . lib ../lib ../../lib ../../lib );
 use Parrot::Test::Harness language => 'z2',
-                          compiler => 'z2.pbc',
+                          compiler => 'z2.pbc';
 
+#!/usr/bin/env ruby
+STR="Hello World!\n"
+$i=0
+
+DIR=File.join(File.dirname(__FILE__),'..')
+
+puts "1..74"
+def with_prog(name)
+  p str= %W[../../parrot z2.pir example/#{name}.spl].map{|x| File.join(DIR,x)}*" "
+  IO.popen(str,'r+') do |io|
+    yield io
+  end
+end
+
+def is(x,y)
+  $i+=1
+  if x==y
+    puts "ok #$i"
+  else
+    puts "not ok #$i -- #{x} expected but got #{y}"
+  end
+end
+
+with_prog 'fibonacci2' do |p|
+  DATA.each do |o|
+    is o, p.readline
+  end
+end
+
+
+with_prog 'hello' do |prog|
+  is STR, prog.readline
+end
+
+with_prog 'reverse' do |prog|
+  prog.write(STR)
+  prog.close_write
+  is STR.reverse, prog.read
+end
+
+with_prog 'primes' do |prog|
+  ary=%w[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97];
+  is '>',prog.read(1)
+  prog.write('100\n')
+  prog.close_write
+  ary.each do |el|
+    is el, prog.readline.chomp
+  end
+end
+
+with_prog 'sum2' do |prog|
+  prog.puts('1')
+  prog.puts('5')
+  prog.close_write
+  is '6', prog.readline.chomp
+end
+__END__
+0
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+144
+233
+377
+610
+987
+1597
+2584
+4181
+6765
+10946
+17711
+28657
+46368
+75025
+121393
+196418
+317811
+514229
+832040
+1346269
+2178309
+3524578
+5702887
+9227465
+14930352
+24157817
+39088169
+63245986
+102334155
+165580141
+267914296
+433494437
+701408733
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.