From f2796cc00198e72f2df382383e601b3822059430 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 18 Feb 2022 18:24:41 +0100 Subject: [PATCH] test: add curly bracket import test (#929) --- ethers-solc/src/utils.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ethers-solc/src/utils.rs b/ethers-solc/src/utils.rs index a5e5978c..c15a2697 100644 --- a/ethers-solc/src/utils.rs +++ b/ethers-solc/src/utils.rs @@ -341,6 +341,7 @@ pub fn create_parent_dir_all(file: impl AsRef) -> Result<(), SolcError> { #[cfg(test)] mod tests { use super::*; + use solang_parser::pt::SourceUnitPart; use std::{ collections::HashSet, fs::{create_dir_all, File}, @@ -383,6 +384,22 @@ mod tests { assert_eq!(files, expected); } + #[test] + fn can_parse_curly_bracket_imports() { + let s = + r#"import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";"#; + + let (unit, _) = solang_parser::parse(s, 0).unwrap(); + assert_eq!(unit.0.len(), 1); + match unit.0[0] { + SourceUnitPart::ImportDirective(_, _) => {} + _ => unreachable!("failed to parse import"), + } + let imports: Vec<_> = find_import_paths(s).map(|m| m.as_str()).collect(); + + assert_eq!(imports, vec!["@openzeppelin/contracts/utils/ReentrancyGuard.sol"]) + } + #[test] fn can_find_single_quote_imports() { let content = r#"