summaryrefslogtreecommitdiff
path: root/tests/unilbrk
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-02-07 06:57:44 +0100
committerJörg Frings-Fürst <debian@jff.email>2022-02-07 06:57:44 +0100
commit6ffaa52cf732a84c0f8259dbc9b8183960ec5c33 (patch)
treed3136c22e3e805cfc0efe78412cce905a17e0c8d /tests/unilbrk
parent591cbf5878b7d4105b275585b9db1324c9dfce56 (diff)
parentaf151c593704a40e10efb28d1e3dd59a23a661f3 (diff)
Merge branch 'release/debian/1.0-1'debian/1.0-1
Diffstat (limited to 'tests/unilbrk')
-rw-r--r--tests/unilbrk/test-u16-possible-linebreaks.c181
-rw-r--r--tests/unilbrk/test-u16-width-linebreaks.c21
-rw-r--r--tests/unilbrk/test-u32-possible-linebreaks.c181
-rw-r--r--tests/unilbrk/test-u32-width-linebreaks.c21
-rw-r--r--tests/unilbrk/test-u8-possible-linebreaks.c172
-rw-r--r--tests/unilbrk/test-u8-width-linebreaks.c21
-rw-r--r--tests/unilbrk/test-ulc-possible-linebreaks.c36
-rw-r--r--tests/unilbrk/test-ulc-width-linebreaks.c21
8 files changed, 596 insertions, 58 deletions
diff --git a/tests/unilbrk/test-u16-possible-linebreaks.c b/tests/unilbrk/test-u16-possible-linebreaks.c
index 2c99d5d..1d897a2 100644
--- a/tests/unilbrk/test-u16-possible-linebreaks.c
+++ b/tests/unilbrk/test-u16-possible-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-16 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (void (*my_u16_possible_linebreaks) (const uint16_t *, size_t, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u16_possible_linebreaks (NULL, 0, "GB18030", NULL);
+ my_u16_possible_linebreaks (NULL, 0, "GB18030", NULL);
{
static const uint16_t input[61] =
@@ -45,13 +46,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u16_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
+ my_u16_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
i == 5
|| i == 11 || i == 25
- || i == 29 || i == 30
+ || i == 29
|| i == 45 || i == 51
|| i == 52 || i == 53 || i == 55 || i == 56
|| i == 58 || i == 59 ? UC_BREAK_POSSIBLE :
@@ -64,13 +65,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u16_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
+ my_u16_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
i == 5
|| i == 11 || i == 25
- || i == 29 || i == 30
+ || i == 29
|| i == 37 || i == 45 || i == 51
|| i == 52 || i == 53 || i == 55 || i == 56
|| i == 58 || i == 59 ? UC_BREAK_POSSIBLE :
@@ -80,6 +81,23 @@ main ()
}
}
+ /* CR LF handling. */
+ {
+ static const uint16_t input[8] =
+ { 'a', '\n', 'b', '\r', 'c', '\r', '\n', 'd' };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 8; i++)
+ {
+ ASSERT (p[i] == (i == 1 || i == 3 || i == 6 ? UC_BREAK_MANDATORY :
+ i == 5 ? (version < 2 ? UC_BREAK_MANDATORY : UC_BREAK_CR_BEFORE_LF) :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
/* Test that a break is possible after a zero-width space followed by some
regular spaces (rule LB8 in Unicode TR#14 revision 26). */
{
@@ -87,7 +105,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
for (i = 0; i < 4; i++)
{
ASSERT (p[i] == (i == 3 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
@@ -95,5 +113,150 @@ main ()
free (p);
}
+ /* Test line breaking in a string with HTML markup. */
+ {
+ static const uint16_t input[21] =
+ {
+ '<', 'P', '>', 'S', 'o', 'm', 'e', ' ', 's', 'e', 'n', 't',
+ 'e', 'n', 'c', 'e', '.', '<', '/', 'P', '>'
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 21; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 17 || i == 19 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of combining marks. */
+ {
+ static const uint16_t input[16] =
+ {
+ 'a', 0x0300, 0x0301, 'e', 0x0300, ' ', 0x0301, 'o', ' ', 0x0300, ' ',
+ 'o', 0x0A00, 0x0300, '\n',
+ 0x0300
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 16; i++)
+ {
+ ASSERT (p[i] == (i == 14 ? UC_BREAK_MANDATORY :
+ i == 6 || i == 9 || i == 11 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of zero-width joiners (U+200D). */
+ {
+ static const uint16_t input[39] =
+ {
+ 0x6709, 0x7121, 0x7AAE, 0x591A, 0x500B, 0x7D20, 0x6578, 0x3002, '\n',
+ 0x6709, 0x200D, 0x7121, 0x200D, 0x7AAE, 0x591A, 0x500B, 0x7D20, 0x200D, 0x6578, 0x3002, '\n',
+ 0x4F60, 0x2014, 0x4E0D, '\n',
+ 0x4F60, 0x2014, 0x200D, 0x4E0D, '\n',
+ 0x261D, 0xD83C, 0xDFFF, '\n',
+ 0x261D, 0x200D, 0xD83C, 0xDFFF, '\n',
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 39; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 20
+ || i == 24 || i == 29
+ || i == 33 || i == 38 ? UC_BREAK_MANDATORY :
+ i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6
+ || i == 14 || i == 15 || i == 16
+ || i == 22 || i == 23
+ || i == 26 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of regional indicators. */
+ {
+ static const uint16_t input[8] =
+ { 0xD83C, 0xDDE9, 0xD83C, 0xDDEA, 0xD83C, 0xDDEB, 0xD83C, 0xDDF7 };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 8; i++)
+ {
+ ASSERT (p[i] == (i == 4 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of hyphen/break-after character after
+ Hebrew letter. */
+ {
+ static const uint16_t input[10] = /* "ab-אב-αβ-ω" */
+ { 'a', 'b', '-', 0x05D0, 0x05D1, '-', 0x03B1, 0x03B2, '-', 0x03C9 };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 10; i++)
+ {
+ ASSERT (p[i] == (i == 3 || i == 9 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour before East Asian opening parenthesis (LB30). */
+ {
+ static const uint16_t input[17] = /* "日中韓統合漢字拡張G「ユニコード」" */
+ {
+ 0x65E5, 0x4E2D, 0x97D3, 0x7D71, 0x5408, 0x6F22, 0x5B57, 0x62E1, 0x5F35,
+ 'G', 0x300C, 0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9, 0x300D
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 17; i++)
+ {
+ ASSERT (p[i] == (i == 1 || i == 2 || i == 3 || i == 4 || i == 5
+ || i == 6 || i == 7 || i == 8 || i == 9
+ || i == 10 /* This is the desired break position. */
+ || i == 12 || i == 13 || i == 15 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of potential future emoji (LB30b). */
+ {
+ static const uint16_t input[4] = { 0xD83F, 0xDFFC, 0xD83C, 0xDFFF };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u16_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 4; i++)
+ {
+ ASSERT (p[i] == UC_BREAK_PROHIBITED);
+ }
+ free (p);
+ }
+}
+
+int
+main ()
+{
+ test_function (u16_possible_linebreaks, 2);
+#undef u16_possible_linebreaks
+ test_function (u16_possible_linebreaks, 1);
+
return 0;
}
diff --git a/tests/unilbrk/test-u16-width-linebreaks.c b/tests/unilbrk/test-u16-width-linebreaks.c
index f4465a4..a6a209f 100644
--- a/tests/unilbrk/test-u16-width-linebreaks.c
+++ b/tests/unilbrk/test-u16-width-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-16 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (int (*my_u16_width_linebreaks) (const uint16_t *, size_t, int, int, int, const char *, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u16_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
+ my_u16_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
{
static const uint16_t input[61] =
@@ -45,7 +46,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
+ my_u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
@@ -59,7 +60,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
+ my_u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
@@ -69,6 +70,14 @@ main ()
free (p);
}
}
+}
+
+int
+main ()
+{
+ test_function (u16_width_linebreaks, 2);
+#undef u16_width_linebreaks
+ test_function (u16_width_linebreaks, 1);
return 0;
}
diff --git a/tests/unilbrk/test-u32-possible-linebreaks.c b/tests/unilbrk/test-u32-possible-linebreaks.c
index 0434889..50e5910 100644
--- a/tests/unilbrk/test-u32-possible-linebreaks.c
+++ b/tests/unilbrk/test-u32-possible-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-32 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (void (*my_u32_possible_linebreaks) (const uint32_t *, size_t, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u32_possible_linebreaks (NULL, 0, "GB18030", NULL);
+ my_u32_possible_linebreaks (NULL, 0, "GB18030", NULL);
{
static const uint32_t input[61] =
@@ -45,13 +46,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u32_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
+ my_u32_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
i == 5
|| i == 11 || i == 25
- || i == 29 || i == 30
+ || i == 29
|| i == 45 || i == 51
|| i == 52 || i == 53 || i == 55 || i == 56
|| i == 58 || i == 59 ? UC_BREAK_POSSIBLE :
@@ -64,13 +65,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u32_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
+ my_u32_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
i == 5
|| i == 11 || i == 25
- || i == 29 || i == 30
+ || i == 29
|| i == 37 || i == 45 || i == 51
|| i == 52 || i == 53 || i == 55 || i == 56
|| i == 58 || i == 59 ? UC_BREAK_POSSIBLE :
@@ -80,6 +81,23 @@ main ()
}
}
+ /* CR LF handling. */
+ {
+ static const uint32_t input[8] =
+ { 'a', '\n', 'b', '\r', 'c', '\r', '\n', 'd' };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 8; i++)
+ {
+ ASSERT (p[i] == (i == 1 || i == 3 || i == 6 ? UC_BREAK_MANDATORY :
+ i == 5 ? (version < 2 ? UC_BREAK_MANDATORY : UC_BREAK_CR_BEFORE_LF) :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
/* Test that a break is possible after a zero-width space followed by some
regular spaces (rule LB8 in Unicode TR#14 revision 26). */
{
@@ -87,7 +105,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
for (i = 0; i < 4; i++)
{
ASSERT (p[i] == (i == 3 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
@@ -95,5 +113,150 @@ main ()
free (p);
}
+ /* Test line breaking in a string with HTML markup. */
+ {
+ static const uint32_t input[21] =
+ {
+ '<', 'P', '>', 'S', 'o', 'm', 'e', ' ', 's', 'e', 'n', 't',
+ 'e', 'n', 'c', 'e', '.', '<', '/', 'P', '>'
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 21; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 17 || i == 19 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of combining marks. */
+ {
+ static const uint32_t input[16] =
+ {
+ 'a', 0x0300, 0x0301, 'e', 0x0300, ' ', 0x0301, 'o', ' ', 0x0300, ' ',
+ 'o', 0x0A00, 0x0300, '\n',
+ 0x0300
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 16; i++)
+ {
+ ASSERT (p[i] == (i == 14 ? UC_BREAK_MANDATORY :
+ i == 6 || i == 9 || i == 11 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of zero-width joiners (U+200D). */
+ {
+ static const uint32_t input[37] =
+ {
+ 0x6709, 0x7121, 0x7AAE, 0x591A, 0x500B, 0x7D20, 0x6578, 0x3002, '\n',
+ 0x6709, 0x200D, 0x7121, 0x200D, 0x7AAE, 0x591A, 0x500B, 0x7D20, 0x200D, 0x6578, 0x3002, '\n',
+ 0x4F60, 0x2014, 0x4E0D, '\n',
+ 0x4F60, 0x2014, 0x200D, 0x4E0D, '\n',
+ 0x261D, 0x1F3FF, '\n',
+ 0x261D, 0x200D, 0x1F3FF, '\n',
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 37; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 20
+ || i == 24 || i == 29
+ || i == 32 || i == 36 ? UC_BREAK_MANDATORY :
+ i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6
+ || i == 14 || i == 15 || i == 16
+ || i == 22 || i == 23
+ || i == 26 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of regional indicators. */
+ {
+ static const uint32_t input[4] =
+ { 0x1F1E9, 0x1F1EA, 0x1F1EB, 0x1F1F7 };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 4; i++)
+ {
+ ASSERT (p[i] == (i == 2 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of hyphen/break-after character after
+ Hebrew letter. */
+ {
+ static const uint32_t input[10] = /* "ab-אב-αβ-ω" */
+ { 'a', 'b', '-', 0x05D0, 0x05D1, '-', 0x03B1, 0x03B2, '-', 0x03C9 };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 10; i++)
+ {
+ ASSERT (p[i] == (i == 3 || i == 9 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour before East Asian opening parenthesis (LB30). */
+ {
+ static const uint32_t input[17] = /* "日中韓統合漢字拡張G「ユニコード」" */
+ {
+ 0x65E5, 0x4E2D, 0x97D3, 0x7D71, 0x5408, 0x6F22, 0x5B57, 0x62E1, 0x5F35,
+ 'G', 0x300C, 0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9, 0x300D
+ };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 17; i++)
+ {
+ ASSERT (p[i] == (i == 1 || i == 2 || i == 3 || i == 4 || i == 5
+ || i == 6 || i == 7 || i == 8 || i == 9
+ || i == 10 /* This is the desired break position. */
+ || i == 12 || i == 13 || i == 15 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of potential future emoji (LB30b). */
+ {
+ static const uint32_t input[2] = { 0x1FFFC, 0x1F3FF };
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u32_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 2; i++)
+ {
+ ASSERT (p[i] == UC_BREAK_PROHIBITED);
+ }
+ free (p);
+ }
+}
+
+int
+main ()
+{
+ test_function (u32_possible_linebreaks, 2);
+#undef u32_possible_linebreaks
+ test_function (u32_possible_linebreaks, 1);
+
return 0;
}
diff --git a/tests/unilbrk/test-u32-width-linebreaks.c b/tests/unilbrk/test-u32-width-linebreaks.c
index a058b3e..1543f31 100644
--- a/tests/unilbrk/test-u32-width-linebreaks.c
+++ b/tests/unilbrk/test-u32-width-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-32 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (int (*my_u32_width_linebreaks) (const uint32_t *, size_t, int, int, int, const char *, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u32_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
+ my_u32_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
{
static const uint32_t input[61] =
@@ -45,7 +46,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
+ my_u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
@@ -59,7 +60,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
+ my_u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
for (i = 0; i < 61; i++)
{
ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
@@ -69,6 +70,14 @@ main ()
free (p);
}
}
+}
+
+int
+main ()
+{
+ test_function (u32_width_linebreaks, 2);
+#undef u32_width_linebreaks
+ test_function (u32_width_linebreaks, 1);
return 0;
}
diff --git a/tests/unilbrk/test-u8-possible-linebreaks.c b/tests/unilbrk/test-u8-possible-linebreaks.c
index 7e1b4c5..3640e56 100644
--- a/tests/unilbrk/test-u8-possible-linebreaks.c
+++ b/tests/unilbrk/test-u8-possible-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-8 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (void (*my_u8_possible_linebreaks) (const uint8_t *, size_t, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u8_possible_linebreaks (NULL, 0, "GB18030", NULL);
+ my_u8_possible_linebreaks (NULL, 0, "GB18030", NULL);
{
static const uint8_t input[91] =
@@ -39,13 +40,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u8_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
+ my_u8_possible_linebreaks (input, SIZEOF (input), "GB18030", p);
for (i = 0; i < 91; i++)
{
ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY :
i == 7
|| i == 13 || i == 39
- || i == 43 || i == 44
+ || i == 43
|| i == 61 || i == 67
|| i == 70 || i == 73 || i == 77 || i == 80
|| i == 84 || i == 87 ? UC_BREAK_POSSIBLE :
@@ -58,13 +59,13 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u8_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
+ my_u8_possible_linebreaks (input, SIZEOF (input), "GB2312", p);
for (i = 0; i < 91; i++)
{
ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY :
i == 7
|| i == 13 || i == 39
- || i == 43 || i == 44
+ || i == 43
|| i == 52 || i == 61 || i == 67
|| i == 70 || i == 73 || i == 77 || i == 80
|| i == 84 || i == 87 ? UC_BREAK_POSSIBLE :
@@ -74,6 +75,22 @@ main ()
}
}
+ /* CR LF handling. */
+ {
+ static const uint8_t input[8] = "a\nb\rc\r\nd";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 8; i++)
+ {
+ ASSERT (p[i] == (i == 1 || i == 3 || i == 6 ? UC_BREAK_MANDATORY :
+ i == 5 ? (version < 2 ? UC_BREAK_MANDATORY : UC_BREAK_CR_BEFORE_LF) :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
/* Test that a break is possible after a zero-width space followed by some
regular spaces (rule LB8 in Unicode TR#14 revision 26). */
{
@@ -81,13 +98,148 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
- for (i = 0; i < 4; i++)
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 6; i++)
{
ASSERT (p[i] == (i == 5 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
}
free (p);
}
+ /* Test line breaking in a string with HTML markup. */
+ {
+ static const uint8_t input[21] = "<P>Some sentence.</P>";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 21; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 17 || i == 19 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of combining marks. */
+ {
+ static const uint8_t input[24] =
+ "a\314\200\314\201e\314\200 \314\201o \314\200 o\302\240\314\200\n"
+ "\314\200";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 24; i++)
+ {
+ ASSERT (p[i] == (i == 21 ? UC_BREAK_MANDATORY :
+ i == 9 || i == 13 || i == 16 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of zero-width joiners (U+200D). */
+ {
+ static const uint8_t input[101] =
+ "\346\234\211\347\204\241\347\252\256\345\244\232\345\200\213\347\264\240\346\225\270\343\200\202\n" /* "有無窮多個素數。" */
+ "\346\234\211\342\200\215\347\204\241\342\200\215\347\252\256\345\244\232\345\200\213\347\264\240\342\200\215\346\225\270\343\200\202\n"
+ "\344\275\240\342\200\224\344\270\215\n" /* "你—不" */
+ "\344\275\240\342\200\224\342\200\215\344\270\215\n"
+ "\342\230\235\360\237\217\277\n" /* "☝🏿" */
+ "\342\230\235\342\200\215\360\237\217\277\n";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 101; i++)
+ {
+ ASSERT (p[i] == (i == 24 || i == 58
+ || i == 68 || i == 81
+ || i == 89 || i == 100 ? UC_BREAK_MANDATORY :
+ i == 3 || i == 6 || i == 9 || i == 12 || i == 15 || i == 18
+ || i == 40 || i == 43 || i == 46
+ || i == 62 || i == 65
+ || i == 72 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test line breaking of regional indicators. */
+ {
+ static const uint8_t input[16] =
+ "\360\237\207\251\360\237\207\252\360\237\207\253\360\237\207\267";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 16; i++)
+ {
+ ASSERT (p[i] == (i == 8 ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of hyphen/break-after character after
+ Hebrew letter. */
+ {
+ static const uint8_t input[15] = /* "ab-אב-αβ-ω" */
+ "ab-\327\220\327\221-\316\261\316\262-\317\211";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 15; i++)
+ {
+ ASSERT (p[i] == (i == 3 || i == 13 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour before East Asian opening parenthesis (LB30). */
+ {
+ static const uint8_t input[49] = /* "日中韓統合漢字拡張G「ユニコード」" */
+ "\346\227\245\344\270\255\351\237\223\347\265\261\345\220\210\346\274\242"
+ "\345\255\227\346\213\241\345\274\265G\343\200\214\343\203\246"
+ "\343\203\213\343\202\263\343\203\274\343\203\211\343\200\215";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 49; i++)
+ {
+ ASSERT (p[i] == (i == 3 || i == 6 || i == 9 || i == 12 || i == 15
+ || i == 18 || i == 21 || i == 24 || i == 27
+ || i == 28 /* This is the desired break position. */
+ || i == 34 || i == 37 || i == 43 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
+
+ /* Test special behaviour of potential future emoji (LB30b). */
+ {
+ static const uint8_t input[8] = "\360\237\277\274\360\237\217\277";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_u8_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 8; i++)
+ {
+ ASSERT (p[i] == UC_BREAK_PROHIBITED);
+ }
+ free (p);
+ }
+}
+
+int
+main ()
+{
+ test_function (u8_possible_linebreaks, 2);
+#undef u8_possible_linebreaks
+ test_function (u8_possible_linebreaks, 1);
+
return 0;
}
diff --git a/tests/unilbrk/test-u8-width-linebreaks.c b/tests/unilbrk/test-u8-width-linebreaks.c
index 8defc0e..4fb9743 100644
--- a/tests/unilbrk/test-u8-width-linebreaks.c
+++ b/tests/unilbrk/test-u8-width-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of UTF-8 strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (int (*my_u8_width_linebreaks) (const uint8_t *, size_t, int, int, int, const char *, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- u8_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
+ my_u8_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
{
static const uint8_t input[91] =
@@ -39,7 +40,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
+ my_u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
for (i = 0; i < 91; i++)
{
ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY :
@@ -53,7 +54,7 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
+ my_u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
for (i = 0; i < 91; i++)
{
ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY :
@@ -63,6 +64,14 @@ main ()
free (p);
}
}
+}
+
+int
+main ()
+{
+ test_function (u8_width_linebreaks, 2);
+#undef u8_width_linebreaks
+ test_function (u8_width_linebreaks, 1);
return 0;
}
diff --git a/tests/unilbrk/test-ulc-possible-linebreaks.c b/tests/unilbrk/test-ulc-possible-linebreaks.c
index 5ff9133..5e4381e 100644
--- a/tests/unilbrk/test-ulc-possible-linebreaks.c
+++ b/tests/unilbrk/test-ulc-possible-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (void (*my_ulc_possible_linebreaks) (const char *, size_t, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- ulc_possible_linebreaks (NULL, 0, "GB18030", NULL);
+ my_ulc_possible_linebreaks (NULL, 0, "GB18030", NULL);
#if HAVE_ICONV
{
@@ -38,17 +39,40 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- ulc_possible_linebreaks (input, SIZEOF (input), "ISO-8859-1", p);
+ my_ulc_possible_linebreaks (input, SIZEOF (input), "ISO-8859-1", p);
for (i = 0; i < 36; i++)
{
ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY :
- i == 5 || i == 11 || i == 15 || i == 16
+ i == 5 || i == 11 || i == 15
|| i == 31 ? UC_BREAK_POSSIBLE :
UC_BREAK_PROHIBITED));
}
free (p);
}
+
+ /* Test line breaking in a string with HTML markup. */
+ {
+ static const char input[21] = "<P>Some sentence.</P>";
+ char *p = (char *) malloc (SIZEOF (input));
+ size_t i;
+
+ my_ulc_possible_linebreaks (input, SIZEOF (input), "UTF-8", p);
+ for (i = 0; i < 21; i++)
+ {
+ ASSERT (p[i] == (i == 8 || i == 17 || i == 19 ? UC_BREAK_POSSIBLE :
+ UC_BREAK_PROHIBITED));
+ }
+ free (p);
+ }
#endif
+}
+
+int
+main ()
+{
+ test_function (ulc_possible_linebreaks, 2);
+#undef ulc_possible_linebreaks
+ test_function (ulc_possible_linebreaks, 1);
return 0;
}
diff --git a/tests/unilbrk/test-ulc-width-linebreaks.c b/tests/unilbrk/test-ulc-width-linebreaks.c
index c1d3398..ed4909b 100644
--- a/tests/unilbrk/test-ulc-width-linebreaks.c
+++ b/tests/unilbrk/test-ulc-width-linebreaks.c
@@ -1,5 +1,5 @@
/* Test of line breaking of strings.
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,12 @@
#include "macros.h"
-int
-main ()
+static void
+test_function (int (*my_ulc_width_linebreaks) (const char *, size_t, int, int, int, const char *, const char *, char *_UC_RESTRICT),
+ int version)
{
/* Test case n = 0. */
- ulc_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
+ my_ulc_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
#if HAVE_ICONV
{
@@ -38,16 +39,24 @@ main ()
char *p = (char *) malloc (SIZEOF (input));
size_t i;
- ulc_width_linebreaks (input, SIZEOF (input), 12, 0, 0, NULL, "ISO-8859-1", p);
+ my_ulc_width_linebreaks (input, SIZEOF (input), 12, 0, 0, NULL, "ISO-8859-1", p);
for (i = 0; i < 36; i++)
{
ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY :
- i == 11 || i == 16 || i == 31 ? UC_BREAK_POSSIBLE :
+ i == 11 || i == 15 || i == 31 ? UC_BREAK_POSSIBLE :
UC_BREAK_PROHIBITED));
}
free (p);
}
#endif
+}
+
+int
+main ()
+{
+ test_function (ulc_width_linebreaks, 2);
+#undef ulc_width_linebreaks
+ test_function (ulc_width_linebreaks, 1);
return 0;
}