File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ impl Repl {
29
29
pub fn read < R : BufRead > ( reader : & mut R ) -> Value {
30
30
reader:: read ( reader)
31
31
}
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
+ }
32
36
pub fn run ( & self ) {
33
37
let stdin = io:: stdin ( ) ;
34
38
@@ -89,3 +93,35 @@ impl Default for Repl {
89
93
}
90
94
}
91
95
}
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