Idris2/tests/refc/strings/TestStrings.idr

53 lines
1.6 KiB
Idris
Raw Normal View History

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
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 ""
putStrLn $ reverse helloWorld
2021-05-20 15:28:02 +03:00
putStrLn $ reverse ""
putStrLn $ substr 1 2 helloWorld
2021-05-20 15:28:02 +03:00
putStrLn $ substr 10 10 helloWorld
putStrLn $ substr 1 2 ""
putStrLn $ show $ assert_total $ strIndex helloWorld 1
putStrLn $ strCons 'a' "bc"
2021-05-20 15:28:02 +03:00
putStrLn $ strCons 'a' ""
putStrLn $ show $ strUncons "abc"
2021-05-20 15:28:02 +03:00
putStrLn $ show $ strUncons ""
putStrLn $ fastPack ['p', 'a', 'c', 'k']
2021-05-20 15:28:02 +03:00
putStrLn $ fastPack []
putStrLn $ show $ fastUnpack "unpack"
2021-05-20 15:28:02 +03:00
putStrLn $ show $ fastUnpack ""
putStrLn $ fastConcat ["con", "cat", "en", "ate"]
2021-05-20 15:28:02 +03:00
putStrLn $ fastConcat []
2021-05-17 16:30:00 +03:00
let chars = the (List Char) ['a', 'A', '~', '0', ' ', '\n', '\x9f']
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]
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"