test: add curly bracket import test (#929)

This commit is contained in:
Matthias Seitz 2022-02-18 18:24:41 +01:00 committed by GitHub
parent 28df48b530
commit f2796cc001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -341,6 +341,7 @@ pub fn create_parent_dir_all(file: impl AsRef<Path>) -> Result<(), SolcError> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use solang_parser::pt::SourceUnitPart;
use std::{ use std::{
collections::HashSet, collections::HashSet,
fs::{create_dir_all, File}, fs::{create_dir_all, File},
@ -383,6 +384,22 @@ mod tests {
assert_eq!(files, expected); 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] #[test]
fn can_find_single_quote_imports() { fn can_find_single_quote_imports() {
let content = r#" let content = r#"