Skip to content
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

Merged
merged 2 commits into from Nov 21, 2019
Merged

Testing for RON files #197

merged 2 commits into from Nov 21, 2019

Conversation

peter-scholtens
Copy link
Contributor

@peter-scholtens peter-scholtens commented Nov 3, 2019

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.

}

fn read_original(file_name: &str) -> (String) {
let input_path = format!("{}/tests/{}", env!("CARGO_MANIFEST_DIR"), file_name);
Copy link
Collaborator

@kvark kvark Nov 4, 2019

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?

Copy link
Contributor Author

@peter-scholtens peter-scholtens Nov 4, 2019

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.

Copy link
Collaborator

@kvark kvark Nov 4, 2019

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),
  );  
}

Copy link
Contributor Author

@peter-scholtens peter-scholtens Nov 4, 2019

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

.expect("Something went wrong reading the file")
}

fn test_sequence(file_name: &str) -> (String) {
Copy link
Collaborator

@kvark kvark Nov 4, 2019

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?

Copy link
Contributor Author

@peter-scholtens peter-scholtens Nov 4, 2019

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

Copy link
Contributor Author

@peter-scholtens peter-scholtens Nov 4, 2019

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.

kvark
kvark approved these changes Nov 4, 2019
Copy link
Collaborator

@kvark kvark left a comment

Would you mind squashing the commits a bit?

…ip of decoding and encoding to RON code is made.
@peter-scholtens
Copy link
Contributor Author

peter-scholtens commented Nov 4, 2019

Like this ? c0d52d2

kvark
kvark approved these changes Nov 4, 2019
Copy link
Collaborator

@kvark kvark left a comment

bors r+

bors bot added a commit that referenced this pull request Nov 4, 2019
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 <peter.scholtens@xs4all.nl>
@bors
Copy link
Contributor

bors bot commented Nov 4, 2019

Build failed

@peter-scholtens
Copy link
Contributor Author

peter-scholtens commented Nov 4, 2019

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.

@kvark
Copy link
Collaborator

kvark commented Nov 21, 2019

thank you!
bors r+

bors bot added a commit that referenced this pull request Nov 21, 2019
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 <peter.scholtens@xs4all.nl>
@bors
Copy link
Contributor

bors bot commented Nov 21, 2019

Build succeeded

@bors bors bot merged commit eae46bb into ron-rs:master Nov 21, 2019
2 checks passed
@CAD97 CAD97 mentioned this pull request May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants