File: utf8_test.ml

package info (click to toggle)
ulex 1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 204 kB
  • ctags: 308
  • sloc: ml: 1,199; makefile: 92
file content (18 lines) | stat: -rw-r--r-- 535 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#load "utf8.cmo";;

let () =
  let b = Buffer.create 10 in
  for i = 0 to 0x10ffff do
    if (i >= 0xd800) && (i <= 0xdfff) then ()
    else (
      (try Utf8.store b i with Utf8.MalFormed ->
	Printf.eprintf "Conversion failure %x\n" i; exit 1);
      let s = Buffer.contents b in
      Buffer.clear b;
      let j = 
	try Utf8.next s 0 with Utf8.MalFormed ->
	  Printf.eprintf "Deconversion failure %x (%S)\n" i s; exit 1 in
      if (i != j) then 
	(Printf.eprintf "Conversion/deconversion error. %x->%x\n" i j; exit 1)
    )
  done