diff options
author | Ben Sima <ben@bsima.me> | 2024-05-20 21:24:46 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2024-05-20 23:15:31 -0400 |
commit | 3e9e451099af984b02390c50417e34dcd2ac6ffa (patch) | |
tree | f543275c3406d23453bd1bb757c122160f8dbad0 | |
parent | 027dcce5d199d914c9c560f354fba71ef4974a00 (diff) |
Detect Python `import as` statements
The regex would fail if there was text after the `import X`, so `import X as Y`
would fail, and bild wouldn't detect the local import. This adds a simple test
that guards against this regex failure.
-rw-r--r-- | Biz/Bild.hs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 5c8e287..a67c1c2 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -161,7 +161,8 @@ main = Cli.Plan help move test_ pure |> Cli.main [ test_bildBild, test_bildExamples, test_isGitIgnored, - test_isGitHook + test_isGitHook, + test_detectPythonImports ] test_bildBild :: Test.Tree @@ -847,6 +848,19 @@ detectPythonImports contentLines = Regex.string "import" *> Regex.some (Regex.psym Char.isSpace) *> Regex.many (Regex.psym isModuleChar) + <* Regex.many Regex.anySym + +test_detectPythonImports :: Test.Tree +test_detectPythonImports = + Test.group + "detectPythonImports" + [ Test.unit "matches import statements" <| do + set <- detectPythonImports ["import Biz.Log"] + Set.fromList ["Biz/Log.py"] @=? set, + Test.unit "matches import as statements" <| do + set <- detectPythonImports ["import Biz.Log as Log"] + Set.fromList ["Biz/Log.py"] @=? set + ] ghcPkgFindModule :: Set String -> String -> IO (Set String) ghcPkgFindModule acc m = |