Idris2/tests/refc/strings/TestStrings.idr

69 lines
2.0 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
2021-06-07 16:30:08 +03:00
isUnderscore : Char -> Bool
isUnderscore '_' = True
isUnderscore _ = False
isHelloWorld : String -> Bool
isHelloWorld "Hello, world" = True
isHelloWorld _ = False
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"
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"