Parse package names with a period
All checks were successful
Build / audit (push) Successful in 9s
Build / test (push) Successful in 14m10s

This commit is contained in:
Eugen Wissner 2024-11-27 22:41:03 +01:00
parent 468852410e
commit 15cf346c61
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 48 additions and 2 deletions

View File

@ -28,7 +28,7 @@ import Data.Void (Void)
import Data.Word (Word8)
import Numeric (readHex, showHex)
import Text.Megaparsec (Parsec, count, eof, parse, takeWhile1P)
import Text.Megaparsec.Byte (space, string, hexDigitChar)
import Text.Megaparsec.Byte (hspace1, space, string, hexDigitChar)
import Text.URI
( URI(..)
, parserBs
@ -43,6 +43,7 @@ import SlackBuilder.Trans
import System.FilePath ((</>), (<.>))
import Control.Monad.IO.Class (MonadIO(..))
import Conduit (MonadThrow(throwM))
import Control.Monad (void)
type GenParser = Parsec Void ByteString
@ -66,7 +67,7 @@ variableEntry variable = string (Char8.append variable "=\"")
<* string "\"\n"
variableSeparator :: GenParser ()
variableSeparator = string " \\" *> space
variableSeparator = void $ some $ hspace1 <|> void (string "\\\n")
packageDownloads :: ByteString -> GenParser [URI]
packageDownloads variableName = string (variableName <> "=\"")
@ -99,6 +100,7 @@ packageName = takeWhile1P Nothing isNameToken
isNameToken x = Word8.isAlphaNum x
|| x == Word8._hyphen
|| x == Word8._underscore
|| x == Word8._period
parseInfoFile :: GenParser PackageInfo
parseInfoFile = PackageInfo . Char8.unpack

View File

@ -72,6 +72,50 @@ spec = do
it "accepts an empty downloads list" $
parseInfoFile' `shouldSucceedOn` infoDownload0
it "parses a package name with a dot" $
let given =
"PRGNAM=\"pkgnam.yaml\"\n\
\VERSION=\"1.2.3\"\n\
\HOMEPAGE=\"homepage\"\n\
\DOWNLOAD=\"https://dlackware.com/download.tar.gz\"\n\
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10\"\n\
\DOWNLOAD_x86_64=\"\"\n\
\MD5SUM_x86_64=\"\"\n\
\REQUIRES=\"\"\n\
\MAINTAINER=\"Z\"\n\
\EMAIL=\"test@example.com\"\n"
in parseInfoFile' `shouldSucceedOn` given
it "parses to downloads in a single line" $
let given =
"PRGNAM=\"pkgnam.yaml\"\n\
\VERSION=\"1.2.3\"\n\
\HOMEPAGE=\"homepage\"\n\
\DOWNLOAD=\"https://dlackware.com/download1.tar.gz https://dlackware.com/download2.tar.gz\"\n\
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10 0102030405060708090a0b0c0d0e0f11\"\n\
\DOWNLOAD_x86_64=\"\"\n\
\MD5SUM_x86_64=\"\"\n\
\REQUIRES=\"\"\n\
\MAINTAINER=\"Z\"\n\
\EMAIL=\"test@example.com\"\n"
in parseInfoFile' `shouldSucceedOn` given
it "parses downloads continuing on the next line" $
let given =
"PRGNAM=\"pkgnam.yaml\"\n\
\VERSION=\"1.2.3\"\n\
\HOMEPAGE=\"homepage\"\n\
\DOWNLOAD=\"https://dlackware.com/download1.tar.gz \\\n\
\ https://dlackware.com/download2.tar.gz\"\n\
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10 \\\n\
\ 0102030405060708090a0b0c0d0e0f11\"\n\
\DOWNLOAD_x86_64=\"\"\n\
\MD5SUM_x86_64=\"\"\n\
\REQUIRES=\"\"\n\
\MAINTAINER=\"Z\"\n\
\EMAIL=\"test@example.com\"\n"
in parseInfoFile' `shouldSucceedOn` given
describe "generate" $ do
it "generates an .info file without downloads" $
let given = PackageInfo "pkgnam" "1.2.3" "homepage" [] [] [] [] [] "Z" "test@example.com"