aboutsummaryrefslogtreecommitdiff
path: root/tests/unicode_test.ml
blob: 8c58dc823416fb9a3fe2a66827eacf7766cf20fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
open OUnit2

let _msg ~expected ~result =
    Printf.sprintf "Expected %s but got %s"
    (String.escaped expected)
    (String.escaped result)

let test_decode env = begin
  let result = Unicode.decode ~encoding:`ISO_8859_1 "caf\xE9"
            |> Unicode.to_utf8
  and expected = "café" in

  assert_equal
      ~msg:(_msg ~expected ~result)
    expected
    result
end

let test_tolist env = begin


  let result = Unicode.decode ~encoding:`UTF_8 "café"
            |> Unicode.to_list in

  let expected = ['c'; 'a'; 'f'; '\xE9']
              |> List.map Uchar.of_char in

  assert_equal
    expected
    result

end


let tests = "unicode_test">::: [
  "test_decode" >:: test_decode;
  "test_tolist" >:: test_tolist

]