Skip to content

Commit

Permalink
refactor the tests (#22)
Browse files Browse the repository at this point in the history
* move the comment of the ignored tests to the *ignore* reason

* put "expected" after "actual" for consistency

* remove the whitespace from the `handle_escaped_strings` test

we already have the `ignore_whitespace_in_string` test for this.

* make the "expected" explicit in all tests
  • Loading branch information
amtoine committed Jun 9, 2023
1 parent 1b952cc commit b02b7e6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ mod test {

#[test]
fn array_of_object() {
let expected = String::from("[{\"a\":0},{},{\"a\":null}]\n");
let nu = String::from(
"[
{
Expand All @@ -61,27 +60,26 @@ mod test {
}
]",
);
let expected = String::from("[{\"a\":0},{},{\"a\":null}]\n");
assert_eq!(expected, format_string(&nu, &Config::default()));
}

#[test]
fn echoes_primitive() {
let nu = String::from("1.35\n");
assert_eq!(nu, format_string(&nu, &Config::default()));
let nu = String::from("1.35");
let expected = String::from("1.35\n");
assert_eq!(expected, format_string(&nu, &Config::default()));
}

#[test]
fn handle_escaped_strings() {
let nu = String::from(" \" hallo \\\" \" \n");
let expected = String::from("\" hallo \\\" \"\n");
let nu = String::from(" \"hallo\\\"\"");
let expected = String::from("\"hallo\\\"\"\n");
assert_eq!(expected, format_string(&nu, &Config::default()));
}

// comments aren't a part of Spans,
// we need another way of reading a skipping comments
// otherwise the nufmt directly remove them.
#[test]
#[ignore]
#[ignore = "comments aren't a part of Spans,"]
fn ignore_comments() {
let nu = String::from("# this is a comment");
let expected = String::from("# this is a comment");
Expand All @@ -90,8 +88,9 @@ mod test {

#[test]
fn ignore_whitespace_in_string() {
let nu = String::from("\" hallo \"\n");
assert_eq!(nu, format_string(&nu, &Config::default()));
let nu = String::from("\" hallo \"");
let expected = String::from("\" hallo \"\n");
assert_eq!(expected, format_string(&nu, &Config::default()));
}

#[test]
Expand Down

0 comments on commit b02b7e6

Please sign in to comment.