Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-foundation

Source of release 0.6.1

0.6.1 / src / text_codec / tests_lookup_tables.lucb

#==============================================================================================
#
#   tests_lookup_tables - the Encoding index lookups and the pointer searches of the encoders
#
#   DESCRIPTION:
#       Values pinned to the donor's behavior: each expectation was printed by the reference
#       build's LibTextCodec (Ladybird 47c82b38d0) for the same arguments. The donor has no unit
#       tests for these functions (Tests/LibTextCodec exercises them through the codecs).
#
#==============================================================================================

test "index code points and index pointers of every kind of index":
    assert(index_gb18030_code_point(0) == 0x4e02)
    assert(index_gb18030_code_point(23939) == 0xe4c5)
    assert(index_gb18030_code_point(23940) == none)
    assert(code_point_gb18030_index(0x4e02) == 0x0)
    assert(code_point_gb18030_index(0x20ac) == 0x1920)
    assert(code_point_gb18030_index(0x41) == none)
    assert(index_big5_code_point(941) == none)
    assert(index_big5_code_point(942) == 0x43f0)
    assert(index_big5_code_point(5024) == 0x3000)
    assert(index_big5_code_point(19781) == 0x79d4)
    assert(index_big5_code_point(19782) == none)
    assert(code_point_big5_index(0x2550) == 0x147f)
    assert(code_point_big5_index(0x70d7) == 0x31de)
    assert(index_jis0208_code_point(0) == 0x3000)
    assert(index_jis0208_code_point(108) == none)
    assert(index_jis0208_code_point(11103) == 0x9ed1)
    assert(index_jis0208_code_point(11104) == none)
    assert(code_point_jis0208_index(0x3088) == 0x161)
    assert(code_point_jis0208_index(0xff0d) == 0x3c)
    assert(code_point_jis0208_index(0x2170) == 0x21ba)
    assert(index_jis0212_code_point(107) == none)
    assert(index_jis0212_code_point(108) == 0x2d8)
    assert(index_jis0212_code_point(7210) == 0x9fa5)
    assert(index_jis0212_code_point(7211) == none)
    assert(code_point_jis0212_index(0x2d8) == 0x6c)
    assert(index_euc_kr_code_point(0) == 0xac02)
    assert(index_euc_kr_code_point(26) == none)
    assert(code_point_euc_kr_index(0xb29f) == 0x55c)
    assert(index_ibm866_code_point(0) == 0x410)
    assert(index_ibm866_code_point(127) == 0xa0)
    assert(index_ibm866_code_point(128) == none)
    assert(code_point_ibm866_index(0x25a0) == 0x7e)
    assert(index_iso_2022_jp_katakana_code_point(0) == 0x3002)
    assert(index_iso_2022_jp_katakana_code_point(62) == 0x309c)
    assert(index_iso_2022_jp_katakana_code_point(63) == none)
    assert(code_point_iso_2022_jp_katakana_index(0x309c) == 0x3e)
    assert(index_windows_1252_code_point(0) == 0x20ac)
    assert(index_windows_1252_code_point(1) == 0x81)
    assert(code_point_windows_1252_index(0x20ac) == 0x0)
    assert(index_windows_874_code_point(91) == none)
    assert(code_point_windows_874_index(0xfffd) == 0x5b)
    assert(index_iso_8859_3_code_point(37) == none)
    assert(index_x_mac_cyrillic_code_point(127) == 0x20ac)
    assert(code_point_koi8_u_index(0x491) == 0x2d)

test "the tables hold the index sizes and first pointers of the donor":
    assert(s_gb18030_ranges.length == 207)
    assert(s_gb18030_index.length == 23940)
    assert(s_big5_index.length == 18840 and s_big5_index_first_pointer == 942)
    assert(s_jis0208_index.length == 11104)
    assert(s_jis0212_index.length == 7103 and s_jis0212_index_first_pointer == 108)
    assert(s_euc_kr_index.length == 23750)
    assert(s_iso_2022_jp_katakana_index.length == 63)

test "a single-byte index maps every pointer the table maps":
    for pointer: u32 in 0..<128:
        let entry = s_windows_1251_index[pointer]
        if entry == 0xfffd:
            assert(index_windows_1251_code_point(pointer) == none)
        else:
            assert(index_windows_1251_code_point(pointer) == (u32)entry)
            assert(code_point_windows_1251_index(entry) == pointer)

test "index gb18030 ranges code point and pointer":
    assert(index_gb18030_ranges_code_point(0) == 0x80)
    assert(index_gb18030_ranges_code_point(1) == 0x81)
    assert(index_gb18030_ranges_code_point(35) == 0xa3)
    assert(index_gb18030_ranges_code_point(36) == 0xa5)
    assert(index_gb18030_ranges_code_point(37) == 0xa6)
    assert(index_gb18030_ranges_code_point(7456) == 0x1e3e)
    assert(index_gb18030_ranges_code_point(7457) == 0xe7c7)
    assert(index_gb18030_ranges_code_point(7458) == 0x1e40)
    assert(index_gb18030_ranges_code_point(19056) == 0x9fb3)
    assert(index_gb18030_ranges_code_point(19057) == 0xe81e)
    assert(index_gb18030_ranges_code_point(19064) == 0xe864)
    assert(index_gb18030_ranges_code_point(19065) == 0x9fbc)
    assert(index_gb18030_ranges_code_point(39076) == 0xe78d)
    assert(index_gb18030_ranges_code_point(39085) == 0xe796)
    assert(index_gb18030_ranges_code_point(39086) == 0xfe1a)
    assert(index_gb18030_ranges_code_point(39419) == 0xffff)
    assert(index_gb18030_ranges_code_point(39420) == none)
    assert(index_gb18030_ranges_code_point(188999) == none)
    assert(index_gb18030_ranges_code_point(189000) == 0x10000)
    assert(index_gb18030_ranges_code_point(189001) == 0x10001)
    assert(index_gb18030_ranges_code_point(1237575) == 0x10ffff)
    assert(index_gb18030_ranges_code_point(1237576) == none)
    assert(index_gb18030_ranges_pointer(0x80) == 0)
    assert(index_gb18030_ranges_pointer(0x81) == 1)
    assert(index_gb18030_ranges_pointer(0xa4) == 36)
    assert(index_gb18030_ranges_pointer(0xa5) == 36)
    assert(index_gb18030_ranges_pointer(0xe7c7) == 7457)
    assert(index_gb18030_ranges_pointer(0xe5e5) == 37026)
    assert(index_gb18030_ranges_pointer(0xfffe) == 39418)
    assert(index_gb18030_ranges_pointer(0xffff) == 39419)
    assert(index_gb18030_ranges_pointer(0x10000) == 189000)
    assert(index_gb18030_ranges_pointer(0x10ffff) == 1237575)
    assert(index_gb18030_ranges_pointer(0xe81e) == 33490)
    assert(index_gb18030_ranges_pointer(0xfe10) == 39076)

test "index Big5 pointer, with the six code points that take the last pointer":
    assert(index_big5_pointer(0x2550) == 18991)
    assert(index_big5_pointer(0x255e) == 18975)
    assert(index_big5_pointer(0x2561) == 18977)
    assert(index_big5_pointer(0x256a) == 18976)
    assert(index_big5_pointer(0x5341) == 5512)
    assert(index_big5_pointer(0x5345) == 5599)
    assert(index_big5_pointer(0x43f0) == none)
    assert(index_big5_pointer(0x3000) == 5024)
    assert(index_big5_pointer(0x70d7) == 12766)
    assert(index_big5_pointer(0x41) == none)
    assert(index_big5_pointer(0x1f600) == none)

test "index Shift_JIS pointer skips the pointers 8272 to 8835":
    assert(index_shift_jis_pointer(0x3088) == 353)
    assert(code_point_jis0208_index(0x3088) == 353)
    assert(index_shift_jis_pointer(0x2170) == 10716)
    assert(code_point_jis0208_index(0x2170) == 8634)
    assert(index_shift_jis_pointer(0xff0d) == 60)
    assert(code_point_jis0208_index(0xff0d) == 60)
    assert(index_shift_jis_pointer(0x2252) == 159)
    assert(code_point_jis0208_index(0x2252) == 159)
    assert(index_shift_jis_pointer(0x41) == none)
    assert(code_point_jis0208_index(0x41) == none)
    assert(index_shift_jis_pointer(0x3000) == 0)
    assert(code_point_jis0208_index(0x3000) == 0)
    assert(code_point_jis0208_index_skipping_range(0x2170, 8272, 8835) == 10716)
    assert(code_point_jis0208_index_skipping_range(0x2170, 0, 0) == 8634)