CHANGES: Update for release
[prosody.git] / tests / test_sasl.lua
blobdd63c5a00ec403dab610f31d4676ef803bcbcdae
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
9 local gmatch = string.gmatch;
10 local t_concat, t_insert = table.concat, table.insert;
11 local to_byte, to_char = string.byte, string.char;
13 local function _latin1toutf8(str)
14 if not str then return str; end
15 local p = {};
16 for ch in gmatch(str, ".") do
17 ch = to_byte(ch);
18 if (ch < 0x80) then
19 t_insert(p, to_char(ch));
20 elseif (ch < 0xC0) then
21 t_insert(p, to_char(0xC2, ch));
22 else
23 t_insert(p, to_char(0xC3, ch - 64));
24 end
25 end
26 return t_concat(p);
27 end
29 function latin1toutf8()
30 local function assert_utf8(latin, utf8)
31 assert_equal(_latin1toutf8(latin), utf8, "Incorrect UTF8 from Latin1: "..tostring(latin));
32 end
34 assert_utf8("", "")
35 assert_utf8("test", "test")
36 assert_utf8(nil, nil)
37 assert_utf8("foobar.r\229kat.se", "foobar.r\195\165kat.se")
38 end