Created
May 29, 2013 01:31
-
-
Save stealthcode/5667379 to your computer and use it in GitHub Desktop.
hsvim kata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.HUnit | |
data Vim = Vim { cursorRow :: Int, cursorCol :: Int, conent :: String } deriving (Show, Eq) | |
right :: Vim -> Vim | |
right v@(Vim y x msg) | |
| x > 0 = Vim y (x-1) msg | |
| otherwise = v | |
left :: Vim -> Vim | |
left v@(Vim y x msg) | |
| x < (length msg) = Vim y (x+1) msg | |
| otherwise = v | |
up :: Vim -> Vim | |
up v@(Vim y x msg) | |
| y > 0 = Vim (y - 1) x msg | |
| otherwise = v | |
vimify :: Char -> Vim -> Vim | |
vimify 'h' = right | |
vimify 'l' = left | |
vimify 'j' = up | |
vimify _ = error "Unrecognized command issued" | |
content = "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit" | |
testData1 = Vim 0 9 content | |
testResult1 = Vim 0 8 content | |
testData1v2 = Vim 0 0 content | |
testResult1v2 = Vim 0 0 content | |
testData2 = Vim 0 9 content | |
testResult2 = Vim 0 10 content | |
testData3 = Vim 1 9 content | |
testResult3 = Vim 0 9 content | |
testData4 = Vim 1 9 content | |
testResult4 = Vim 0 9 content | |
tests = test | |
[ "test 1" ~: "test that 'h' moves cursor left one" | |
~: testResult1 ~=? (vimify 'h' testData1) | |
, "test 1v2" ~: "test that 'h' moves cursor left one" | |
~: testResult1v2 ~=? (vimify 'h' testData1v2) | |
, "test 2" ~: "test that 'l' moves cursor right one" | |
~: testResult2 ~=? (vimify 'l' testData2) | |
, "test 3" ~: "test that 'j' moves cursor stays" | |
~: testResult3 ~=? (vimify 'j' testData3) | |
, "test 4" ~: "test that 'j' moves up to line 0" | |
~: testResult4 ~=? (vimify 'j' testData4) | |
] | |
main = do | |
runTestTT tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment