home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / tests / general / cset.icn < prev    next >
Text File  |  2001-12-06  |  2KB  |  86 lines

  1. #SRC: JCON
  2.  
  3. # test csets and character conversions
  4.  
  5. procedure main()
  6.    local a, c, i, n, s, cs, ct, x, y
  7.  
  8.    x := 'a1b2c3'
  9.    write("x:    ", x);
  10.    write("*x:   ", *x)
  11.    every writes("!x:   " | !x | "\n");
  12.    write("?z:   ", ?'z')
  13.    write("?empty: ", ?'', " (OOPS)")    # should fail
  14.    write()
  15.  
  16.    kw("digits", &digits)
  17.    kw("lcase", &lcase)
  18.    kw("ucase", &ucase)
  19.    kw("letters", &letters)
  20.    write("    &ascii: ", *&ascii, " elements")
  21.    write()
  22.  
  23.    write ("   x         y     ",
  24.       "     x++y         y++x     x--y   y--x   x**y   y**x   ~~x")
  25.  
  26.    every x := ( 'a1b2c3' | "a1b2c3" | 1234 | 12.34 | '') &
  27.          y := ( 'xyzabc' | "xyzabc" | 3456 | 34.56 | "@ 90") do {
  28.     write(
  29.        right(image(x),8), right(image(y),9),
  30.        right(x++y, 13), right(y++x, 13),
  31.        right(x--y, 7), right(y--x, 7),
  32.        right(x**y, 7), right(y**x, 7),
  33.        right(~~x, 7))
  34.    }
  35.  
  36.    # various tests involving chars with the sign bit set
  37.  
  38.    # test conversion of int to char (string) and back
  39.    write()
  40.    every i := 0 to 255 by 15 do {
  41.       s := ""
  42.       c := char(i)
  43.       s ||:= c
  44.       n := ord(c)
  45.       cs := cset(c)
  46.       write(right(i, 3), right(image(c), 8), right(image(s), 8), right(n, 5),
  47.      right(image(cs), 8))
  48.       }
  49.  
  50.    # test more and stranger conversions 
  51.    write()
  52.    a := [0, 15.71, "32rU", "16r2D", "60", "8r113", "90", "105", "120", "8r207",
  53.     "16r96", "16ra5", "16rB4", "16rc3", "16rD2", "16re1", "16rf0", "16rfF"]
  54.    every s := !a do {
  55.       c := char(s)
  56.       n := ord(c)
  57.       write(right(image(s), 8), right(image(c), 8), right(n, 5))
  58.       }
  59.  
  60.    # test conversion of string to int and back
  61.    write()
  62.    a := ["\x00", "\x0F", "\x1e", "-", "<", "\113", "Z", "i", "x", "\x87",
  63.          "\x96", "\xa5", "\xB4", "\xc3", "\xD2", "\xe1", "\xf0", "\xfF"]
  64.    every s := !a do {
  65.       n := ord(s)
  66.       c := char(n)
  67.       write(right(image(s), 6), right(n, 5), right(image(c), 8))
  68.       }
  69.  
  70.    # test conversion of cset to string and int
  71.    write()
  72.    a := ['\x00', '\x0F', '\x1e', '-', '<', '\113', 'Z', 'i', 'x', '\x87',
  73.          '\x96', '\xa5', '\xB4', '\xc3', '\xD2', '\xe1', '\xf0', '\xfF']
  74.    every cs := !a do {
  75.       s := string(cs)
  76.       n := ord(cs)
  77.       write(right(image(cs), 6), right(image(s), 8), right(n, 5))
  78.       }
  79. end
  80.  
  81. procedure kw(label, value)
  82.    write(right("&" || label, 10), ": '", value, "'")
  83.    return
  84. end
  85.  
  86.