Create unit test for Util module

This commit is contained in:
2021-11-08 11:12:09 +01:00
parent 42b2eb5e41
commit 66dad8ea00
5 changed files with 69 additions and 7 deletions

View File

@@ -111,12 +111,7 @@ sepTokenizer _ _ [] = Nothing
sepTokenizer predicate tokenizer input = do
result@(TokenizeResult _ consumed) <- tokenizer input
let next = drop consumed input
let (isSep, _) = if null next
then (True, 0)
else if predicate . head $ next
then (True, 1)
else (False, 0)
if isSep
if null next || (predicate . head $ next)
then return $ result
else Nothing

View File

@@ -63,6 +63,7 @@ controlChar x = case x of
explode :: (Foldable f) => (a -> Bool) -> f a -> [[a]]
explode predicate xs = filter (not . null) $ foldr split [[]] xs
where
split _ [] = []
split y (ys:yss)
| predicate y = []:ys:yss
| otherwise = (y:ys):yss
| otherwise = (y:ys):yss

View File

@@ -97,6 +97,8 @@ instructions = [ Simple { _op = Nop, _noParams = 0, _noPops = 0, _sAction = (\
]
jumpIf :: (Int -> Int -> Bool) -> VM -> Args -> Either String VM
jumpIf _ _ [] = Left $ "Address expected"
jumpIf _ _ (_:_:_) = Left $ "Multiple parameters are not supported by jmp* instructions"
jumpIf predicate vm [addr] = Right $ vm { _pc = pc }
where
(top:_) = toList . _stack $ vm