<commit_before>module Main where

import Language.GoLite

import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
import Text.Megaparsec

main = hspec goLite

goLite = describe "Language.GoLite" $ do
    lexer

lexer = describe "Lexer" $ do
    describe "octal_lit" $ do
        it "parses an octal integer literal" $ do
            parseOnly octal_lit "054321" `shouldBe` Right 0o54321

        it "can parse an arbitrary number of zeroes" $ do
            parseOnly octal_lit "00000" `shouldBe` Right 0

        prop "cannot begin with a nonzero digit" $ do
            forAll (choose ('1', '7')) (isLeft . parseOnly octal_lit . (:"53421"))

isRight (Right _) = True
isRight _ = False

isLeft (Left _) = True
isLeft _ = False

parseOnly m = parse (m <* eof) "test"<commit_msg>add some test cases for hexadecimal literal parsing<commit_after>module Main where

import Language.GoLite

import Control.Monad
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
import Text.Megaparsec
import Text.Megaparsec.String

main :: IO ()
main = hspec goLite

goLite :: SpecWith ()
goLite = describe "Language.GoLite" $ do
    lexer

lexer :: SpecWith ()
lexer = describe "Lexer" $ do
    describe "octal_lit" $ do
        it "parses an octal integer literal" $ do
            parseOnly octal_lit "054321" `shouldBe` Right 0o54321

        prop "parses an arbitrary number of zeroes" $ do
            forAll (choose (1, 100)) $ \n ->
               isRight . parseOnly octal_lit . replicate n $ '0'

        prop "cannot parse strings beginning with a nonzero digit" $ do
            forAll (choose ('1', '7'))
                   (isLeft . parseOnly octal_lit . (:"53421"))

    describe "hex_lit" $ do
        prop "parses hexadecimal integer literals" $ do
            forAll (resize 8 hexGenLower) $ \s ->
                parseOnly hex_lit s == Right (read s :: Int)

        prop "doesn't care about letter-digit case"$ do
            forAll (resize 8 hexGenMixedCase) $ \s ->
                parseOnly hex_lit s == Right (read s :: Int)

hexGenLower :: Gen String
hexGenLower = ("0x" ++) <$> mkDigits where
    mkDigits
        = sized
        . flip replicateM
        . elements
        $ ['0'..'9'] ++ ['a'..'f']

hexGenMixedCase :: Gen String
hexGenMixedCase = (++) <$> prefixes <*> mkDigits where
    prefixes = elements ["0x", "0X"]
    mkDigits
        = sized
        . flip replicateM
        . elements
        $ ['0'..'9'] ++ ['a'..'f'] ++ ['A'..'F']

isRight :: Either a b -> Bool
isRight (Right _) = True
isRight _ = False

isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft _ = False

parseOnly :: Parser a -> String -> Either ParseError a
parseOnly m = parse (m <* eof) "test"
{'fraction_non_alphanumeric': 0.1119676945668135, 'fraction_numerical': 0.021292217327459617, 'mean_word_length': 2.5252263906856403, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5470512', 'n_tokens_mistral': 929, 'n_tokens_neox': 874, 'n_words': 290}