Skip to content

Commit

Permalink
Improve readability of assert_str
Browse files Browse the repository at this point in the history
 - function renamed.
 - `input` renamed to `actual` which gives clearer IDE hints.
  • Loading branch information
allan2 committed Oct 5, 2024
1 parent 85e13d1 commit db89b9d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions dotenvy/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ mod substitution_tests {
use crate::iter::{Iter, ParseBufError};

/// Asserts the parsed string is equal to the expected string.
fn assert_string(input: &str, expected: Vec<(&str, &str)>) -> Result<(), ParseBufError> {
let actual_iter = Iter::new(input.as_bytes());
fn assert_str(actual: &str, expected: Vec<(&str, &str)>) -> Result<(), ParseBufError> {
let actual_iter = Iter::new(actual.as_bytes());
let expected_count = expected.len();

let expected_iter = expected
Expand All @@ -415,7 +415,7 @@ mod substitution_tests {

let mut count = 0;
for (expected, actual) in expected_iter.zip(actual_iter) {
assert_eq!(expected, actual?);
assert_eq!(actual?, expected);
count += 1;
}
assert_eq!(count, expected_count);
Expand All @@ -424,7 +424,7 @@ mod substitution_tests {

#[test]
fn variable_in_parenthesis_surrounded_by_quotes() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r#"
KEY=test
KEY1="${KEY}"
Expand All @@ -435,33 +435,33 @@ mod substitution_tests {

#[test]
fn sub_undefined_variables_to_empty_string() -> Result<(), ParseBufError> {
assert_string(r#"KEY=">$KEY1<>${KEY2}<""#, vec![("KEY", "><><")])
assert_str(r#"KEY=">$KEY1<>${KEY2}<""#, vec![("KEY", "><><")])
}

#[test]
fn do_not_sub_with_dollar_escaped() -> Result<(), ParseBufError> {
assert_string(
assert_str(
"KEY=>\\$KEY1<>\\${KEY2}<",
vec![("KEY", ">$KEY1<>${KEY2}<")],
)
}

#[test]
fn do_not_sub_in_weak_quotes_with_dollar_escaped() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r#"KEY=">\$KEY1<>\${KEY2}<""#,
vec![("KEY", ">$KEY1<>${KEY2}<")],
)
}

#[test]
fn do_not_sub_in_strong_quotes() -> Result<(), ParseBufError> {
assert_string("KEY='>${KEY1}<>$KEY2<'", vec![("KEY", ">${KEY1}<>$KEY2<")])
assert_str("KEY='>${KEY1}<>$KEY2<'", vec![("KEY", ">${KEY1}<>$KEY2<")])
}

#[test]
fn same_variable_reused() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r"
KEY=VALUE
KEY1=$KEY$KEY
Expand All @@ -472,7 +472,7 @@ mod substitution_tests {

#[test]
fn with_dot() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r"
KEY.Value=VALUE
",
Expand All @@ -482,7 +482,7 @@ mod substitution_tests {

#[test]
fn recursive_substitution() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r"
KEY=${KEY1}+KEY_VALUE
KEY1=${KEY}+KEY1_VALUE
Expand All @@ -493,7 +493,7 @@ mod substitution_tests {

#[test]
fn var_without_paranthesis_subbed_before_separators() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r#"
KEY1=test_user
KEY1_1=test_user_with_separator
Expand All @@ -510,15 +510,15 @@ mod substitution_tests {
#[test]
fn sub_var_from_env_var() -> Result<(), ParseBufError> {
temp_env::with_var("KEY11", Some("test_user_env"), || {
assert_string(r#"KEY=">${KEY11}<""#, vec![("KEY", ">test_user_env<")])
assert_str(r#"KEY=">${KEY11}<""#, vec![("KEY", ">test_user_env<")])
})
}

#[test]
fn substitute_variable_env_variable_overrides_dotenv_in_substitution(
) -> Result<(), ParseBufError> {
temp_env::with_var("KEY11", Some("test_user_env"), || {
assert_string(
assert_str(
r#"
KEY11=test_user
KEY=">${KEY11}<"
Expand All @@ -530,7 +530,7 @@ mod substitution_tests {

#[test]
fn consequent_substitutions() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r"
KEY1=test_user
KEY2=$KEY1_2
Expand All @@ -546,7 +546,7 @@ mod substitution_tests {

#[test]
fn consequent_substitutions_with_one_missing() -> Result<(), ParseBufError> {
assert_string(
assert_str(
r"
KEY2=$KEY1_2
KEY=>${KEY1}<>${KEY2}<
Expand Down

0 comments on commit db89b9d

Please sign in to comment.