[pango/log-attr-tweaks: 20/23] tests: Validate log attrs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/log-attr-tweaks: 20/23] tests: Validate log attrs
- Date: Sun, 22 Aug 2021 06:51:40 +0000 (UTC)
commit 056ad7546e0c6b097a359d53fdf7f9955f81a7c2
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 21 18:39:09 2021 -0400
tests: Validate log attrs
Now that we have api to do it, we should validate
our log attrs in test-break.
pango/break.c | 58 +++++++++++++++++++++++++++++++++++++-----------------
tests/test-break.c | 1 +
2 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index 50bca699..01257f87 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -1917,19 +1917,19 @@ check_line_char (int pos,
static gboolean
check_line_invariants (const char *text,
int length,
- const PangoLogAttr *log_attrs,
+ const PangoLogAttr *attrs,
int attrs_len,
GError **error)
{
return log_attr_foreach (text, length,
- log_attrs, attrs_len,
+ attrs, attrs_len,
check_line_char, error);
}
static gboolean
check_grapheme_invariants (const char *text,
int length,
- const PangoLogAttr *log_attrs,
+ const PangoLogAttr *attrs,
int attrs_len,
GError **error)
{
@@ -1939,7 +1939,7 @@ check_grapheme_invariants (const char *text,
static gboolean
check_word_invariants (const char *text,
int length,
- const PangoLogAttr *log_attrs,
+ const PangoLogAttr *attrs,
int attrs_len,
GError **error)
{
@@ -1950,18 +1950,19 @@ check_word_invariants (const char *text,
for (int i = 0; i < attrs_len; i++)
{
+ /* Check that word starts and ends are alternating */
switch (state)
{
case AFTER_END:
- if (log_attrs[i].is_word_start)
+ if (attrs[i].is_word_start)
{
- if (log_attrs[i].is_word_end)
+ if (attrs[i].is_word_end)
state = AFTER_END;
else
state = AFTER_START;
break;
}
- if (log_attrs[i].is_word_end)
+ if (attrs[i].is_word_end)
{
g_set_error (error,
PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_WORD,
@@ -1971,15 +1972,15 @@ check_word_invariants (const char *text,
break;
case AFTER_START:
- if (log_attrs[i].is_word_end)
+ if (attrs[i].is_word_end)
{
- if (log_attrs[i].is_word_start)
+ if (attrs[i].is_word_start)
state = AFTER_START;
else
state = AFTER_END;
break;
}
- if (log_attrs[i].is_word_start)
+ if (attrs[i].is_word_start)
{
g_set_error (error,
PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_WORD,
@@ -1991,6 +1992,15 @@ check_word_invariants (const char *text,
default:
g_assert_not_reached ();
}
+
+ /* Check that words don't end in the middle of graphemes */
+ if (attrs[i].is_word_boundary && !attrs[i].is_cursor_position)
+ {
+ g_set_error (error,
+ PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_SENTENCE,
+ "char %d: Word ends inside a grapheme", i);
+ return FALSE;
+ }
}
return TRUE;
@@ -1999,7 +2009,7 @@ check_word_invariants (const char *text,
static gboolean
check_sentence_invariants (const char *text,
int length,
- const PangoLogAttr *log_attrs,
+ const PangoLogAttr *attrs,
int attrs_len,
GError **error)
{
@@ -2010,18 +2020,19 @@ check_sentence_invariants (const char *text,
for (int i = 0; i < attrs_len; i++)
{
+ /* Check that word starts and ends are alternating */
switch (state)
{
case AFTER_END:
- if (log_attrs[i].is_sentence_start)
+ if (attrs[i].is_sentence_start)
{
- if (log_attrs[i].is_sentence_end)
+ if (attrs[i].is_sentence_end)
state = AFTER_END;
else
state = AFTER_START;
break;
}
- if (log_attrs[i].is_sentence_end)
+ if (attrs[i].is_sentence_end)
{
g_set_error (error,
PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_SENTENCE,
@@ -2031,15 +2042,15 @@ check_sentence_invariants (const char *text,
break;
case AFTER_START:
- if (log_attrs[i].is_sentence_end)
+ if (attrs[i].is_sentence_end)
{
- if (log_attrs[i].is_sentence_start)
+ if (attrs[i].is_sentence_start)
state = AFTER_START;
else
state = AFTER_END;
break;
}
- if (log_attrs[i].is_sentence_start)
+ if (attrs[i].is_sentence_start)
{
g_set_error (error,
PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_SENTENCE,
@@ -2051,6 +2062,15 @@ check_sentence_invariants (const char *text,
default:
g_assert_not_reached ();
}
+
+ /* Check that sentences don't end in the middle of words */
+ if (attrs[i].is_sentence_boundary && !attrs[i].is_word_boundary)
+ {
+ g_set_error (error,
+ PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_SENTENCE,
+ "char %d: Sentence ends inside a word", i);
+ return FALSE;
+ }
}
return TRUE;
@@ -2255,6 +2275,8 @@ pango_get_log_attrs (const char *text,
* - Word starts and ends alternate
* - Sentence starts and ends alternate
* - Expandable spaces are spaces
+ * - Words don't end in the middle of graphemes
+ * - Sentences don't end in the middle of words
*
* Returns: %TRUE if @log_attrs are valid
*
@@ -2296,6 +2318,6 @@ pango_validate_log_attrs (const char *text,
return TRUE;
}
-/* }}} */
+ /* }}} */
/* vim:set foldmethod=marker expandtab: */
diff --git a/tests/test-break.c b/tests/test-break.c
index 3fb5cdcd..beef9f63 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -95,6 +95,7 @@ test_file (const gchar *filename, GString *string)
g_assert_cmpint (len, ==, len2);
g_assert_true (memcmp (attrs, attrs2, sizeof (PangoLogAttr) * len) == 0);
+ g_assert_true (pango_validate_log_attrs (text, length, attrs, len, NULL));
layout2 = pango_layout_copy (layout);
attrs2 = pango_layout_get_log_attrs_readonly (layout2, &len2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]