File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ impl Repl {
2929 pub fn read < R : BufRead > ( reader : & mut R ) -> Value {
3030 reader:: read ( reader)
3131 }
32+ // @TODO add to reader.rs and wrap here
33+ pub fn read_string ( string : & str ) -> Value {
34+ Repl :: read ( & mut string. as_bytes ( ) )
35+ }
3236 pub fn run ( & self ) {
3337 let stdin = io:: stdin ( ) ;
3438
@@ -89,3 +93,35 @@ impl Default for Repl {
8993 }
9094 }
9195}
96+
97+ #[ cfg( test) ]
98+ mod tests {
99+ use crate :: repl:: Repl ;
100+ use crate :: value:: Value ;
101+ //@TODO separate into individual tests
102+ #[ test]
103+ fn read_string ( ) {
104+ let num = Repl :: read_string ( "1" ) ;
105+ match num {
106+ Value :: I32 ( _) => { } ,
107+ _ => panic ! ( "Reading of integer should have returned Value::I32" )
108+ }
109+ let list = Repl :: read_string ( "(+ 1 2)" ) ;
110+ match list {
111+ Value :: PersistentList ( _) => { } ,
112+ _ => panic ! ( "Reading of integer should have returned Value::PersistentList" )
113+ }
114+
115+ let vector = Repl :: read_string ( "[1 2 a]" ) ;
116+ match vector {
117+ Value :: PersistentVector ( _) => { } ,
118+ _ => panic ! ( "Reading of integer should have returned Value::PersistentVector" )
119+ }
120+
121+ let symbol = Repl :: read_string ( "abc" ) ;
122+ match symbol {
123+ Value :: Symbol ( _) => { } ,
124+ _ => panic ! ( "Reading of integer should have returned Value::Symbol" )
125+ }
126+ }
127+ }
You can’t perform that action at this time.
0 commit comments