forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share utils between sway-parse unit tests (FuelLabs#4265)
This PR adds `mod sway_parse::test_utils` containing two utils, `fn parse<T>` and `fn parse_to_end<T>`, to replace non-generic utils like `fn parse_item` or `fn parse_path_expr`.
- Loading branch information
Showing
6 changed files
with
49 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{priv_prelude::ParseToEnd, Parse, Parser}; | ||
use std::sync::Arc; | ||
|
||
pub fn parse<T>(input: &str) -> T | ||
where | ||
T: Parse, | ||
{ | ||
let handler = <_>::default(); | ||
let ts = crate::token::lex(&handler, &Arc::from(input), 0, input.len(), None).unwrap(); | ||
Parser::new(&handler, &ts) | ||
.parse() | ||
.unwrap_or_else(|_| panic!("Parse error: {:?}", handler.consume().0)) | ||
} | ||
|
||
pub fn parse_to_end<T>(input: &str) -> T | ||
where | ||
T: ParseToEnd, | ||
{ | ||
let handler = <_>::default(); | ||
let ts = crate::token::lex(&handler, &Arc::from(input), 0, input.len(), None).unwrap(); | ||
Parser::new(&handler, &ts) | ||
.parse_to_end() | ||
.map(|(m, _)| m) | ||
.unwrap_or_else(|_| panic!("Parse error: {:?}", handler.consume().0)) | ||
} |