[pango] test-break: Skip initial comment in test files



commit a2c568c29da228be3f1ce47e0c86c1c9ecdbb162
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 7 21:17:53 2019 -0400

    test-break: Skip initial comment in test files
    
    This is useful for documenting tests.

 tests/test-break.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/tests/test-break.c b/tests/test-break.c
index acbe9014..f9b8d94e 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -47,6 +47,7 @@ test_file (const gchar *filename, GString *string)
   int i;
   GString *s1, *s2, *s3, *s4;
   int m;
+  char *test;
 
   if (!g_file_get_contents (filename, &contents, &length, &error))
     {
@@ -55,12 +56,19 @@ test_file (const gchar *filename, GString *string)
       return;
     }
 
-  len = g_utf8_strlen (contents, -1) + 1;
+  test = contents;
+
+  /* Skip initial comments */
+  while (test[0] == '#')
+    test = strchr (test, '\n') + 1;
+
+  length = strlen (test);
+  len = g_utf8_strlen (test, -1) + 1;
   attrs = g_new (PangoLogAttr, len);
 
   lang = pango_language_from_string ("en");
 
-  pango_get_log_attrs (contents, length, -1, lang, attrs, len);
+  pango_get_log_attrs (test, length, -1, lang, attrs, len);
 
   s1 = g_string_new ("Breaks: ");
   s2 = g_string_new ("Whitespace: ");
@@ -77,7 +85,7 @@ test_file (const gchar *filename, GString *string)
   g_string_append_printf (s4, "%*s", (int)(m - s4->len), "");
   g_string_append_printf (string, "%*s", (int)(m - strlen ("Text: ")), "");
 
-  for (i = 0, p = contents; i < len; i++, p = g_utf8_next_char (p))
+  for (i = 0, p = test; i < len; i++, p = g_utf8_next_char (p))
     {
       PangoLogAttr log = attrs[i];
       int b = 0;
@@ -179,7 +187,7 @@ test_file (const gchar *filename, GString *string)
           else
             {
               char *str = g_strdup_printf ("[%#04x]", ch);
-              g_string_append (string, str); 
+              g_string_append (string, str);
               g_string_append_printf (s1, "%*s", (int)strlen (str), "");
               g_string_append_printf (s2, "%*s", (int)strlen (str), "");
               g_string_append_printf (s3, "%*s", (int)strlen (str), "");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]