solc: adjust flatten format (#1172)

This commit is contained in:
YYY 2022-04-23 16:40:34 +08:00 committed by GitHub
parent 8444b8ebbe
commit 1cba287193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -250,7 +250,9 @@ impl ProjectPathsConfig {
pub fn flatten(&self, target: &Path) -> Result<String> {
tracing::trace!("flattening file");
let graph = Graph::resolve(self)?;
self.flatten_node(target, &graph, &mut Default::default(), false, false, false)
self.flatten_node(target, &graph, &mut Default::default(), false, false, false).map(|x| {
format!("{}\n", utils::RE_THREE_OR_MORE_NEWLINES.replace_all(&x, "\n\n").trim())
})
}
/// Flattens a single node from the dependency graph
@ -321,7 +323,6 @@ impl ProjectPathsConfig {
let result = String::from_utf8(content).map_err(|err| {
SolcError::msg(format!("failed to convert extended bytes to string: {}", err))
})?;
let result = utils::RE_THREE_OR_MORE_NEWLINES.replace_all(&result, "\n\n").into_owned();
Ok(result)
}

View File

@ -490,8 +490,7 @@ contract C { }
assert_eq!(
result,
r#"
pragma solidity ^0.8.10;
r#"pragma solidity ^0.8.10;
contract C { }
@ -547,8 +546,7 @@ contract C { }
assert_eq!(
result,
r#"
pragma solidity ^0.8.10;
r#"pragma solidity ^0.8.10;
pragma experimental ABIEncoderV2;
contract C { }
@ -656,7 +654,7 @@ contract C { }
let result = project.flatten(&f).unwrap();
assert_eq!(
result.trim(),
result,
r#"pragma solidity ^0.8.10;
contract C { }
@ -664,7 +662,8 @@ contract C { }
error IllegalArgument();
error IllegalState();
contract A { }"#
contract A { }
"#
);
}
@ -707,7 +706,7 @@ contract C { }
let result = project.flatten(&f).unwrap();
assert_eq!(
result.trim(),
result,
r#"pragma solidity ^0.8.10;
contract C { }
@ -716,7 +715,8 @@ contract C { }
contract B { }
contract A { }"#
contract A { }
"#
);
}