...

Source file src/github.com/go-playground/locales/ja/ja_test.go

Documentation: github.com/go-playground/locales/ja

     1  package ja
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/go-playground/locales"
     8  	"github.com/go-playground/locales/currency"
     9  )
    10  
    11  func TestLocale(t *testing.T) {
    12  
    13  	trans := New()
    14  	expected := "ja"
    15  
    16  	if trans.Locale() != expected {
    17  		t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
    18  	}
    19  }
    20  
    21  func TestPluralsRange(t *testing.T) {
    22  
    23  	trans := New()
    24  
    25  	tests := []struct {
    26  		expected locales.PluralRule
    27  	}{
    28  		{
    29  			expected: locales.PluralRuleOther,
    30  		},
    31  	}
    32  
    33  	rules := trans.PluralsRange()
    34  	expected := 1
    35  	if len(rules) != expected {
    36  		t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
    37  	}
    38  
    39  	for _, tt := range tests {
    40  
    41  		r := locales.PluralRuleUnknown
    42  
    43  		for i := 0; i < len(rules); i++ {
    44  			if rules[i] == tt.expected {
    45  				r = rules[i]
    46  				break
    47  			}
    48  		}
    49  		if r == locales.PluralRuleUnknown {
    50  			t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
    51  		}
    52  	}
    53  }
    54  
    55  func TestPluralsOrdinal(t *testing.T) {
    56  
    57  	trans := New()
    58  
    59  	tests := []struct {
    60  		expected locales.PluralRule
    61  	}{
    62  		{
    63  			expected: locales.PluralRuleOther,
    64  		},
    65  	}
    66  
    67  	rules := trans.PluralsOrdinal()
    68  	expected := 1
    69  	if len(rules) != expected {
    70  		t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
    71  	}
    72  
    73  	for _, tt := range tests {
    74  
    75  		r := locales.PluralRuleUnknown
    76  
    77  		for i := 0; i < len(rules); i++ {
    78  			if rules[i] == tt.expected {
    79  				r = rules[i]
    80  				break
    81  			}
    82  		}
    83  		if r == locales.PluralRuleUnknown {
    84  			t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
    85  		}
    86  	}
    87  }
    88  
    89  func TestPluralsCardinal(t *testing.T) {
    90  
    91  	trans := New()
    92  
    93  	tests := []struct {
    94  		expected locales.PluralRule
    95  	}{
    96  		{
    97  			expected: locales.PluralRuleOther,
    98  		},
    99  	}
   100  
   101  	rules := trans.PluralsCardinal()
   102  	expected := 1
   103  	if len(rules) != expected {
   104  		t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
   105  	}
   106  
   107  	for _, tt := range tests {
   108  
   109  		r := locales.PluralRuleUnknown
   110  
   111  		for i := 0; i < len(rules); i++ {
   112  			if rules[i] == tt.expected {
   113  				r = rules[i]
   114  				break
   115  			}
   116  		}
   117  		if r == locales.PluralRuleUnknown {
   118  			t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
   119  		}
   120  	}
   121  }
   122  
   123  func TestRangePlurals(t *testing.T) {
   124  
   125  	trans := New()
   126  
   127  	tests := []struct {
   128  		num1     float64
   129  		v1       uint64
   130  		num2     float64
   131  		v2       uint64
   132  		expected locales.PluralRule
   133  	}{
   134  		{
   135  			num1:     1,
   136  			v1:       1,
   137  			num2:     2,
   138  			v2:       2,
   139  			expected: locales.PluralRuleOther,
   140  		},
   141  	}
   142  
   143  	for _, tt := range tests {
   144  		rule := trans.RangePluralRule(tt.num1, tt.v1, tt.num2, tt.v2)
   145  		if rule != tt.expected {
   146  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   147  		}
   148  	}
   149  }
   150  
   151  func TestOrdinalPlurals(t *testing.T) {
   152  
   153  	trans := New()
   154  
   155  	tests := []struct {
   156  		num      float64
   157  		v        uint64
   158  		expected locales.PluralRule
   159  	}{
   160  		{
   161  			num:      1,
   162  			v:        0,
   163  			expected: locales.PluralRuleOther,
   164  		},
   165  	}
   166  
   167  	for _, tt := range tests {
   168  		rule := trans.OrdinalPluralRule(tt.num, tt.v)
   169  		if rule != tt.expected {
   170  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   171  		}
   172  	}
   173  }
   174  
   175  func TestCardinalPlurals(t *testing.T) {
   176  
   177  	trans := New()
   178  
   179  	tests := []struct {
   180  		num      float64
   181  		v        uint64
   182  		expected locales.PluralRule
   183  	}{
   184  		{
   185  			num:      1,
   186  			v:        0,
   187  			expected: locales.PluralRuleOther,
   188  		},
   189  	}
   190  
   191  	for _, tt := range tests {
   192  		rule := trans.CardinalPluralRule(tt.num, tt.v)
   193  		if rule != tt.expected {
   194  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   195  		}
   196  	}
   197  }
   198  
   199  func TestDaysAbbreviated(t *testing.T) {
   200  
   201  	trans := New()
   202  	days := trans.WeekdaysAbbreviated()
   203  
   204  	for i, day := range days {
   205  		s := trans.WeekdayAbbreviated(time.Weekday(i))
   206  		if s != day {
   207  			t.Errorf("Expected '%s' Got '%s'", day, s)
   208  		}
   209  	}
   210  
   211  	tests := []struct {
   212  		idx      int
   213  		expected string
   214  	}{
   215  		{
   216  			idx:      0,
   217  			expected: "日",
   218  		},
   219  		{
   220  			idx:      1,
   221  			expected: "月",
   222  		},
   223  		{
   224  			idx:      2,
   225  			expected: "火",
   226  		},
   227  		{
   228  			idx:      3,
   229  			expected: "水",
   230  		},
   231  		{
   232  			idx:      4,
   233  			expected: "木",
   234  		},
   235  		{
   236  			idx:      5,
   237  			expected: "金",
   238  		},
   239  		{
   240  			idx:      6,
   241  			expected: "土",
   242  		},
   243  	}
   244  
   245  	for _, tt := range tests {
   246  		s := trans.WeekdayAbbreviated(time.Weekday(tt.idx))
   247  		if s != tt.expected {
   248  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   249  		}
   250  	}
   251  }
   252  
   253  func TestDaysNarrow(t *testing.T) {
   254  
   255  	trans := New()
   256  	days := trans.WeekdaysNarrow()
   257  
   258  	for i, day := range days {
   259  		s := trans.WeekdayNarrow(time.Weekday(i))
   260  		if s != day {
   261  			t.Errorf("Expected '%s' Got '%s'", string(day), s)
   262  		}
   263  	}
   264  
   265  	tests := []struct {
   266  		idx      int
   267  		expected string
   268  	}{
   269  		{
   270  			idx:      0,
   271  			expected: "日",
   272  		},
   273  		{
   274  			idx:      1,
   275  			expected: "月",
   276  		},
   277  		{
   278  			idx:      2,
   279  			expected: "火",
   280  		},
   281  		{
   282  			idx:      3,
   283  			expected: "水",
   284  		},
   285  		{
   286  			idx:      4,
   287  			expected: "木",
   288  		},
   289  		{
   290  			idx:      5,
   291  			expected: "金",
   292  		},
   293  		{
   294  			idx:      6,
   295  			expected: "土",
   296  		},
   297  	}
   298  
   299  	for _, tt := range tests {
   300  		s := trans.WeekdayNarrow(time.Weekday(tt.idx))
   301  		if s != tt.expected {
   302  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   303  		}
   304  	}
   305  }
   306  
   307  func TestDaysShort(t *testing.T) {
   308  
   309  	trans := New()
   310  	days := trans.WeekdaysShort()
   311  
   312  	for i, day := range days {
   313  		s := trans.WeekdayShort(time.Weekday(i))
   314  		if s != day {
   315  			t.Errorf("Expected '%s' Got '%s'", day, s)
   316  		}
   317  	}
   318  
   319  	tests := []struct {
   320  		idx      int
   321  		expected string
   322  	}{
   323  		{
   324  			idx:      0,
   325  			expected: "日",
   326  		},
   327  		{
   328  			idx:      1,
   329  			expected: "月",
   330  		},
   331  		{
   332  			idx:      2,
   333  			expected: "火",
   334  		},
   335  		{
   336  			idx:      3,
   337  			expected: "水",
   338  		},
   339  		{
   340  			idx:      4,
   341  			expected: "木",
   342  		},
   343  		{
   344  			idx:      5,
   345  			expected: "金",
   346  		},
   347  		{
   348  			idx:      6,
   349  			expected: "土",
   350  		},
   351  	}
   352  
   353  	for _, tt := range tests {
   354  		s := trans.WeekdayShort(time.Weekday(tt.idx))
   355  		if s != tt.expected {
   356  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   357  		}
   358  	}
   359  }
   360  
   361  func TestDaysWide(t *testing.T) {
   362  
   363  	trans := New()
   364  	days := trans.WeekdaysWide()
   365  
   366  	for i, day := range days {
   367  		s := trans.WeekdayWide(time.Weekday(i))
   368  		if s != day {
   369  			t.Errorf("Expected '%s' Got '%s'", day, s)
   370  		}
   371  	}
   372  
   373  	tests := []struct {
   374  		idx      int
   375  		expected string
   376  	}{
   377  		{
   378  			idx:      0,
   379  			expected: "日曜日",
   380  		},
   381  		{
   382  			idx:      1,
   383  			expected: "月曜日",
   384  		},
   385  		{
   386  			idx:      2,
   387  			expected: "火曜日",
   388  		},
   389  		{
   390  			idx:      3,
   391  			expected: "水曜日",
   392  		},
   393  		{
   394  			idx:      4,
   395  			expected: "木曜日",
   396  		},
   397  		{
   398  			idx:      5,
   399  			expected: "金曜日",
   400  		},
   401  		{
   402  			idx:      6,
   403  			expected: "土曜日",
   404  		},
   405  	}
   406  
   407  	for _, tt := range tests {
   408  		s := trans.WeekdayWide(time.Weekday(tt.idx))
   409  		if s != tt.expected {
   410  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   411  		}
   412  	}
   413  }
   414  
   415  func TestMonthsAbbreviated(t *testing.T) {
   416  
   417  	trans := New()
   418  	months := trans.MonthsAbbreviated()
   419  
   420  	for i, month := range months {
   421  		s := trans.MonthAbbreviated(time.Month(i + 1))
   422  		if s != month {
   423  			t.Errorf("Expected '%s' Got '%s'", month, s)
   424  		}
   425  	}
   426  
   427  	tests := []struct {
   428  		idx      int
   429  		expected string
   430  	}{
   431  		{
   432  			idx:      1,
   433  			expected: "1月",
   434  		},
   435  		{
   436  			idx:      2,
   437  			expected: "2月",
   438  		},
   439  		{
   440  			idx:      3,
   441  			expected: "3月",
   442  		},
   443  		{
   444  			idx:      4,
   445  			expected: "4月",
   446  		},
   447  		{
   448  			idx:      5,
   449  			expected: "5月",
   450  		},
   451  		{
   452  			idx:      6,
   453  			expected: "6月",
   454  		},
   455  		{
   456  			idx:      7,
   457  			expected: "7月",
   458  		},
   459  		{
   460  			idx:      8,
   461  			expected: "8月",
   462  		},
   463  		{
   464  			idx:      9,
   465  			expected: "9月",
   466  		},
   467  		{
   468  			idx:      10,
   469  			expected: "10月",
   470  		},
   471  		{
   472  			idx:      11,
   473  			expected: "11月",
   474  		},
   475  		{
   476  			idx:      12,
   477  			expected: "12月",
   478  		},
   479  	}
   480  
   481  	for _, tt := range tests {
   482  		s := trans.MonthAbbreviated(time.Month(tt.idx))
   483  		if s != tt.expected {
   484  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   485  		}
   486  	}
   487  }
   488  
   489  func TestMonthsNarrow(t *testing.T) {
   490  
   491  	trans := New()
   492  	months := trans.MonthsNarrow()
   493  
   494  	for i, month := range months {
   495  		s := trans.MonthNarrow(time.Month(i + 1))
   496  		if s != month {
   497  			t.Errorf("Expected '%s' Got '%s'", month, s)
   498  		}
   499  	}
   500  
   501  	tests := []struct {
   502  		idx      int
   503  		expected string
   504  	}{
   505  		{
   506  			idx:      1,
   507  			expected: "1",
   508  		},
   509  		{
   510  			idx:      2,
   511  			expected: "2",
   512  		},
   513  		{
   514  			idx:      3,
   515  			expected: "3",
   516  		},
   517  		{
   518  			idx:      4,
   519  			expected: "4",
   520  		},
   521  		{
   522  			idx:      5,
   523  			expected: "5",
   524  		},
   525  		{
   526  			idx:      6,
   527  			expected: "6",
   528  		},
   529  		{
   530  			idx:      7,
   531  			expected: "7",
   532  		},
   533  		{
   534  			idx:      8,
   535  			expected: "8",
   536  		},
   537  		{
   538  			idx:      9,
   539  			expected: "9",
   540  		},
   541  		{
   542  			idx:      10,
   543  			expected: "10",
   544  		},
   545  		{
   546  			idx:      11,
   547  			expected: "11",
   548  		},
   549  		{
   550  			idx:      12,
   551  			expected: "12",
   552  		},
   553  	}
   554  
   555  	for _, tt := range tests {
   556  		s := trans.MonthNarrow(time.Month(tt.idx))
   557  		if s != tt.expected {
   558  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   559  		}
   560  	}
   561  }
   562  
   563  func TestMonthsWide(t *testing.T) {
   564  
   565  	trans := New()
   566  	months := trans.MonthsWide()
   567  
   568  	for i, month := range months {
   569  		s := trans.MonthWide(time.Month(i + 1))
   570  		if s != month {
   571  			t.Errorf("Expected '%s' Got '%s'", month, s)
   572  		}
   573  	}
   574  
   575  	tests := []struct {
   576  		idx      int
   577  		expected string
   578  	}{
   579  		{
   580  			idx:      1,
   581  			expected: "1月",
   582  		},
   583  		{
   584  			idx:      2,
   585  			expected: "2月",
   586  		},
   587  		{
   588  			idx:      3,
   589  			expected: "3月",
   590  		},
   591  		{
   592  			idx:      4,
   593  			expected: "4月",
   594  		},
   595  		{
   596  			idx:      5,
   597  			expected: "5月",
   598  		},
   599  		{
   600  			idx:      6,
   601  			expected: "6月",
   602  		},
   603  		{
   604  			idx:      7,
   605  			expected: "7月",
   606  		},
   607  		{
   608  			idx:      8,
   609  			expected: "8月",
   610  		},
   611  		{
   612  			idx:      9,
   613  			expected: "9月",
   614  		},
   615  		{
   616  			idx:      10,
   617  			expected: "10月",
   618  		},
   619  		{
   620  			idx:      11,
   621  			expected: "11月",
   622  		},
   623  		{
   624  			idx:      12,
   625  			expected: "12月",
   626  		},
   627  	}
   628  
   629  	for _, tt := range tests {
   630  		s := string(trans.MonthWide(time.Month(tt.idx)))
   631  		if s != tt.expected {
   632  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   633  		}
   634  	}
   635  }
   636  
   637  func TestFmtTimeFull(t *testing.T) {
   638  
   639  	loc, err := time.LoadLocation("Asia/Tokyo")
   640  	if err != nil {
   641  		t.Errorf("Expected '<nil>' Got '%s'", err)
   642  	}
   643  
   644  	fixed := time.FixedZone("OTHER", -4)
   645  
   646  	tests := []struct {
   647  		t        time.Time
   648  		expected string
   649  	}{
   650  		{
   651  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
   652  			expected: "9時05分01秒 日本標準時",
   653  		},
   654  		{
   655  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
   656  			expected: "20時05分01秒 OTHER",
   657  		},
   658  	}
   659  
   660  	trans := New()
   661  
   662  	for _, tt := range tests {
   663  		s := trans.FmtTimeFull(tt.t)
   664  		if s != tt.expected {
   665  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   666  		}
   667  	}
   668  }
   669  
   670  func TestFmtTimeLong(t *testing.T) {
   671  
   672  	loc, err := time.LoadLocation("Asia/Tokyo")
   673  	if err != nil {
   674  		t.Errorf("Expected '<nil>' Got '%s'", err)
   675  	}
   676  
   677  	tests := []struct {
   678  		t        time.Time
   679  		expected string
   680  	}{
   681  		{
   682  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
   683  			expected: "9:05:01 JST",
   684  		},
   685  		{
   686  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
   687  			expected: "20:05:01 JST",
   688  		},
   689  	}
   690  
   691  	trans := New()
   692  
   693  	for _, tt := range tests {
   694  		s := trans.FmtTimeLong(tt.t)
   695  		if s != tt.expected {
   696  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   697  		}
   698  	}
   699  }
   700  
   701  func TestFmtTimeMedium(t *testing.T) {
   702  
   703  	tests := []struct {
   704  		t        time.Time
   705  		expected string
   706  	}{
   707  		{
   708  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
   709  			expected: "9:05:01",
   710  		},
   711  		{
   712  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
   713  			expected: "20:05:01",
   714  		},
   715  	}
   716  
   717  	trans := New()
   718  
   719  	for _, tt := range tests {
   720  		s := trans.FmtTimeMedium(tt.t)
   721  		if s != tt.expected {
   722  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   723  		}
   724  	}
   725  }
   726  
   727  func TestFmtTimeShort(t *testing.T) {
   728  
   729  	tests := []struct {
   730  		t        time.Time
   731  		expected string
   732  	}{
   733  		{
   734  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
   735  			expected: "9:05",
   736  		},
   737  		{
   738  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
   739  			expected: "20:05",
   740  		},
   741  	}
   742  
   743  	trans := New()
   744  
   745  	for _, tt := range tests {
   746  		s := trans.FmtTimeShort(tt.t)
   747  		if s != tt.expected {
   748  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   749  		}
   750  	}
   751  }
   752  
   753  func TestFmtDateFull(t *testing.T) {
   754  
   755  	tests := []struct {
   756  		t        time.Time
   757  		expected string
   758  	}{
   759  		{
   760  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   761  			expected: "2016年2月3日水曜日",
   762  		},
   763  	}
   764  
   765  	trans := New()
   766  
   767  	for _, tt := range tests {
   768  		s := trans.FmtDateFull(tt.t)
   769  		if s != tt.expected {
   770  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   771  		}
   772  	}
   773  }
   774  
   775  func TestFmtDateLong(t *testing.T) {
   776  
   777  	tests := []struct {
   778  		t        time.Time
   779  		expected string
   780  	}{
   781  		{
   782  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   783  			expected: "2016年2月3日",
   784  		},
   785  	}
   786  
   787  	trans := New()
   788  
   789  	for _, tt := range tests {
   790  		s := trans.FmtDateLong(tt.t)
   791  		if s != tt.expected {
   792  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   793  		}
   794  	}
   795  }
   796  
   797  func TestFmtDateMedium(t *testing.T) {
   798  
   799  	tests := []struct {
   800  		t        time.Time
   801  		expected string
   802  	}{
   803  		{
   804  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   805  			expected: "2016/02/03",
   806  		},
   807  	}
   808  
   809  	trans := New()
   810  
   811  	for _, tt := range tests {
   812  		s := trans.FmtDateMedium(tt.t)
   813  		if s != tt.expected {
   814  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   815  		}
   816  	}
   817  }
   818  
   819  func TestFmtDateShort(t *testing.T) {
   820  
   821  	tests := []struct {
   822  		t        time.Time
   823  		expected string
   824  	}{
   825  		{
   826  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   827  			expected: "2016/02/03",
   828  		},
   829  		{
   830  			t:        time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
   831  			expected: "500/02/03",
   832  		},
   833  	}
   834  
   835  	trans := New()
   836  
   837  	for _, tt := range tests {
   838  		s := trans.FmtDateShort(tt.t)
   839  		if s != tt.expected {
   840  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   841  		}
   842  	}
   843  }
   844  
   845  func TestFmtNumber(t *testing.T) {
   846  
   847  	tests := []struct {
   848  		num      float64
   849  		v        uint64
   850  		expected string
   851  	}{
   852  		{
   853  			num:      1123456.5643,
   854  			v:        2,
   855  			expected: "1,123,456.56",
   856  		},
   857  		{
   858  			num:      1123456.5643,
   859  			v:        1,
   860  			expected: "1,123,456.6",
   861  		},
   862  		{
   863  			num:      221123456.5643,
   864  			v:        3,
   865  			expected: "221,123,456.564",
   866  		},
   867  		{
   868  			num:      -221123456.5643,
   869  			v:        3,
   870  			expected: "-221,123,456.564",
   871  		},
   872  		{
   873  			num:      -221123456.5643,
   874  			v:        3,
   875  			expected: "-221,123,456.564",
   876  		},
   877  		{
   878  			num:      0,
   879  			v:        2,
   880  			expected: "0.00",
   881  		},
   882  		{
   883  			num:      -0,
   884  			v:        2,
   885  			expected: "0.00",
   886  		},
   887  	}
   888  
   889  	trans := New()
   890  
   891  	for _, tt := range tests {
   892  		s := trans.FmtNumber(tt.num, tt.v)
   893  		if s != tt.expected {
   894  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   895  		}
   896  	}
   897  }
   898  
   899  func TestFmtCurrency(t *testing.T) {
   900  
   901  	tests := []struct {
   902  		num      float64
   903  		v        uint64
   904  		currency currency.Type
   905  		expected string
   906  	}{
   907  		{
   908  			num:      1123456.5643,
   909  			v:        2,
   910  			currency: currency.JPY,
   911  			expected: "¥1,123,456.56",
   912  		},
   913  		{
   914  			num:      1123456.5643,
   915  			v:        1,
   916  			currency: currency.JPY,
   917  			expected: "¥1,123,456.60",
   918  		},
   919  		{
   920  			num:      221123456.5643,
   921  			v:        3,
   922  			currency: currency.JPY,
   923  			expected: "¥221,123,456.564",
   924  		},
   925  		{
   926  			num:      -221123456.5643,
   927  			v:        3,
   928  			currency: currency.JPY,
   929  			expected: "-¥221,123,456.564",
   930  		},
   931  		{
   932  			num:      0,
   933  			v:        2,
   934  			currency: currency.JPY,
   935  			expected: "¥0.00",
   936  		},
   937  		{
   938  			num:      -0,
   939  			v:        2,
   940  			currency: currency.JPY,
   941  			expected: "¥0.00",
   942  		},
   943  		{
   944  			num:      1.23,
   945  			v:        0,
   946  			currency: currency.JPY,
   947  			expected: "¥1.00",
   948  		},
   949  	}
   950  
   951  	trans := New()
   952  
   953  	for _, tt := range tests {
   954  		s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
   955  		if s != tt.expected {
   956  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   957  		}
   958  	}
   959  }
   960  
   961  func TestFmtAccounting(t *testing.T) {
   962  
   963  	tests := []struct {
   964  		num      float64
   965  		v        uint64
   966  		currency currency.Type
   967  		expected string
   968  	}{
   969  		{
   970  			num:      1123456.5643,
   971  			v:        2,
   972  			currency: currency.JPY,
   973  			expected: "¥1,123,456.56",
   974  		},
   975  		{
   976  			num:      1123456.5643,
   977  			v:        1,
   978  			currency: currency.JPY,
   979  			expected: "¥1,123,456.60",
   980  		},
   981  		{
   982  			num:      221123456.5643,
   983  			v:        3,
   984  			currency: currency.JPY,
   985  			expected: "¥221,123,456.564",
   986  		},
   987  		{
   988  			num:      -221123456.5643,
   989  			v:        3,
   990  			currency: currency.JPY,
   991  			expected: "(¥221,123,456.564)",
   992  		},
   993  		{
   994  			num:      -0,
   995  			v:        2,
   996  			currency: currency.JPY,
   997  			expected: "¥0.00",
   998  		},
   999  		{
  1000  			num:      1.23,
  1001  			v:        0,
  1002  			currency: currency.JPY,
  1003  			expected: "¥1.00",
  1004  		},
  1005  	}
  1006  
  1007  	trans := New()
  1008  
  1009  	for _, tt := range tests {
  1010  		s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
  1011  		if s != tt.expected {
  1012  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1013  		}
  1014  	}
  1015  }
  1016  
  1017  func TestFmtPercent(t *testing.T) {
  1018  
  1019  	tests := []struct {
  1020  		num      float64
  1021  		v        uint64
  1022  		expected string
  1023  	}{
  1024  		{
  1025  			num:      15,
  1026  			v:        0,
  1027  			expected: "15%",
  1028  		},
  1029  		{
  1030  			num:      15,
  1031  			v:        2,
  1032  			expected: "15.00%",
  1033  		},
  1034  		{
  1035  			num:      434.45,
  1036  			v:        0,
  1037  			expected: "434%",
  1038  		},
  1039  		{
  1040  			num:      34.4,
  1041  			v:        2,
  1042  			expected: "34.40%",
  1043  		},
  1044  		{
  1045  			num:      -34,
  1046  			v:        0,
  1047  			expected: "-34%",
  1048  		},
  1049  	}
  1050  
  1051  	trans := New()
  1052  
  1053  	for _, tt := range tests {
  1054  		s := trans.FmtPercent(tt.num, tt.v)
  1055  		if s != tt.expected {
  1056  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1057  		}
  1058  	}
  1059  }
  1060  

View as plain text