diff options
author | Pádraig Brady <P@draigBrady.com> | 2012-09-04 13:12:23 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-09-11 03:23:42 +0100 |
commit | 6cf9c59b1635906f3595fc43dcd36dc4433fd7aa (patch) | |
tree | b2a419c97f592646046443bae73191edd5ce3c86 /gl/tests | |
parent | 4fdd1cc597209b9e85ed66fdb594abca6f148155 (diff) | |
download | coreutils-6cf9c59b1635906f3595fc43dcd36dc4433fd7aa.tar.xz |
maint: add more control flags to mbsalign
* gl/lib/mbsalign.h: Add MBA_UNIBYTE_ONLY (to allow
faster processing). Also add MBA_NO_LEFT_PAD, MBA_NO_RIGHT_PAD
to give greater control of padding, useful with the first
or last fields on a line.
* gl/lib/mbsalign.c (mbsalign): Implement the new flags.
* gl/tests/test-mbsalign.c (main): Test combinations
of the new flags.
Diffstat (limited to 'gl/tests')
-rw-r--r-- | gl/tests/test-mbsalign.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gl/tests/test-mbsalign.c b/gl/tests/test-mbsalign.c index 86aa87739..11e9dee0e 100644 --- a/gl/tests/test-mbsalign.c +++ b/gl/tests/test-mbsalign.c @@ -38,6 +38,35 @@ main (void) width = 4; n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER, 0); ASSERT (*dest == ' ' && *(dest + n - 1) == ' '); + ASSERT (n == 4); + + /* Test center alignment, with no trailing padding. */ + width = 4; + n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER, + MBA_NO_RIGHT_PAD); + ASSERT (n == 3); + ASSERT (*dest == ' ' && *(dest + n - 1) == 's'); + + /* Test left alignment, with no trailing padding. (truncate only). */ + width = 4; + n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_LEFT, + MBA_NO_RIGHT_PAD); + ASSERT (n == 2); + ASSERT (*dest == 'e' && *(dest + n - 1) == 's'); + + /* Test center alignment, with no padding. (truncate only). */ + width = 4; + n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER, + MBA_NO_LEFT_PAD | MBA_NO_RIGHT_PAD); + ASSERT (n == 2); + ASSERT (*dest == 'e' && *(dest + n - 1) == 's'); + + /* Test center alignment, with no left padding. (may be useful for RTL?) */ + width = 4; + n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER, + MBA_NO_LEFT_PAD); + ASSERT (n == 3); + ASSERT (*dest == 'e' && *(dest + n - 1) == ' '); if (setlocale (LC_ALL, "en_US.UTF8")) { @@ -55,16 +84,19 @@ main (void) /* Test multibyte center alignment. */ width = 4; n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_CENTER, 0); + ASSERT (n == 5); ASSERT (*dest == ' ' && *(dest + n - 1) == ' '); /* Test multibyte left alignment. */ width = 4; n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0); + ASSERT (n == 5); ASSERT (*(dest + n - 1) == ' ' && *(dest + n - 2) == ' '); /* Test multibyte right alignment. */ width = 4; n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_RIGHT, 0); + ASSERT (n == 5); ASSERT (*(dest) == ' ' && *(dest + 1) == ' '); /* multibyte multicell truncation. */ @@ -94,6 +126,12 @@ main (void) n = mbsalign ("t\tés" /* 6 including NUL */ , dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0); ASSERT (n == 7); + + /* Test forced unibyte truncation. */ + width = 4; + n = mbsalign ("t\tés", dest, sizeof dest, &width, MBS_ALIGN_LEFT, + MBA_UNIBYTE_ONLY); + ASSERT (n == 4); } return 0; |