Create unit test for Util module
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user