1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Test suites for module `push_back_reader`
12 module test_push_back_reader
is test_suite
15 import io
::push_back_reader
17 class TestPushBackDecorator
20 private fun sample
: PushBackDecorator do
21 return new PushBackDecorator(new StringReader("""
31 assert 'a' == subject
.read_char
.ascii
34 fun test_read_char_eof
do
35 var subject
= new PushBackDecorator(new StringReader(""))
37 assert -1 == subject
.read_char
40 fun test_unread_read_char
do
43 subject
.unread_char
('z')
44 assert 'z' == subject
.read_char
.ascii
45 assert 'a' == subject
.read_char
.ascii
48 fun test_read_partial
do
51 assert "abcd" == subject
.read
(4)
54 fun test_read_too_much
do
61 assert exp
== subject
.read
(100)
64 fun test_unread_read
do
68 assert "aab" == subject
.read
(3)
71 fun test_unread_read_mixed
do
75 assert "aab" == subject
.read
(3)
85 assert exp
== subject
.read_all
88 fun test_unread_read_all
do
96 assert exp
== subject
.read_all
102 assert "abcd" == subject
.read_line
103 assert "" == subject
.read_line
106 fun test_unread_read_line
do
109 subject
.unread
("a\nb")
110 assert "a" == subject
.read_line
111 assert "babcd" == subject
.read_line
117 assert not subject
.eof
122 fun test_eof_empty
do
123 var subject
= new PushBackDecorator(new StringReader(""))
135 fun test_unread_close
do
138 subject
.unread
("foo")
143 fun test_unread_char_order
do
146 subject
.unread_char
('z')
147 subject
.unread_char
('y')
148 assert "yzab" == subject
.read
(4)
151 fun test_unread_order
do
154 subject
.unread
("bar")
155 subject
.unread
("foo")
156 assert "foobarab" == subject
.read
(8)