From 3e9e451099af984b02390c50417e34dcd2ac6ffa Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 20 May 2024 21:24:46 -0400 Subject: 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. --- Biz/Bild.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 = -- cgit v1.2.3