2021-05-17 13:48:46 +03:00
|
|
|
module TestStrings
|
|
|
|
|
|
|
|
import Data.String
|
2021-05-17 16:30:00 +03:00
|
|
|
import Data.String.Iterator
|
|
|
|
|
|
|
|
iteratorTail : String -> String
|
|
|
|
iteratorTail str = withString str $ \it => unconsTail str (uncons str it)
|
|
|
|
where
|
|
|
|
unconsTail : (str : String) -> (1 _ : UnconsResult str) -> String
|
|
|
|
unconsTail str EOF = ""
|
|
|
|
unconsTail str (Character _ tailIt) = withIteratorString str tailIt id
|
2021-05-17 13:48:46 +03:00
|
|
|
|
2021-06-07 16:30:08 +03:00
|
|
|
isUnderscore : Char -> Bool
|
|
|
|
isUnderscore '_' = True
|
|
|
|
isUnderscore _ = False
|
|
|
|
|
|
|
|
isHelloWorld : String -> Bool
|
|
|
|
isHelloWorld "Hello, world" = True
|
|
|
|
isHelloWorld _ = False
|
|
|
|
|
2021-05-17 13:48:46 +03:00
|
|
|
main : IO ()
|
|
|
|
main = do
|
|
|
|
let helloWorld = "Hello, " ++ "world"
|
|
|
|
|
|
|
|
putStrLn helloWorld
|
|
|
|
putStrLn $ show $ length helloWorld
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ show $ String.length ""
|
2021-05-17 13:48:46 +03:00
|
|
|
|
|
|
|
putStrLn $ reverse helloWorld
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ reverse ""
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ substr 1 2 helloWorld
|
2024-01-22 16:25:22 +03:00
|
|
|
|
|
|
|
let overtake0 = substr 10 10 helloWorld
|
|
|
|
putStrLn $ "\{show $ length overtake0} : \{overtake0}"
|
|
|
|
let overtake1 = substr 1 2 ""
|
|
|
|
putStrLn $ "\{show $ length overtake1} : \{overtake1}"
|
|
|
|
putStrLn $ substr (-10) (1) helloWorld
|
|
|
|
putStrLn $ substr 2 (-2) helloWorld
|
|
|
|
putStrLn $ substr (-5) (-2) helloWorld
|
|
|
|
putStrLn $ substr 1000000 1 helloWorld
|
|
|
|
putStrLn $ substr 5 100000 helloWorld
|
|
|
|
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ show $ assert_total $ strIndex helloWorld 1
|
|
|
|
|
|
|
|
putStrLn $ strCons 'a' "bc"
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ strCons 'a' ""
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ show $ strUncons "abc"
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ show $ strUncons ""
|
2021-05-17 13:48:46 +03:00
|
|
|
|
|
|
|
putStrLn $ fastPack ['p', 'a', 'c', 'k']
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ fastPack []
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ show $ fastUnpack "unpack"
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ show $ fastUnpack ""
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ fastConcat ["con", "cat", "en", "ate"]
|
2021-05-20 15:28:02 +03:00
|
|
|
putStrLn $ fastConcat []
|
2021-05-17 13:48:46 +03:00
|
|
|
|
2021-05-17 16:30:00 +03:00
|
|
|
let chars = the (List Char) ['a', 'A', '~', '0', ' ', '\n', '\x9f']
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ show $ map isUpper chars
|
|
|
|
putStrLn $ show $ map isLower chars
|
|
|
|
putStrLn $ show $ map isDigit chars
|
|
|
|
putStrLn $ show $ map isSpace chars
|
|
|
|
putStrLn $ show $ map isNL chars
|
|
|
|
putStrLn $ show $ map isControl chars
|
|
|
|
|
2021-05-17 16:30:00 +03:00
|
|
|
putStrLn $ show $ map {f = List} chr [97, 65, 126, 48, 32, 10, 159]
|
2021-05-17 13:48:46 +03:00
|
|
|
putStrLn $ show $ map ord chars
|
2021-05-17 16:30:00 +03:00
|
|
|
|
|
|
|
putStrLn $ show $ Data.String.Iterator.unpack "iterator unpack"
|
|
|
|
putStrLn $ show $ iteratorTail "iterator tail"
|
2021-06-07 16:30:08 +03:00
|
|
|
|
|
|
|
-- Test Char pattern matching
|
|
|
|
putStrLn $ show $ isUnderscore '_'
|
|
|
|
putStrLn $ show $ isUnderscore ' '
|
|
|
|
|
|
|
|
-- Test String pattern matching
|
|
|
|
putStrLn $ show $ isHelloWorld helloWorld
|
|
|
|
putStrLn $ show $ isHelloWorld "Hello, Idris"
|