added tests for b64
This commit is contained in:
		
							parent
							
								
									252c5e5c68
								
							
						
					
					
						commit
						d44cef3060
					
				
							
								
								
									
										10
									
								
								based.cabal
								
								
								
								
							
							
						
						
									
										10
									
								
								based.cabal
								
								
								
								
							| 
						 | 
				
			
			@ -71,3 +71,13 @@ executable based
 | 
			
		|||
    -- base64-bytestring,
 | 
			
		||||
  -- hs-source-dirs:
 | 
			
		||||
  default-language:    Haskell2010
 | 
			
		||||
 | 
			
		||||
test-suite based-test
 | 
			
		||||
  type:              exitcode-stdio-1.0
 | 
			
		||||
  hs-source-dirs:    test
 | 
			
		||||
  main-is:           Main.hs
 | 
			
		||||
  build-depends:
 | 
			
		||||
    base,
 | 
			
		||||
    based,
 | 
			
		||||
    HUnit
 | 
			
		||||
  default-language:  Haskell2010
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
module Main where
 | 
			
		||||
 | 
			
		||||
import Test.HUnit
 | 
			
		||||
import Encoding.Base64 (enc64, dec64)
 | 
			
		||||
import System.Exit (exitFailure, exitSuccess)
 | 
			
		||||
 | 
			
		||||
-- Test cases for enc64 function
 | 
			
		||||
testEnc64 :: Test
 | 
			
		||||
testEnc64 = TestCase $ do
 | 
			
		||||
    assertEqual "for (enc64 \"hello\")," "aGVsbG8=" (enc64 "hello")
 | 
			
		||||
    assertEqual "for (enc64 \"Haskell\")," "SGFza2VsbA==" (enc64 "Haskell")
 | 
			
		||||
    assertEqual "for (enc64 \"\x00\x01\x02\")," "AAEC" (enc64 "\x00\x01\x02")
 | 
			
		||||
    assertEqual "for (enc64 \"😂\")," "8J+Ygg==" (enc64 "😂")
 | 
			
		||||
 | 
			
		||||
-- Test cases for dec64 function
 | 
			
		||||
testDec64 :: Test
 | 
			
		||||
testDec64 = TestCase $ do
 | 
			
		||||
    assertEqual "for (dec64 \"aGVsbG8=\")," "hello" (dec64 "aGVsbG8=")
 | 
			
		||||
    assertEqual "for (dec64 \"SGFza2VsbA==\")," "Haskell" (dec64 "SGFza2VsbA==")
 | 
			
		||||
    assertEqual "for (dec64 \"AAEC\")," "\x00\x01\x02" (dec64 "AAEC")
 | 
			
		||||
    assertEqual "for (dec64 \"8J+Ygg==\")," "😂" (dec64 "😂")
 | 
			
		||||
 | 
			
		||||
tests :: Test
 | 
			
		||||
tests = TestList [TestLabel "Test enc64" testEnc64,
 | 
			
		||||
                  TestLabel "Test dec64" testDec64]
 | 
			
		||||
 | 
			
		||||
-- main :: IO Counts
 | 
			
		||||
-- main = runTestTT tests >>= \counts -> print counts >> runTestTTAndExit tests
 | 
			
		||||
 | 
			
		||||
-- runAndPrint :: Test -> IO Counts
 | 
			
		||||
-- runAndPrint t = do
 | 
			
		||||
--     counts <- runTestTT t
 | 
			
		||||
--     let label = case t of
 | 
			
		||||
--                   TestLabel l _ -> l
 | 
			
		||||
--                   _             -> "Unnamed test."
 | 
			
		||||
--     putStrLn $ label ++ ": " ++ if errors counts + failures counts == 0 then "[OK]" else "[FAIL]"
 | 
			
		||||
--     return counts
 | 
			
		||||
 | 
			
		||||
main :: IO ()
 | 
			
		||||
main = do
 | 
			
		||||
    counts <- runTestTT tests
 | 
			
		||||
    print counts
 | 
			
		||||
    if errors counts + failures counts == 0
 | 
			
		||||
        then exitSuccess
 | 
			
		||||
        else exitFailure
 | 
			
		||||
		Loading…
	
		Reference in New Issue