]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Main.hs
Switch from test-framework to tasty.
[hath.git] / src / Main.hs
index 45705be673f087d76d8e64ea61f16c086ac98632..2bb586980f5a06bf2de39a54dfdab580c3cda21d 100644 (file)
@@ -7,6 +7,7 @@ import qualified Data.ByteString.Char8 as BS (intercalate, pack, unpack)
 import Data.List ((\\), intercalate)
 import Data.Maybe (catMaybes, isNothing)
 import Data.String.Utils (splitWs)
+import Network.DNS.Types ( DNSError (NameError) )
 import System.Exit (ExitCode(..), exitWith)
 import System.IO (stderr, hPutStrLn)
 import Text.Read (readMaybe)
@@ -49,7 +50,8 @@ add_barriers x = non_addr_char ++ x ++ non_addr_char
 --   3. Generate a regex matching every value between those min and
 --      max values.
 --   4. Join the regexes from step 3 with regexes matching periods.
---   5. Stick an address boundary on either side of the result.
+--   5. Stick an address boundary on either side of the result if
+--      use_barriers is True.
 --
 cidr_to_regex :: Bool -> Cidr.Cidr -> String
 cidr_to_regex use_barriers cidr =
@@ -79,9 +81,15 @@ alternate terms = "(" ++ (intercalate "|" terms) ++ ")"
 
 -- | Take two Ints as parameters, and return a regex matching any
 --   integer between them (inclusive).
+--
+--   IMPORTANT: we match from max to min so that if e.g. the last
+--   octet is '255', we want '255' to match before '2' in the regex
+--   (255|254|...|3|2|1) which does not happen if we use
+--   (1|2|3|...|254|255).
+--
 numeric_range :: Int -> Int -> String
 numeric_range x y =
-    alternate (map show [lower..upper])
+    alternate (map show $ reverse [lower..upper])
      where
        lower = minimum [x,y]
        upper = maximum [x,y]
@@ -152,5 +160,7 @@ main = do
         space = BS.pack " "
         results =
           case eds of
+            -- NameError simply means "not found" so we output nothing.
+            Left NameError -> ""
             Left err -> "ERROR (" ++ (show err) ++ ")"
             Right ds -> BS.unpack $ BS.intercalate space ds