tests/test_sasl.lua
author Matthew Wild <mwild1@gmail.com>
Wed, 03 Dec 2008 13:06:23 +0000
changeset 518 127eb78cbf4a
parent 509 32899c8a6fe5
child 519 cccd610a0ef9
permissions -rw-r--r--
Fix port number in mod_console instructions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
509
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     1
--- WARNING! ---
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
-- This file contains a mix of encodings below. 
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
-- Many editors will unquestioningly convert these for you.
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
-- Please be careful :(  (I recommend Scite)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
---------------------------------
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
local	gmatch = string.gmatch;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
local	t_concat, t_insert = table.concat, table.insert;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
local	to_byte, to_char = string.byte, string.char;
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
local function _latin1toutf8(str)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
		if not str then return str; end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
                local p = {};
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
                for ch in gmatch(str, ".") do
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
                        ch = to_byte(ch);
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
                        if (ch < 0x80) then
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    17
                                t_insert(p, to_char(ch));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
                        elseif (ch < 0xC0) then
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
                                t_insert(p, to_char(0xC2, ch));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
                        else
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
                                t_insert(p, to_char(0xC3, ch - 64));
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
                        end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
                end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
                return t_concat(p);
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
        end
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
function latin1toutf8()
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
	local function assert_utf8(latin, utf8)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    29
			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
    30
	end
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
	
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
	assert_utf8("", "")
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    33
	assert_utf8("test", "test")
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    34
	assert_utf8(nil, nil)
32899c8a6fe5 Add test for latin1toutf8 (which passes)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    35
	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
    36
end