Basic file tests

John Leuner jewel at pixie.co.za
Wed Jan 21 07:03:55 PST 2004


I have written some very basic tests for file.slate.

src/file.test
src/sunit/file/testfile.txt

I am not sure whether I have to call close on each File or whether the
garbage collector will eventually call some kind of finalizer.


-- 
John Leuner <jewel at pixie.co.za>
-------------- next part --------------
Tests addSlot: #File valued: TestCase derive.

t@(Tests File traits) testOpen
[ | reader |
 reader: (File open: 'src/sunit/file/testfile.txt') reader.
 t assert: (reader isNil) not.
].

t@(Tests File traits) testContents
[ | contents comp |
 contents: (File open: 'src/sunit/file/testfile.txt') reader contents.
 comp: ( { $i. $ . $l. $a. $'. $e. $ . $d. $i. $'. $u. $ . $n. $o. $'. $e. $ . $b. $a. $'. $e. $ . $m. $u. $t. $c. $e. $ . $l. $e. $ . $k. $a. $ . $c. $i. $z. $r. $a. $ . $i. $j. $e. $n. $a. $i. $j. $i. $'. $a. $ . $l. $a. $ . $a. $l. $i. $s. } as: String ).
 t assert:  (comp = contents) .
].

t@(Tests File traits) testRead
[ | reader |
 reader: (File open: 'src/sunit/file/testfile.txt') reader.
 t assert:  (reader next == $i) .
 t assert:  (reader next == $ ) .
 t assert:  (reader next == $l) .
].

t@(Tests File traits) testPeek
[ | reader |
 reader: (File open: 'src/sunit/file/testfile.txt') reader.
 t assert:  (reader next == $i) .
 t assert:  (reader next == $ ) .
 t assert:  ((reader peekForwardBy: 1) == $l) .
 t assert:  (reader next == $l) .
 t assert:  ((reader peekForwardBy: 3) == $e) .
 reader next.
 reader next.
 t assert:  (reader next == $e) .
].

t@(Tests File traits) testWrite
[ | reader writer |
 writer: (File openNew: 'src/sunit/file/outputfile.txt') writer.
 writer ; 'some text\na text\nmore text'.
 writer close .
 reader: (File openNew: 'src/sunit/file/outputfile.txt') reader.
 t assert: ((reader contents) = 'some text\na text\nmore text').
 reader close.
].


t@(Tests File traits) testSuite
[| suite result |
  suite: TestSuite newEmpty.
  suite tests
    addAll: {t newForSelector: #testOpen.
	     t newForSelector: #testContents.
	     t newForSelector: #testRead.	
	     t newForSelector: #testPeek.
	     t newForSelector: #testWrite.	
	    }.
  result: suite run
].



-------------- next part --------------
i la'e di'u no'e ba'e mutce le ka cizra ijenaiji'a la alis


More information about the Slate mailing list