use super::imports_package;
fn imports(text: &str) -> bool {
return imports_package(text, "@scope/b");
}
#[test]
fn detects_the_incumbent_forms() {
for text in [
"import { a } from '@scope/b';",
"import type { A } from \"@scope/b/ts\";",
"import '@scope/b';",
"export * from '@scope/b';",
"const m = await import('@scope/b');",
"const m = await import ( `@scope/b/sub` );",
"const m = require('@scope/b');",
"import { a }\nfrom\n'@scope/b';",
] {
assert!(imports(text), "{text}");
}
}
#[test]
fn ignores_the_incumbent_non_specifiers() {
for text in [
"import { a } from '@scope/bc';",
"const name = '@scope/b';",
"reimport '@scope/b';",
"myrequire('@scope/b');",
"import { a } from 'x@scope/b';",
"@scope/b",
"",
] {
assert!(!imports(text), "{text}");
}
}
#[test]
fn finds_a_later_specifier_after_an_earlier_mention() {
assert!(imports(
"const note = '@scope/b';\nimport { a } from '@scope/b';"
));
}
#[test]
fn requires_a_whole_keyword() {
for prefix in ["a", "Z", "7", "_", "$"] {
assert!(!imports(&format!("{prefix}from '@scope/b'")), "{prefix}");
assert!(
!imports(&format!("{prefix}require('@scope/b')")),
"{prefix}"
);
}
assert!(imports("-from '@scope/b'"));
assert!(imports("from'@scope/b'"));
assert!(imports("x=require\t(\r'@scope/b')"));
}
#[test]
fn requires_a_closing_quote_or_a_subpath() {
assert!(!imports("import '@scope/b\";"));
assert!(!imports("import '@scope/b"));
assert!(imports("import \"@scope/b\""));
assert!(imports("import `@scope/b/x`"));
assert!(!imports("import (@scope/b)"));
}
#[test]
fn requires_specifier_position() {
assert!(!imports("'@scope/b'"));
assert!(!imports("('@scope/b')"));
assert!(!imports("x('@scope/b')"));
assert!(!imports("from('@scope/b')"));
assert!(imports("import('@scope/b')"));
assert!(!imports("requirex '@scope/b'"));
assert!(!imports("importx '@scope/b'"));
}
#[test]
fn applies_the_rule_to_an_empty_name() {
assert!(imports_package("import ''", ""));
assert!(imports_package("require('/x')", ""));
assert!(!imports_package("const a = ''", ""));
}