Commit 7e260784 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Move lib/Char tests from testsuite to base

parent 2b0adbd2
......@@ -7,3 +7,13 @@ test('fixed', normal, compile_and_run, [''])
test('quotOverflow', normal, compile_and_run, [''])
test('assert', exit_code(1), compile_and_run, ['-fno-ignore-asserts'])
test('CPUTime001', normal, compile_and_run, [''])
test('readLitChar', normal, compile_and_run, [''])
test('unicode001',
if_platform('i386-unknown-openbsd', expect_fail),
compile_and_run,
[''])
test('unicode002',
if_platform('i386-unknown-openbsd', expect_fail),
compile_and_run,
[''])
module Main (main)
where
import Data.Char (digitToInt, lexLitChar, readLitChar)
main :: IO ()
main =
do putStrLn (show $ readLitChar "A")
putStrLn (show $ readLitChar "'A'")
putStrLn (show $ lexLitChar "A")
putStrLn (show $ lexLitChar "'A'")
[('A',"")]
[('\'',"A'")]
[("A","")]
[("'","A'")]
-- !!! Tests the various character classifiactions for a selection of Unicode
-- characters.
module Main where
import Data.Char
main = do
putStrLn (" " ++ concat (map (++" ") strs))
mapM putStrLn (map do_char chars)
where
do_char char = s ++ (take (12-length s) (repeat ' ')) ++ concat (map f bs)
where
s = show char
bs = map ($char) functions
f True = "X "
f False = " "
strs = ["upper","lower","alpha","alnum","digit","print","space","cntrl"]
functions = [isUpper,isLower,isAlpha,isAlphaNum,isDigit,isPrint,isSpace,isControl]
chars = [backspace,tab,space,zero,lower_a,upper_a,delete,
right_pointing_double_angle_quotation_mark,
greek_capital_letter_alpha,
bengali_digit_zero,
en_space,
gothic_letter_ahsa,
monospaced_digit_zero
]
backspace = '\x08'
tab = '\t'
space = ' '
zero = '0'
lower_a = 'a'
upper_a = 'A'
delete = '\x7f'
right_pointing_double_angle_quotation_mark = '\xBB'
latin_small_letter_i_with_caron = '\x1D0'
combining_acute_accent = '\x301'
greek_capital_letter_alpha = '\x0391'
bengali_digit_zero = '\x09E6'
en_space = '\x2002'
gothic_letter_ahsa = '\x10330'
monospaced_digit_zero = '\x1D7F6'
upper lower alpha alnum digit print space cntrl
'\b' X
'\t' X X
' ' X X
'0' X X X
'a' X X X X
'A' X X X X
'\DEL' X
'\187' X
'\913' X X X X
'\2534' X X
'\8194' X X
'\66352' X X X
'\120822' X X
upper lower alpha alnum digit print space cntrl
'\b' X
'\t' X X
' ' X X
'0' X X X
'a' X X X X
'A' X X X X
'\DEL' X
'\187' X
'\913' X X X X
'\2534' X X
'\8194' X
'\66352' X X X
'\120822' X X
module Main where
import Data.Char
import Numeric
header = "Code C P S U L A D"
preds = [
isControl,
isPrint,
isSpace,
isUpper,
isLower,
isAlpha,
isDigit]
prtBool :: Bool -> String
prtBool True = "T "
prtBool False = "F "
showCode :: Char -> Int -> String
showCode c w = code ++ pad
where
code = show (ord c)
l = length code
spaces = map anytospace [1..]
anytospace _ = ' '
pad | l >= w = ""
| otherwise = take (w - l) spaces
charCode :: Char -> String
rapply a b = b a
charCode c = (showCode c 5) ++ (foldr1 (++) $ map prtBool $ map (rapply c) preds)
main = do
putStrLn header
mapM (putStrLn . charCode) [ (chr 0) .. (chr 6553) ]
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment