File tree 13 files changed +33
-31
lines changed
13 files changed +33
-31
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,8 @@ fn main() {
62
62
let parser = Parser :: new (input );
63
63
let ast = parser . parse ();
64
64
65
- // ast.errors() returns an errors slice encountered during lexing and parsing
66
- assert! ( ast . errors (). is_empty ());
65
+ // ast.errors() returns an iterator with the errors encountered during lexing and parsing
66
+ assert_eq! ( 0 , ast . errors (). len ());
67
67
68
68
// ast.document() get the Document, or root node, of the tree that you can
69
69
// start iterating on.
@@ -97,7 +97,7 @@ fn main() {
97
97
" ;
98
98
let parser = Parser :: new (input );
99
99
let ast = parser . parse ();
100
- assert! ( ast . errors (). is_empty ());
100
+ assert_eq! ( 0 , ast . errors (). len ());
101
101
102
102
let doc = ast . document ();
103
103
@@ -130,7 +130,7 @@ fn main() {
130
130
131
131
let parser = Parser :: new (input );
132
132
let ast = parser . parse ();
133
- assert! ( & ast . errors (). is_empty ());
133
+ assert_eq! ( 0 , ast . errors (). len ());
134
134
135
135
let doc = ast . document ();
136
136
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ fn are_variables_unused() {
11
11
let parser = Parser :: new ( & src) ;
12
12
let ast = parser. parse ( ) ;
13
13
14
- assert ! ( & ast. errors( ) . is_empty ( ) ) ;
14
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
15
15
16
16
let doc = ast. document ( ) ;
17
17
Original file line number Diff line number Diff line change 42
42
//! let parser = Parser::new(schema);
43
43
//! let ast = parser.parse();
44
44
//!
45
- //! assert!( ast.errors().is_empty ());
45
+ //! assert_eq!(0, ast.errors().len ());
46
46
//! let document = ast.document();
47
47
//! for definition in document.definitions() {
48
48
//! match definition {
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ use std::fmt;
16
16
/// let parser = Parser::new(input);
17
17
/// let ast = parser.parse();
18
18
///
19
- /// assert!( ast.errors().is_empty ());
19
+ /// assert_eq!(0, ast.errors().len ());
20
20
///
21
21
/// let doc = ast.document();
22
22
/// ```
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ mod cursor;
2
2
mod token;
3
3
mod token_kind;
4
4
5
+ use std:: slice:: Iter ;
6
+
5
7
use crate :: { lexer:: cursor:: Cursor , Error } ;
6
8
7
9
pub use token:: Token ;
@@ -59,8 +61,8 @@ impl Lexer {
59
61
}
60
62
61
63
/// Get a reference to the lexer's tokens.
62
- pub ( crate ) fn errors ( & self ) -> & [ Error ] {
63
- self . errors . as_slice ( )
64
+ pub ( crate ) fn errors < ' e > ( & ' e self ) -> Iter < ' _ , Error > {
65
+ self . errors . iter ( )
64
66
}
65
67
}
66
68
Original file line number Diff line number Diff line change 62
62
//! let ast = parser.parse();
63
63
//!
64
64
//! // ast.errors() returns an errors slice encountered during lexing and parsing
65
- //! assert!( ast.errors().is_empty ());
65
+ //! assert_eq!(0, ast.errors().len ());
66
66
//!
67
67
//! // ast.document() get the Document, or root node, of the tree that you can
68
68
//! // start iterating on.
94
94
//! ";
95
95
//! let parser = Parser::new(input);
96
96
//! let ast = parser.parse();
97
- //! assert!( ast.errors().is_empty ());
97
+ //! assert_eq!(0, ast.errors().len ());
98
98
//!
99
99
//! let doc = ast.document();
100
100
//!
125
125
//!
126
126
//! let parser = Parser::new(input);
127
127
//! let ast = parser.parse();
128
- //! assert!(& ast.errors().is_empty ());
128
+ //! assert_eq!(0, ast.errors().len ());
129
129
//!
130
130
//! let doc = ast.document();
131
131
//!
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ type Business implements NamedEntity & ValuedEntity & CatEntity {
131
131
}" ;
132
132
let parser = Parser :: new ( input) ;
133
133
let ast = parser. parse ( ) ;
134
- assert ! ( ast. errors( ) . is_empty ( ) ) ;
134
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
135
135
136
136
let doc = ast. document ( ) ;
137
137
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ mod test {
68
68
" ;
69
69
let parser = Parser :: new ( input) ;
70
70
let ast = parser. parse ( ) ;
71
- assert ! ( & ast. errors( ) . is_empty ( ) ) ;
71
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
72
72
73
73
let doc = ast. document ( ) ;
74
74
@@ -129,7 +129,7 @@ query GraphQuery($graph_id: ID!, $variant: String) {
129
129
" ;
130
130
let parser = Parser :: new ( input) ;
131
131
let ast = parser. parse ( ) ;
132
- assert ! ( & ast. errors( ) . is_empty ( ) ) ;
132
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
133
133
134
134
let doc = ast. document ( ) ;
135
135
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ mod test {
112
112
let input = "union SearchResult = Photo | Person | Cat | Dog" ;
113
113
let parser = Parser :: new ( input) ;
114
114
let ast = parser. parse ( ) ;
115
- assert ! ( ast. errors( ) . is_empty ( ) ) ;
115
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
116
116
117
117
let doc = ast. document ( ) ;
118
118
Original file line number Diff line number Diff line change @@ -270,7 +270,7 @@ query GraphQuery($graph_id: ID!, $variant: String) {
270
270
" ;
271
271
let parser = Parser :: new ( input) ;
272
272
let ast = parser. parse ( ) ;
273
- assert ! ( & ast. errors( ) . is_empty ( ) ) ;
273
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
274
274
275
275
let doc = ast. document ( ) ;
276
276
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ pub(crate) use token_text::TokenText;
42
42
/// // Parse the query, and return a SyntaxTree.
43
43
/// let ast = parser.parse();
44
44
/// // Check that are no errors. These are not part of the AST.
45
- /// assert!(& ast.errors().is_empty ());
45
+ /// assert_eq!(0, ast.errors().len ());
46
46
///
47
47
/// // Get the document root node
48
48
/// let doc = ast.document();
@@ -65,7 +65,7 @@ pub(crate) use token_text::TokenText;
65
65
/// let parser = Parser::new(core_schema);
66
66
/// let ast = parser.parse();
67
67
///
68
- /// assert!( ast.errors().is_empty ());
68
+ /// assert_eq!(0, ast.errors().len ());
69
69
///
70
70
/// let document = ast.document();
71
71
/// ```
@@ -91,7 +91,7 @@ impl Parser {
91
91
tokens. push ( s) ;
92
92
}
93
93
94
- for e in lexer. errors ( ) . to_owned ( ) {
94
+ for e in lexer. errors ( ) . cloned ( ) {
95
95
errors. push ( e) ;
96
96
}
97
97
Original file line number Diff line number Diff line change 1
- use std:: fmt;
1
+ use std:: { fmt, slice :: Iter } ;
2
2
3
3
use rowan:: GreenNodeBuilder ;
4
4
@@ -44,8 +44,8 @@ pub struct SyntaxTree {
44
44
45
45
impl SyntaxTree {
46
46
/// Get a reference to the syntax tree's errors.
47
- pub fn errors ( & self ) -> & [ crate :: Error ] {
48
- self . errors . as_ref ( )
47
+ pub fn errors ( & self ) -> Iter < ' _ , crate :: Error > {
48
+ self . errors . iter ( )
49
49
}
50
50
51
51
/// Return the root typed `Document` node.
@@ -159,7 +159,7 @@ mod test {
159
159
" ;
160
160
let parser = Parser :: new ( input) ;
161
161
let ast = parser. parse ( ) ;
162
- assert ! ( ast. errors( ) . is_empty ( ) ) ;
162
+ assert_eq ! ( 0 , ast. errors( ) . len ( ) ) ;
163
163
164
164
let doc = ast. document ( ) ;
165
165
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use std::{
6
6
fmt:: Write ,
7
7
fs,
8
8
path:: { Path , PathBuf } ,
9
+ slice:: Iter ,
9
10
} ;
10
11
11
12
use expect_test:: expect_file;
@@ -52,25 +53,24 @@ fn parser_tests() {
52
53
} ) ;
53
54
}
54
55
55
- fn assert_errors_are_present ( errors : & [ Error ] , path : & Path ) {
56
+ fn assert_errors_are_present ( errors : Iter < ' _ , Error > , path : & Path ) {
56
57
assert ! (
57
- ! errors. is_empty ( ) ,
58
+ errors. len ( ) != 0 ,
58
59
"There should be errors in the file {:?}" ,
59
60
path. display( )
60
61
) ;
61
62
}
62
63
63
- fn assert_errors_are_absent ( errors : & [ Error ] , path : & Path ) {
64
- assert_eq ! (
65
- errors,
66
- & [ ] as & [ Error ] ,
64
+ fn assert_errors_are_absent < ' e > ( errors : Iter < ' _ , Error > , path : & Path ) {
65
+ assert ! (
66
+ errors. len( ) == 0 ,
67
67
"There should be no errors in the file {:?}" ,
68
68
path. display( ) ,
69
69
) ;
70
70
}
71
71
72
72
/// Concatenate tokens and erorrs.
73
- fn dump_tokens_and_errors ( tokens : & [ Token ] , errors : & [ Error ] ) -> String {
73
+ fn dump_tokens_and_errors < ' e > ( tokens : & [ Token ] , errors : impl Iterator < Item = & ' e Error > ) -> String {
74
74
let mut acc = String :: new ( ) ;
75
75
for token in tokens {
76
76
writeln ! ( acc, "{:?}" , token) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments