#!/bin/sh

echo -n $0: 'MAT INPUT... '

cat >test.fil <<'eof'
1,2,3
4,5,6,0
7,8
eof

cat >test.bas <<'eof'
' square and user interaction test
dim a(2,2)
mat input a
mat print a
mat input a
mat print a

' 1d file test
dim csv%(3)
open "i", #1, "test.fil"
do until eof(1)
  mat input #1, csv%
  write csv%(1),csv%(2),csv%(3)
loop
close #1

' 2d file test - loop to validate EOF operation
open "i", #1, "test.fil"
mat input #1, csv%(3,2)
close #1
mat write csv%
eof

cat >test.input <<'eof'
1,2,3,4,5
1
3,4
eof

cat >test.ref <<'eof'
? 
 1             2            
 3             4            
? ? 
 1             0            
 3             4            
1,2,3
4,5,6
7,8,0
1,2
3,0
4,5
eof

sh ./test/runbas test.bas <test.input >test.data

if cmp test.ref test.data
then
  #rm -f test.*
  echo passed
else
  echo failed
  exit 1
fi
