tests/test_sasl.lua

Wed, 10 Dec 2008 15:44:03 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 10 Dec 2008 15:44:03 +0000
changeset 615
4ae3e81513f3
parent 519
cccd610a0ef9
child 758
b1885732e979
permissions
-rw-r--r--

0.1 -> 0.2

615
4ae3e81513f3 0.1 -> 0.2
Matthew Wild <mwild1@gmail.com>
parents: 519
diff changeset
1 -- Prosody IM v0.2
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
2 -- Copyright (C) 2008 Matthew Wild
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
3 -- Copyright (C) 2008 Waqas Hussain
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
4 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
5 -- This program is free software; you can redistribute it and/or
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
6 -- modify it under the terms of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
7 -- as published by the Free Software Foundation; either version 2
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
8 -- of the License, or (at your option) any later version.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
9 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
10 -- This program is distributed in the hope that it will be useful,
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
13 -- GNU General Public License for more details.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
14 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
15 -- You should have received a copy of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
16 -- along with this program; if not, write to the Free Software
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
18 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
19
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 509
diff changeset
20
509
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 --- WARNING! ---
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 -- This file contains a mix of encodings below.
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 -- Many editors will unquestioningly convert these for you.
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 -- Please be careful :( (I recommend Scite)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 ---------------------------------
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local gmatch = string.gmatch;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local t_concat, t_insert = table.concat, table.insert;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 local to_byte, to_char = string.byte, string.char;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local function _latin1toutf8(str)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if not str then return str; end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local p = {};
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 for ch in gmatch(str, ".") do
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 ch = to_byte(ch);
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 if (ch < 0x80) then
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 t_insert(p, to_char(ch));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 elseif (ch < 0xC0) then
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 t_insert(p, to_char(0xC2, ch));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 else
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 t_insert(p, to_char(0xC3, ch - 64));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 return t_concat(p);
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 function latin1toutf8()
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 local function assert_utf8(latin, utf8)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 assert_equal(_latin1toutf8(latin), utf8, "Incorrect UTF8 from Latin1: "..tostring(latin));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 assert_utf8("", "")
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 assert_utf8("test", "test")
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 assert_utf8(nil, nil)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 assert_utf8("foobar.råkat.se", "foobar.rÃ¥kat.se")
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 end

mercurial