Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: check all import styles #634

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ethers-solc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use walkdir::WalkDir;
/// statement with the named groups "path", "id".
pub static RE_SOL_IMPORT: Lazy<Regex> = Lazy::new(|| {
// Adapted from https://github.com/nomiclabs/hardhat/blob/cced766c65b25d3d0beb39ef847246ac9618bdd9/packages/hardhat-core/src/internal/solidity/parse.ts#L100
Regex::new(r#"import\s+(?:(?:"(?P<path>[^;]*)"|'([^;]*)')(?:;|\s+as\s+(?P<id>[^;]*);)|.+from\s+(?:"(.*)"|'(.*)');)"#).unwrap()
Regex::new(r#"import\s+(?:(?:"(?P<p1>[^;]*)"|'([^;]*)')(?:;|\s+as\s+(?P<id>[^;]*);)|.+from\s+(?:"(?P<p2>.*)"|'(?P<p3>.*)');)"#).unwrap()
});

/// A regex that matches the version part of a solidity pragma
Expand All @@ -27,7 +27,7 @@ pub static RE_SOL_PRAGMA_VERSION: Lazy<Regex> =
pub fn find_import_paths(contract: &str) -> Vec<&str> {
RE_SOL_IMPORT
.captures_iter(contract)
.filter_map(|cap| cap.name("path"))
.filter_map(|cap| cap.name("p1").or_else(|| cap.name("p2")).or_else(|| cap.name("p3")))
.map(|m| m.as_str())
.collect()
}
Expand Down Expand Up @@ -153,8 +153,13 @@ mod tests {
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "../contract/Contract.sol";
import { T } from "../Test.sol";
import { T } from '../Test2.sol';
"##;
assert_eq!(vec!["hardhat/console.sol", "../contract/Contract.sol"], find_import_paths(s));
assert_eq!(
vec!["hardhat/console.sol", "../contract/Contract.sol", "../Test.sol", "../Test2.sol"],
find_import_paths(s)
);
}
#[test]
fn can_find_version() {
Expand Down