Patchwork [3/4] time: Add tests for Minguo calendar [BZ #24293]

login
register
mail settings
Submitter TAMUKI Shoichi
Date April 1, 2019, 3:59 a.m.
Message ID <201904010359.AA04318@tamuki.linet.gr.jp>
Download mbox | patch
Permalink /patch/32112/
State New
Headers show

Comments

TAMUKI Shoichi - April 1, 2019, 3:59 a.m.
The original author: Rafal Luzynski <digitalfreak@lingonborough.com>

ChangeLog:

	[BZ #24293]
	* time/Makefile (LOCALES): Add zh_TW.UTF-8, cmn_TW.UTF-8,
	hak_TW.UTF-8, nan_TW.UTF-8, and lzh_TW.UTF-8.
	* time/tst-strftime2.c (locales): Likewise.
	(dates): Add 1910-04-01, 1911-12-31, 1912-01-01, 1913-04-01,
	2010-04-01, and 2011-04-01.
	(mkreftable): Add rules for the new locales and the new dates.
---
 time/Makefile        |  4 +++-
 time/tst-strftime2.c | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 7 deletions(-)
Carlos O'Donell - April 1, 2019, 8:34 p.m.
On 3/31/19 11:59 PM, TAMUKI Shoichi wrote:

OK for master if you:
- Use Co-authored-by in git commit message.
- Add Rafal's name as a secondary author in Changelog.


Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> The original author: Rafal Luzynski <digitalfreak@lingonborough.com>
> 
> ChangeLog:
> 
> 	[BZ #24293]
> 	* time/Makefile (LOCALES): Add zh_TW.UTF-8, cmn_TW.UTF-8,
> 	hak_TW.UTF-8, nan_TW.UTF-8, and lzh_TW.UTF-8.
> 	* time/tst-strftime2.c (locales): Likewise.
> 	(dates): Add 1910-04-01, 1911-12-31, 1912-01-01, 1913-04-01,
> 	2010-04-01, and 2011-04-01.
> 	(mkreftable): Add rules for the new locales and the new dates.
> ---
>   time/Makefile        |  4 +++-
>   time/tst-strftime2.c | 37 +++++++++++++++++++++++++++++++------
>   2 files changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/time/Makefile b/time/Makefile
> index 5c6304ece1..e722a8f631 100644
> --- a/time/Makefile
> +++ b/time/Makefile
> @@ -50,7 +50,9 @@ include ../Rules
>   ifeq ($(run-built-tests),yes)
>   LOCALES := de_DE.ISO-8859-1 en_US.ISO-8859-1 ja_JP.EUC-JP fr_FR.UTF-8 \
>   	   es_ES.UTF-8 pl_PL.UTF-8 ru_RU.UTF-8 \
> -	   ja_JP.UTF-8 lo_LA.UTF-8 th_TH.UTF-8
> +	   ja_JP.UTF-8 lo_LA.UTF-8 th_TH.UTF-8 \
> +	   zh_TW.UTF-8 cmn_TW.UTF-8 hak_TW.UTF-8 \
> +	   nan_TW.UTF-8 lzh_TW.UTF-8

OK. Add new required locales.

>   include ../gen-locales.mk
>   
>   $(objpfx)tst-ftime_l.out: $(gen-locales)
> diff --git a/time/tst-strftime2.c b/time/tst-strftime2.c
> index f537d93ba4..2c94bf592e 100644
> --- a/time/tst-strftime2.c
> +++ b/time/tst-strftime2.c
> @@ -29,7 +29,9 @@
>   
>   static const char *locales[] =
>   {
> -  "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8"
> +  "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8",
> +  "zh_TW.UTF-8", "cmn_TW.UTF-8", "hak_TW.UTF-8",
> +  "nan_TW.UTF-8", "lzh_TW.UTF-8"


OK.

Add enum and use below, this prevents constant and comment
getting out of sync.

>   };
>   
>   static const char *formats[] = { "%EY", "%_EY", "%-EY" };
> @@ -41,12 +43,18 @@ typedef struct
>   
>   static const date_t dates[] =
>   {
> +  {  1,  4, 1910 },
> +  { 31, 12, 1911 },
> +  {  1,  1, 1912 },
> +  {  1,  4, 1913 },

OK. This is going to add more dates for ja_JP to handle too.

>     {  1,  4, 1988 },
>     {  7,  1, 1989 },
>     {  8,  1, 1989 },
>     {  1,  4, 1990 },
>     {  1,  4, 1997 },
> -  {  1,  4, 1998 }
> +  {  1,  4, 1998 },
> +  {  1,  4, 2010 },
> +  {  1,  4, 2011 }

OK.

>   };
>   
>   static char ref[array_length (locales)][array_length (formats)]
> @@ -75,12 +83,21 @@ mkreftable (void)
>     /* Japanese era year to be checked.  */
>     static const int yrj[] =
>     {
> -    63, 64, 1, 2, 9, 10
> +    43, 44, 45, 2,
> +    63, 64, 1, 2, 9, 10, 22, 23

OK.

>     };
>     /* Buddhist calendar year to be checked.  */
>     static const int yrb[] =
>     {
> -    2531, 2532, 2532, 2533, 2540, 2541
> +    2453, 2454, 2455, 2456,
> +    2531, 2532, 2532, 2533, 2540, 2541, 2553, 2554

OK.

> +  };
> +  /* R.O.C. calendar year to be checked.  Negative number is prior to
> +     Minguo counting up.  */
> +  static const int yrc[] =
> +  {
> +    -2, -1, 1, 2,
> +    77, 78, 78, 79, 86, 87, 99, 100

OK.

>     };
>   
>     for (i = 0; i < array_length (locales); i++)
> @@ -89,14 +106,22 @@ mkreftable (void)
>   	{
>   	  if (i == 0)  /* ja_JP  */
>   	    {
> -	      era = (is_before (k, 8, 1, 1989)) ? "\u662d\u548c"
> -						: "\u5e73\u6210";
> +	      era = (is_before (k, 30,  7, 1912)) ? "\u660e\u6cbb"

OK. verified.

> +		  : (is_before (k, 25, 12, 1926)) ? "\u5927\u6b63"

OK. verified.

> +		  : (is_before (k,  8,  1, 1989)) ? "\u662d\u548c"

OK. verified.

> +						  : "\u5e73\u6210";

OK. verified.

>   	      yr = yrj[k], sfx = "\u5e74";
>   	    }
>   	  else if (i == 1)  /* lo_LA  */
>   	    era = "\u0e9e.\u0eaa. ", yr = yrb[k], sfx = "";
>   	  else if (i == 2)  /* th_TH  */
>   	    era = "\u0e1e.\u0e28. ", yr = yrb[k], sfx = "";
> +	  else if (i >= 3 && i <= 7)  /* {zh,cmn,hak,nan,lzh}_TW  */

else if (i == zh_TW
          || i == cmn_TW
          || i == hak_TW
          || i == nan_TW
          || i == lzh_TW)

Tests can afford to be clear.

> +	    {
> +	      era = (is_before (k, 1, 1, 1912)) ? "\u6c11\u524d"
> +						: "\u6c11\u570b";
> +	      yr = yrc[k], sfx = "\u5e74";

OK. Verified ROC beings 1912, and 2019 == 108.

> +	    }
>   	  else
>   	    assert (0);  /* Unreachable.  */
>   	  if (yr == 1)
>

Patch

diff --git a/time/Makefile b/time/Makefile
index 5c6304ece1..e722a8f631 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -50,7 +50,9 @@  include ../Rules
 ifeq ($(run-built-tests),yes)
 LOCALES := de_DE.ISO-8859-1 en_US.ISO-8859-1 ja_JP.EUC-JP fr_FR.UTF-8 \
 	   es_ES.UTF-8 pl_PL.UTF-8 ru_RU.UTF-8 \
-	   ja_JP.UTF-8 lo_LA.UTF-8 th_TH.UTF-8
+	   ja_JP.UTF-8 lo_LA.UTF-8 th_TH.UTF-8 \
+	   zh_TW.UTF-8 cmn_TW.UTF-8 hak_TW.UTF-8 \
+	   nan_TW.UTF-8 lzh_TW.UTF-8
 include ../gen-locales.mk
 
 $(objpfx)tst-ftime_l.out: $(gen-locales)
diff --git a/time/tst-strftime2.c b/time/tst-strftime2.c
index f537d93ba4..2c94bf592e 100644
--- a/time/tst-strftime2.c
+++ b/time/tst-strftime2.c
@@ -29,7 +29,9 @@ 
 
 static const char *locales[] =
 {
-  "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8"
+  "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8",
+  "zh_TW.UTF-8", "cmn_TW.UTF-8", "hak_TW.UTF-8",
+  "nan_TW.UTF-8", "lzh_TW.UTF-8"
 };
 
 static const char *formats[] = { "%EY", "%_EY", "%-EY" };
@@ -41,12 +43,18 @@  typedef struct
 
 static const date_t dates[] =
 {
+  {  1,  4, 1910 },
+  { 31, 12, 1911 },
+  {  1,  1, 1912 },
+  {  1,  4, 1913 },
   {  1,  4, 1988 },
   {  7,  1, 1989 },
   {  8,  1, 1989 },
   {  1,  4, 1990 },
   {  1,  4, 1997 },
-  {  1,  4, 1998 }
+  {  1,  4, 1998 },
+  {  1,  4, 2010 },
+  {  1,  4, 2011 }
 };
 
 static char ref[array_length (locales)][array_length (formats)]
@@ -75,12 +83,21 @@  mkreftable (void)
   /* Japanese era year to be checked.  */
   static const int yrj[] =
   {
-    63, 64, 1, 2, 9, 10
+    43, 44, 45, 2,
+    63, 64, 1, 2, 9, 10, 22, 23
   };
   /* Buddhist calendar year to be checked.  */
   static const int yrb[] =
   {
-    2531, 2532, 2532, 2533, 2540, 2541
+    2453, 2454, 2455, 2456,
+    2531, 2532, 2532, 2533, 2540, 2541, 2553, 2554
+  };
+  /* R.O.C. calendar year to be checked.  Negative number is prior to
+     Minguo counting up.  */
+  static const int yrc[] =
+  {
+    -2, -1, 1, 2,
+    77, 78, 78, 79, 86, 87, 99, 100
   };
 
   for (i = 0; i < array_length (locales); i++)
@@ -89,14 +106,22 @@  mkreftable (void)
 	{
 	  if (i == 0)  /* ja_JP  */
 	    {
-	      era = (is_before (k, 8, 1, 1989)) ? "\u662d\u548c"
-						: "\u5e73\u6210";
+	      era = (is_before (k, 30,  7, 1912)) ? "\u660e\u6cbb"
+		  : (is_before (k, 25, 12, 1926)) ? "\u5927\u6b63"
+		  : (is_before (k,  8,  1, 1989)) ? "\u662d\u548c"
+						  : "\u5e73\u6210";
 	      yr = yrj[k], sfx = "\u5e74";
 	    }
 	  else if (i == 1)  /* lo_LA  */
 	    era = "\u0e9e.\u0eaa. ", yr = yrb[k], sfx = "";
 	  else if (i == 2)  /* th_TH  */
 	    era = "\u0e1e.\u0e28. ", yr = yrb[k], sfx = "";
+	  else if (i >= 3 && i <= 7)  /* {zh,cmn,hak,nan,lzh}_TW  */
+	    {
+	      era = (is_before (k, 1, 1, 1912)) ? "\u6c11\u524d"
+						: "\u6c11\u570b";
+	      yr = yrc[k], sfx = "\u5e74";
+	    }
 	  else
 	    assert (0);  /* Unreachable.  */
 	  if (yr == 1)