@@ -25,7 +25,10 @@ impl Display for FileParseError {
25
25
26
26
impl Error for FileParseError { }
27
27
28
- pub async fn parse_file < O : Clone + Debug , E : Debug > (
28
+ pub async fn parse_file <
29
+ O : Clone + Debug ,
30
+ E : Debug + Display + for < ' a > winnow:: error:: ParserError < & ' a str > ,
31
+ > (
29
32
// The for<'a> syntax is a higher-ranked trait bound which is
30
33
// necessary to specify that the lifetime of the string passed
31
34
// into the parser does not need to outlive this function call
@@ -42,7 +45,7 @@ pub async fn parse_file<O: Clone + Debug, E: Debug>(
42
45
// parser.parse_next(&mut contents.as_str().into()).unwrap()
43
46
// );
44
47
parser
45
- . parse_next ( & mut contents. as_str ( ) . into ( ) )
48
+ . parse ( contents. as_str ( ) . into ( ) )
46
49
. map_err ( |e| Box :: new ( FileParseError :: new ( e. to_string ( ) ) ) as Box < dyn Error > )
47
50
}
48
51
@@ -67,4 +70,86 @@ mod tests {
67
70
. await ;
68
71
assert_eq ! ( x_vals, vec![ Value :: Int ( 1 ) , Value :: Int ( 3 ) ] ) ;
69
72
}
73
+
74
+ #[ tokio:: test]
75
+ async fn test_parse_boolean_file ( ) {
76
+ let parser = crate :: parser:: lola_input_file;
77
+ let file = "examples/maple_sequence_true.input" ;
78
+ let mut data = parse_file ( parser, file) . await . unwrap ( ) ;
79
+ let m_vals = data
80
+ . input_stream ( & VarName ( "m" . into ( ) ) )
81
+ . unwrap ( )
82
+ . collect :: < Vec < _ > > ( )
83
+ . await ;
84
+ assert_eq ! (
85
+ m_vals,
86
+ vec![
87
+ Value :: Bool ( true ) ,
88
+ Value :: Bool ( false ) ,
89
+ Value :: Bool ( false ) ,
90
+ Value :: Bool ( false ) ,
91
+ Value :: Bool ( false )
92
+ ] ,
93
+ ) ;
94
+ let a_vals = data
95
+ . input_stream ( & VarName ( "a" . into ( ) ) )
96
+ . unwrap ( )
97
+ . collect :: < Vec < _ > > ( )
98
+ . await ;
99
+ assert_eq ! (
100
+ a_vals,
101
+ vec![
102
+ Value :: Bool ( false ) ,
103
+ Value :: Bool ( true ) ,
104
+ Value :: Bool ( false ) ,
105
+ Value :: Bool ( false ) ,
106
+ Value :: Bool ( false )
107
+ ] ,
108
+ ) ;
109
+ let p_vals = data
110
+ . input_stream ( & VarName ( "p" . into ( ) ) )
111
+ . unwrap ( )
112
+ . collect :: < Vec < _ > > ( )
113
+ . await ;
114
+ assert_eq ! (
115
+ p_vals,
116
+ vec![
117
+ Value :: Bool ( false ) ,
118
+ Value :: Bool ( false ) ,
119
+ Value :: Bool ( true ) ,
120
+ Value :: Bool ( false ) ,
121
+ Value :: Bool ( false )
122
+ ] ,
123
+ ) ;
124
+ let l_vals = data
125
+ . input_stream ( & VarName ( "l" . into ( ) ) )
126
+ . unwrap ( )
127
+ . collect :: < Vec < _ > > ( )
128
+ . await ;
129
+ assert_eq ! (
130
+ l_vals,
131
+ vec![
132
+ Value :: Bool ( false ) ,
133
+ Value :: Bool ( false ) ,
134
+ Value :: Bool ( false ) ,
135
+ Value :: Bool ( true ) ,
136
+ Value :: Bool ( false )
137
+ ] ,
138
+ ) ;
139
+ let e_vals = data
140
+ . input_stream ( & VarName ( "e" . into ( ) ) )
141
+ . unwrap ( )
142
+ . collect :: < Vec < _ > > ( )
143
+ . await ;
144
+ assert_eq ! (
145
+ e_vals,
146
+ vec![
147
+ Value :: Bool ( false ) ,
148
+ Value :: Bool ( false ) ,
149
+ Value :: Bool ( false ) ,
150
+ Value :: Bool ( false ) ,
151
+ Value :: Bool ( true )
152
+ ] ,
153
+ ) ;
154
+ }
70
155
}
0 commit comments