aboutsummaryrefslogtreecommitdiff
path: root/tests/unicode_test.ml
blob: 6f8ffa90a3c3261a123f86d50fb0038591dafbb4 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(*
This file is part of licht.

licht is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

licht is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with licht.  If not, see <http://www.gnu.org/licenses/>.
*)

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

]