Tests for module unilbrk/u16-width-linebreaks.
[gnulib.git] / tests / test-vasnprintf-posix.c
index 84da8b2..895c807 100644 (file)
@@ -1189,6 +1189,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2f %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2f %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000.00 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   { /* A positive number.  */
     size_t length;
     char *result =
@@ -1569,6 +1589,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2Lf %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2Lf %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000.00 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   /* Test the support of the %F format directive.  */
 
   { /* A positive number.  */
@@ -1687,6 +1727,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2F %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2F %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000.00 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   { /* A positive number.  */
     size_t length;
     char *result =
@@ -1803,6 +1863,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2LF %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.2LF %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000.00 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   /* Test the support of the %e format directive.  */
 
   { /* A positive number.  */
@@ -2116,6 +2196,28 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.4e %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "9.9995e+02 33") == 0
+           || strcmp (result, "9.9995e+002 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.4e %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1.0000e+03 33") == 0
+           || strcmp (result, "1.0000e+003 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   { /* A positive number.  */
     size_t length;
     char *result =
@@ -2506,6 +2608,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.4Le %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "9.9995e+02 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.4Le %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1.0000e+03 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   /* Test the support of the %g format directive.  */
 
   { /* A positive number.  */
@@ -2809,6 +2931,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.5g %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.5g %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   { /* A positive number.  */
     size_t length;
     char *result =
@@ -3199,6 +3341,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     free (result);
   }
 
+  { /* Precision with no rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.5Lg %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "999.95 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%.5Lg %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "1000 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
   /* Test the support of the %n format directive.  */
 
   {