-
Notifications
You must be signed in to change notification settings - Fork 123
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
Testing for RON files #197
Conversation
tests/preserve_sequence.rs
Outdated
} | ||
|
||
fn read_original(file_name: &str) -> (String) { | ||
let input_path = format!("{}/tests/{}", env!("CARGO_MANIFEST_DIR"), file_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just include the original with include_str!
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know it exists. However, if I try, the compiler keeps complaining "error: argument must be a string literal", unless I copy the string into the function. But then the flexibility of calling various files is gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was thinking:
fn read_original(source: &str) -> String {...}
fn test_xxx() {
let file1 = include_str!("my_file1.ron");
assert_eq!(
read_original(file1),
make_roundtrip(file1),
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. Then the file is only read once, and processed twice. A much nicer way indeed. See 0fa9da3
tests/preserve_sequence.rs
Outdated
.expect("Something went wrong reading the file") | ||
} | ||
|
||
fn test_sequence(file_name: &str) -> (String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this should be called test_roundtrip
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. I though about several names (reciprocal, symmetric etc) but couldn't find a brief and correct description. See 1272b61
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to update calling functions, see update in e3ada7f Now the first example fails as the mapping order is modified, while the second example proofs the test is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind squashing the commits a bit?
…ip of decoding and encoding to RON code is made.
Like this ? c0d52d2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
197: Testing for RON files r=kvark a=peter-scholtens As a solution to the proposed test as mentioned in #192 I created a two functions: read_original() and test_sequence(). Using an assert equal macro various files can be tested. Two examples are given: the first one fails as the mapping sequence changes, the secvond one is correct, as the map only contains one item. Co-authored-by: Peter C. S. Scholtens <[email protected]>
Build failed |
It should fail testing on the first example1 as the sequence is not preserved. Or should this be listed as a separate bug? The second test should pass succesfully. |
…d unused use-statements.
thank you! |
197: Testing for RON files r=kvark a=peter-scholtens As a solution to the proposed test as mentioned in #192 I created a two functions: read_original() and test_sequence(). Using an assert equal macro various files can be tested. Two examples are given: the first one fails as the mapping sequence changes, the secvond one is correct, as the map only contains one item. Co-authored-by: Peter C. S. Scholtens <[email protected]>
Build succeeded |
As a solution to the proposed test as mentioned in #192 I created a two functions: read_original() and test_sequence(). Using an assert equal macro various files can be tested. Two examples are given: the first one fails as the mapping sequence changes, the secvond one is correct, as the map only contains one item.