11use super :: * ;
22use std:: path:: Path ;
33
4- /// Helper function to check if parsing produces the expected error type
4+ /// Helper function to check if parsing produces the expected error
55fn expect_error ( content : & str , expected : ParsingError ) {
66 let result = parse_with_recovery ( Path :: new ( "test.tq" ) , content) ;
77 match result {
@@ -10,14 +10,12 @@ fn expect_error(content: &str, expected: ParsingError) {
1010 content
1111 ) ,
1212 Err ( errors) => {
13- // Check if any error matches the expected type
14- let found_expected = errors
15- . iter ( )
16- . any ( |error| std:: mem:: discriminant ( error) == std:: mem:: discriminant ( & expected) ) ;
13+ // Check if any error exactly matches the expected error
14+ let found_expected = errors. contains ( & expected) ;
1715
1816 if !found_expected {
1917 panic ! (
20- "Expected error type like {:?} but got: {:?} for input '{}'" ,
18+ "Expected error {:?} but got: {:?} for input '{}'" ,
2119 expected, errors, content
2220 ) ;
2321 }
@@ -32,7 +30,7 @@ fn invalid_identifier_uppercase_start() {
3230Making_Coffee : Ingredients -> Coffee
3331 "#
3432 . trim_ascii ( ) ,
35- ParsingError :: InvalidIdentifier ( 0 , 0 , "" . to_string ( ) ) ,
33+ ParsingError :: InvalidIdentifier ( 0 , 13 , "Making_Coffee " . to_string ( ) ) ,
3634 ) ;
3735}
3836
@@ -43,7 +41,7 @@ fn invalid_identifier_mixed_case() {
4341makeCoffee : Ingredients -> Coffee
4442 "#
4543 . trim_ascii ( ) ,
46- ParsingError :: InvalidIdentifier ( 0 , 0 , "" . to_string ( ) ) ,
44+ ParsingError :: InvalidIdentifier ( 0 , 10 , "makeCoffee " . to_string ( ) ) ,
4745 ) ;
4846}
4947
@@ -54,7 +52,7 @@ fn invalid_identifier_with_dashes() {
5452make-coffee : Ingredients -> Coffee
5553 "#
5654 . trim_ascii ( ) ,
57- ParsingError :: InvalidIdentifier ( 0 , 0 , "" . to_string ( ) ) ,
55+ ParsingError :: InvalidIdentifier ( 0 , 11 , "make-coffee " . to_string ( ) ) ,
5856 ) ;
5957}
6058
@@ -65,7 +63,7 @@ fn invalid_identifier_with_spaces() {
6563make coffee : Ingredients -> Coffee
6664 "#
6765 . trim_ascii ( ) ,
68- ParsingError :: InvalidParameters ( 0 , 0 ) ,
66+ ParsingError :: InvalidParameters ( 5 , 6 ) ,
6967 ) ;
7068}
7169
@@ -76,7 +74,7 @@ fn invalid_signature_wrong_arrow() {
7674making_coffee : Ingredients => Coffee
7775 "#
7876 . trim_ascii ( ) ,
79- ParsingError :: InvalidSignature ( 0 , 0 ) ,
77+ ParsingError :: InvalidSignature ( 28 , 0 ) ,
8078 ) ;
8179}
8280
@@ -87,7 +85,7 @@ fn invalid_genus_lowercase_forma() {
8785making_coffee : ingredients -> Coffee
8886 "#
8987 . trim_ascii ( ) ,
90- ParsingError :: InvalidGenus ( 16 , 0 ) ,
88+ ParsingError :: InvalidGenus ( 16 , 11 ) ,
9189 ) ;
9290}
9391
@@ -98,7 +96,7 @@ fn invalid_genus_both_lowercase() {
9896making_coffee : ingredients -> coffee
9997 "#
10098 . trim_ascii ( ) ,
101- ParsingError :: InvalidGenus ( 16 , 0 ) ,
99+ ParsingError :: InvalidGenus ( 16 , 11 ) ,
102100 ) ;
103101}
104102
@@ -109,7 +107,7 @@ fn invalid_signature_missing_arrow() {
109107making_coffee : Ingredients Coffee
110108 "#
111109 . trim_ascii ( ) ,
112- ParsingError :: InvalidSignature ( 16 , 0 ) ,
110+ ParsingError :: InvalidSignature ( 28 , 0 ) ,
113111 ) ;
114112}
115113
@@ -131,7 +129,7 @@ fn invalid_identifier_in_parameters() {
131129making_coffee(BadParam) : Ingredients -> Coffee
132130 "#
133131 . trim_ascii ( ) ,
134- ParsingError :: InvalidIdentifier ( 14 , 0 , "" . to_string ( ) ) ,
132+ ParsingError :: InvalidIdentifier ( 0 , 8 , "BadParam " . to_string ( ) ) ,
135133 ) ;
136134}
137135
@@ -183,7 +181,7 @@ making_coffee :
183181 This is missing closing backticks
184182 "#
185183 . trim_ascii ( ) ,
186- ParsingError :: InvalidMultiline ( 41 , 0 ) ,
184+ ParsingError :: InvalidMultiline ( 24 , 0 ) ,
187185 ) ;
188186}
189187
@@ -196,7 +194,7 @@ making_coffee :
196194 1. Do something { exec("command"
197195 "#
198196 . trim_ascii ( ) ,
199- ParsingError :: ExpectedMatchingChar ( 38 , 0 , "a code block" , '{' , '}' ) ,
197+ ParsingError :: ExpectedMatchingChar ( 37 , 0 , "a code block" , '{' , '}' ) ,
200198 ) ;
201199}
202200
@@ -235,7 +233,7 @@ making_coffee :
235233 1. Do something { exec("command" }
236234 "#
237235 . trim_ascii ( ) ,
238- ParsingError :: ExpectedMatchingChar ( 43 , 0 , "a function call " , '(' , ')' ) ,
236+ ParsingError :: ExpectedMatchingChar ( 43 , 0 , "parameters for a function" , '(' , ')' ) ,
239237 ) ;
240238}
241239
@@ -248,7 +246,7 @@ making_coffee :
248246 1. Do something { re peat() }
249247 "#
250248 . trim_ascii ( ) ,
251- ParsingError :: InvalidFunction ( 38 , 0 ) ,
249+ ParsingError :: InvalidFunction ( 39 , 7 ) ,
252250 ) ;
253251}
254252
@@ -261,7 +259,7 @@ making_coffee :
261259 1. Do something { re peat <thing>() }
262260 "#
263261 . trim_ascii ( ) ,
264- ParsingError :: InvalidFunction ( 38 , 0 ) ,
262+ ParsingError :: InvalidFunction ( 39 , 15 ) ,
265263 ) ;
266264}
267265
@@ -274,7 +272,7 @@ making_coffee :
274272 1. { repeat <making_coffee }
275273 "#
276274 . trim_ascii ( ) ,
277- ParsingError :: ExpectedMatchingChar ( 29 , 0 , "an invocation" , '<' , '>' ) ,
275+ ParsingError :: ExpectedMatchingChar ( 33 , 0 , "an invocation" , '<' , '>' ) ,
278276 ) ;
279277}
280278
@@ -288,7 +286,7 @@ making_coffee :
288286 A. This should be lowercase
289287 "#
290288 . trim_ascii ( ) ,
291- ParsingError :: InvalidSubstep ( 37 , 0 ) ,
289+ ParsingError :: InvalidSubstep ( 43 , 0 ) ,
292290 ) ;
293291}
294292
@@ -301,6 +299,6 @@ robot :
301299Your plastic pal who's fun to be with! { re peat <jingle> }
302300 "#
303301 . trim_ascii ( ) ,
304- ParsingError :: InvalidCodeBlock ( 43 , 7 ) ,
302+ ParsingError :: InvalidCodeBlock ( 50 , 7 ) ,
305303 ) ;
306304}
0 commit comments