A parser for commandlines, returns an arg list and expands
format strings given in a translation table. Additionally
the commandline can end with %< specifying that the command
expects input on stdin.
Some tests for the parser.
formatTable = [('s',"<insert subject here>"),
('a',"<insert author here>")]
testParser :: (Show a, Eq a) => Parser a -> String -> a -> a
testParser p s ok = case parse p "" s of
Left e -> error $ "Parser failed with: " ++ (show e)
Right res -> if res == ok
then res
else error $ "Parser failed: got "
++ (show res) ++ ", expected "
++ (show ok)
testCases = [("a b",(["a","b"], False)),
("a b %<",(["a","b"], True)),
("a b %< ",(["a","b"], True)),
("\"arg0 contains spaces \\\"quotes\\\"\" b",
(["arg0 contains spaces \"quotes\"","b"],False)),
("a %s %<",(["a","<insert subject here>"], True))]
runTests = map (uncurry $ testParser (commandline formatTable)) testCases
|