-
Notifications
You must be signed in to change notification settings - Fork 1
Test refactoring #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wadealexc
wants to merge
10
commits into
master
Choose a base branch
from
test-utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test refactoring #23
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cd2bce7
Merge pull request #15 from jalextowle/lexer-refactor
ad38ba0
Added utils module to package. Implemented a few simple test utils an…
b245a97
Further refactoring in parse_tests.rs to reduce line width and code size
7d2497d
Refactored parse_types_tests to use util library
4cc496c
Refactored expression tests to use utils
6ddb6be
Refactored integration tests to use utils, and updated parse_tests wi…
64521f3
Path shortening on lex_tests
175b544
Added comments to util functions and renamed parser::expect_eq to par…
6e6fb65
fail_test now properly panics - oops
7b42708
Addressed requested changes. Made fail_test generic and removed 1-let…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub mod lex_4_25; | ||
| pub mod parse_4_25; | ||
| pub mod utils; |
This file contains hidden or 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,102 @@ | ||
| use std::fmt::Debug; | ||
| use super::lex_4_25; | ||
| use super::parse_4_25; | ||
|
|
||
| pub mod test_utils { | ||
wadealexc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use super::*; | ||
|
|
||
| /** | ||
| * Fail a test, panicing and printing expected and actual values | ||
| */ | ||
| pub fn fail_test<T: Debug + PartialEq>(expect: T, actual: T) { | ||
| panic!("\nExpected: {:#?} \nActual: {:#?}\n", expect, actual) | ||
| } | ||
|
|
||
| pub mod lexer { | ||
| use super::lex_4_25; | ||
|
|
||
| /** | ||
| * Advance cur in string using next_token, and check that the return matches | ||
| * the expected Token. If not, the test fails. | ||
| */ | ||
| pub fn expect_next_token(string: &Vec<char>, cur: &mut usize, token: lex_4_25::Token) { | ||
| match lex_4_25::next_token(&string, cur) { | ||
| ref next if *next == token => (), | ||
| actual => super::fail_test(token, actual) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| pub mod parser { | ||
| use super::lex_4_25; | ||
| use super::parse_4_25; | ||
|
|
||
| /** | ||
| * Returns a Token as a ParseNode with no children | ||
| */ | ||
| pub fn as_leaf(token: lex_4_25::Token) -> Box<parse_4_25::ParseNode> { | ||
| Box::new(token.to_leaf()) | ||
| } | ||
|
|
||
| /** | ||
| * Returns a ParseNode with the given Token serving as the node, and | ||
| * a passed-in array of children as the node's children. | ||
| */ | ||
| pub fn as_node(node: lex_4_25::Token, children: Vec<Box<parse_4_25::ParseNode>>) -> Box<parse_4_25::ParseNode> { | ||
wadealexc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Box::new(parse_4_25::ParseNode { | ||
| node, | ||
| children | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Returns a ParseNode with the given Token and children, but does | ||
| * not wrap the ParseNode in a Box | ||
| */ | ||
| pub fn as_node_raw(node: lex_4_25::Token, children: Vec<Box<parse_4_25::ParseNode>>) -> parse_4_25::ParseNode { | ||
| parse_4_25::ParseNode { | ||
| node, | ||
| children | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Given an array of children, returns their ParseTree | ||
| */ | ||
| pub fn as_tree(children: Vec<parse_4_25::ParseNode>) -> parse_4_25::ParseTree { | ||
| parse_4_25::ParseTree { | ||
| children | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Shorthand for parse(String::from("str-input")). Calls | ||
| * parse_4_25::parse and returns the resulting ParseTree | ||
| */ | ||
| pub fn parse_str(string: &str) -> parse_4_25::ParseTree { | ||
| parse_4_25::parse(String::from(string)) | ||
| } | ||
|
|
||
| /** | ||
| * Given two ParseTrees, checks for equality. If unequal, | ||
| * panics and prints the prettified trees. | ||
| */ | ||
| pub fn expect_tree_eq(expect: parse_4_25::ParseTree, actual: parse_4_25::ParseTree) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the formatting here. I'd say that we should adopt it in the |
||
| match expect == actual { | ||
| true => (), | ||
| false => super::fail_test(expect, actual) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Given two ParseNodes, checks for equality. If unequal, | ||
| * panics and prints the prettified nodes. | ||
| */ | ||
| pub fn expect_node_eq(expect: parse_4_25::ParseNode, actual: parse_4_25::ParseNode) { | ||
| match expect == actual { | ||
| true => (), | ||
| false => super::fail_test(expect, actual) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.