...

Source file src/github.com/go-playground/locales/ru_RU/ru_RU_test.go

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

     1  package ru_RU
     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 := "ru_RU"
    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 := 4
    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.PluralRuleOne,
    98  		},
    99  		{
   100  			expected: locales.PluralRuleFew,
   101  		},
   102  		{
   103  			expected: locales.PluralRuleMany,
   104  		},
   105  		{
   106  			expected: locales.PluralRuleOther,
   107  		},
   108  	}
   109  
   110  	rules := trans.PluralsCardinal()
   111  	expected := 4
   112  	if len(rules) != expected {
   113  		t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
   114  	}
   115  
   116  	for _, tt := range tests {
   117  
   118  		r := locales.PluralRuleUnknown
   119  
   120  		for i := 0; i < len(rules); i++ {
   121  			if rules[i] == tt.expected {
   122  				r = rules[i]
   123  				break
   124  			}
   125  		}
   126  		if r == locales.PluralRuleUnknown {
   127  			t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
   128  		}
   129  	}
   130  }
   131  
   132  func TestRangePlurals(t *testing.T) {
   133  
   134  	trans := New()
   135  
   136  	tests := []struct {
   137  		num1     float64
   138  		v1       uint64
   139  		num2     float64
   140  		v2       uint64
   141  		expected locales.PluralRule
   142  	}{
   143  		{
   144  			num1:     1,
   145  			v1:       1,
   146  			num2:     2,
   147  			v2:       2,
   148  			expected: locales.PluralRuleOther,
   149  		},
   150  		{
   151  			num1:     1,
   152  			v1:       0,
   153  			num2:     2,
   154  			v2:       0,
   155  			expected: locales.PluralRuleFew,
   156  		},
   157  		{
   158  			num1:     1,
   159  			v1:       0,
   160  			num2:     21,
   161  			v2:       0,
   162  			expected: locales.PluralRuleOne,
   163  		},
   164  		{
   165  			num1:     1,
   166  			v1:       0,
   167  			num2:     5,
   168  			v2:       0,
   169  			expected: locales.PluralRuleMany,
   170  		},
   171  		{
   172  			num1:     1,
   173  			v1:       0,
   174  			num2:     10,
   175  			v2:       0,
   176  			expected: locales.PluralRuleMany,
   177  		},
   178  		{
   179  			num1:     1,
   180  			v1:       0,
   181  			num2:     10.0,
   182  			v2:       1,
   183  			expected: locales.PluralRuleOther,
   184  		},
   185  		{
   186  			num1:     2,
   187  			v1:       0,
   188  			num2:     21,
   189  			v2:       0,
   190  			expected: locales.PluralRuleOne,
   191  		},
   192  		{
   193  			num1:     2,
   194  			v1:       0,
   195  			num2:     22,
   196  			v2:       0,
   197  			expected: locales.PluralRuleFew,
   198  		},
   199  		{
   200  			num1:     2,
   201  			v1:       0,
   202  			num2:     5,
   203  			v2:       0,
   204  			expected: locales.PluralRuleMany,
   205  		},
   206  		{
   207  			num1:     2,
   208  			v1:       0,
   209  			num2:     10,
   210  			v2:       1,
   211  			expected: locales.PluralRuleOther,
   212  		},
   213  		{
   214  			num1:     0,
   215  			v1:       0,
   216  			num2:     1,
   217  			v2:       0,
   218  			expected: locales.PluralRuleOne,
   219  		},
   220  		{
   221  			num1:     0,
   222  			v1:       0,
   223  			num2:     2,
   224  			v2:       0,
   225  			expected: locales.PluralRuleFew,
   226  		},
   227  		{
   228  			num1:     0,
   229  			v1:       0,
   230  			num2:     5,
   231  			v2:       0,
   232  			expected: locales.PluralRuleMany,
   233  		},
   234  		{
   235  			num1:     0,
   236  			v1:       0,
   237  			num2:     10,
   238  			v2:       1,
   239  			expected: locales.PluralRuleOther,
   240  		},
   241  		{
   242  			num1:     0.0,
   243  			v1:       1,
   244  			num2:     1,
   245  			v2:       0,
   246  			expected: locales.PluralRuleOne,
   247  		},
   248  		{
   249  			num1:     0.0,
   250  			v1:       1,
   251  			num2:     2,
   252  			v2:       0,
   253  			expected: locales.PluralRuleFew,
   254  		},
   255  		{
   256  			num1:     0.0,
   257  			v1:       1,
   258  			num2:     5,
   259  			v2:       0,
   260  			expected: locales.PluralRuleMany,
   261  		},
   262  		{
   263  			num1:     0.0,
   264  			v1:       1,
   265  			num2:     10.0,
   266  			v2:       1,
   267  			expected: locales.PluralRuleOther,
   268  		},
   269  	}
   270  
   271  	for _, tt := range tests {
   272  		rule := trans.RangePluralRule(tt.num1, tt.v1, tt.num2, tt.v2)
   273  		if rule != tt.expected {
   274  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   275  		}
   276  	}
   277  }
   278  
   279  func TestOrdinalPlurals(t *testing.T) {
   280  
   281  	trans := New()
   282  
   283  	tests := []struct {
   284  		num      float64
   285  		v        uint64
   286  		expected locales.PluralRule
   287  	}{
   288  		{
   289  			num:      1,
   290  			v:        0,
   291  			expected: locales.PluralRuleOther,
   292  		},
   293  		{
   294  			num:      2,
   295  			v:        0,
   296  			expected: locales.PluralRuleOther,
   297  		},
   298  		{
   299  			num:      3,
   300  			v:        0,
   301  			expected: locales.PluralRuleOther,
   302  		},
   303  		{
   304  			num:      4,
   305  			v:        0,
   306  			expected: locales.PluralRuleOther,
   307  		},
   308  	}
   309  
   310  	for _, tt := range tests {
   311  		rule := trans.OrdinalPluralRule(tt.num, tt.v)
   312  		if rule != tt.expected {
   313  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   314  		}
   315  	}
   316  }
   317  
   318  func TestCardinalPlurals(t *testing.T) {
   319  
   320  	trans := New()
   321  
   322  	tests := []struct {
   323  		num      float64
   324  		v        uint64
   325  		expected locales.PluralRule
   326  	}{
   327  		{
   328  			num:      1,
   329  			v:        0,
   330  			expected: locales.PluralRuleOne,
   331  		},
   332  		{
   333  			num:      21,
   334  			v:        0,
   335  			expected: locales.PluralRuleOne,
   336  		},
   337  		{
   338  			num:      31,
   339  			v:        0,
   340  			expected: locales.PluralRuleOne,
   341  		},
   342  		{
   343  			num:      2,
   344  			v:        0,
   345  			expected: locales.PluralRuleFew,
   346  		},
   347  		{
   348  			num:      3,
   349  			v:        0,
   350  			expected: locales.PluralRuleFew,
   351  		},
   352  		{
   353  			num:      22,
   354  			v:        0,
   355  			expected: locales.PluralRuleFew,
   356  		},
   357  		{
   358  			num:      23,
   359  			v:        0,
   360  			expected: locales.PluralRuleFew,
   361  		},
   362  		{
   363  			num:      0,
   364  			v:        0,
   365  			expected: locales.PluralRuleMany,
   366  		},
   367  		{
   368  			num:      5,
   369  			v:        0,
   370  			expected: locales.PluralRuleMany,
   371  		},
   372  		{
   373  			num:      11,
   374  			v:        0,
   375  			expected: locales.PluralRuleMany,
   376  		},
   377  		{
   378  			num:      100,
   379  			v:        0,
   380  			expected: locales.PluralRuleMany,
   381  		},
   382  	}
   383  
   384  	for _, tt := range tests {
   385  		rule := trans.CardinalPluralRule(tt.num, tt.v)
   386  		if rule != tt.expected {
   387  			t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
   388  		}
   389  	}
   390  }
   391  
   392  func TestDaysAbbreviated(t *testing.T) {
   393  
   394  	trans := New()
   395  	days := trans.WeekdaysAbbreviated()
   396  
   397  	for i, day := range days {
   398  		s := trans.WeekdayAbbreviated(time.Weekday(i))
   399  		if s != day {
   400  			t.Errorf("Expected '%s' Got '%s'", day, s)
   401  		}
   402  	}
   403  
   404  	tests := []struct {
   405  		idx      int
   406  		expected string
   407  	}{
   408  		{
   409  			idx:      0,
   410  			expected: "вс",
   411  		},
   412  		{
   413  			idx:      1,
   414  			expected: "пн",
   415  		},
   416  		{
   417  			idx:      2,
   418  			expected: "вт",
   419  		},
   420  		{
   421  			idx:      3,
   422  			expected: "ср",
   423  		},
   424  		{
   425  			idx:      4,
   426  			expected: "чт",
   427  		},
   428  		{
   429  			idx:      5,
   430  			expected: "пт",
   431  		},
   432  		{
   433  			idx:      6,
   434  			expected: "сб",
   435  		},
   436  	}
   437  
   438  	for _, tt := range tests {
   439  		s := trans.WeekdayAbbreviated(time.Weekday(tt.idx))
   440  		if s != tt.expected {
   441  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   442  		}
   443  	}
   444  }
   445  
   446  func TestDaysNarrow(t *testing.T) {
   447  
   448  	trans := New()
   449  	days := trans.WeekdaysNarrow()
   450  
   451  	for i, day := range days {
   452  		s := trans.WeekdayNarrow(time.Weekday(i))
   453  		if s != day {
   454  			t.Errorf("Expected '%s' Got '%s'", string(day), s)
   455  		}
   456  	}
   457  
   458  	tests := []struct {
   459  		idx      int
   460  		expected string
   461  	}{
   462  		{
   463  			idx:      0,
   464  			expected: "вс",
   465  		},
   466  		{
   467  			idx:      1,
   468  			expected: "пн",
   469  		},
   470  		{
   471  			idx:      2,
   472  			expected: "вт",
   473  		},
   474  		{
   475  			idx:      3,
   476  			expected: "ср",
   477  		},
   478  		{
   479  			idx:      4,
   480  			expected: "чт",
   481  		},
   482  		{
   483  			idx:      5,
   484  			expected: "пт",
   485  		},
   486  		{
   487  			idx:      6,
   488  			expected: "сб",
   489  		},
   490  	}
   491  
   492  	for _, tt := range tests {
   493  		s := trans.WeekdayNarrow(time.Weekday(tt.idx))
   494  		if s != tt.expected {
   495  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   496  		}
   497  	}
   498  }
   499  
   500  func TestDaysShort(t *testing.T) {
   501  
   502  	trans := New()
   503  	days := trans.WeekdaysShort()
   504  
   505  	for i, day := range days {
   506  		s := trans.WeekdayShort(time.Weekday(i))
   507  		if s != day {
   508  			t.Errorf("Expected '%s' Got '%s'", day, s)
   509  		}
   510  	}
   511  
   512  	tests := []struct {
   513  		idx      int
   514  		expected string
   515  	}{
   516  		{
   517  			idx:      0,
   518  			expected: "вс",
   519  		},
   520  		{
   521  			idx:      1,
   522  			expected: "пн",
   523  		},
   524  		{
   525  			idx:      2,
   526  			expected: "вт",
   527  		},
   528  		{
   529  			idx:      3,
   530  			expected: "ср",
   531  		},
   532  		{
   533  			idx:      4,
   534  			expected: "чт",
   535  		},
   536  		{
   537  			idx:      5,
   538  			expected: "пт",
   539  		},
   540  		{
   541  			idx:      6,
   542  			expected: "сб",
   543  		},
   544  	}
   545  
   546  	for _, tt := range tests {
   547  		s := trans.WeekdayShort(time.Weekday(tt.idx))
   548  		if s != tt.expected {
   549  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   550  		}
   551  	}
   552  }
   553  
   554  func TestDaysWide(t *testing.T) {
   555  
   556  	trans := New()
   557  	days := trans.WeekdaysWide()
   558  
   559  	for i, day := range days {
   560  		s := trans.WeekdayWide(time.Weekday(i))
   561  		if s != day {
   562  			t.Errorf("Expected '%s' Got '%s'", day, s)
   563  		}
   564  	}
   565  
   566  	tests := []struct {
   567  		idx      int
   568  		expected string
   569  	}{
   570  		{
   571  			idx:      0,
   572  			expected: "воскресенье",
   573  		},
   574  		{
   575  			idx:      1,
   576  			expected: "понедельник",
   577  		},
   578  		{
   579  			idx:      2,
   580  			expected: "вторник",
   581  		},
   582  		{
   583  			idx:      3,
   584  			expected: "среда",
   585  		},
   586  		{
   587  			idx:      4,
   588  			expected: "четверг",
   589  		},
   590  		{
   591  			idx:      5,
   592  			expected: "пятница",
   593  		},
   594  		{
   595  			idx:      6,
   596  			expected: "суббота",
   597  		},
   598  	}
   599  
   600  	for _, tt := range tests {
   601  		s := trans.WeekdayWide(time.Weekday(tt.idx))
   602  		if s != tt.expected {
   603  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   604  		}
   605  	}
   606  }
   607  
   608  func TestMonthsAbbreviated(t *testing.T) {
   609  
   610  	trans := New()
   611  	months := trans.MonthsAbbreviated()
   612  
   613  	for i, month := range months {
   614  		s := trans.MonthAbbreviated(time.Month(i + 1))
   615  		if s != month {
   616  			t.Errorf("Expected '%s' Got '%s'", month, s)
   617  		}
   618  	}
   619  
   620  	tests := []struct {
   621  		idx      int
   622  		expected string
   623  	}{
   624  		{
   625  			idx:      1,
   626  			expected: "янв.",
   627  		},
   628  		{
   629  			idx:      2,
   630  			expected: "февр.",
   631  		},
   632  		{
   633  			idx:      3,
   634  			expected: "мар.",
   635  		},
   636  		{
   637  			idx:      4,
   638  			expected: "апр.",
   639  		},
   640  		{
   641  			idx:      5,
   642  			expected: "мая",
   643  		},
   644  		{
   645  			idx:      6,
   646  			expected: "июн.",
   647  		},
   648  		{
   649  			idx:      7,
   650  			expected: "июл.",
   651  		},
   652  		{
   653  			idx:      8,
   654  			expected: "авг.",
   655  		},
   656  		{
   657  			idx:      9,
   658  			expected: "сент.",
   659  		},
   660  		{
   661  			idx:      10,
   662  			expected: "окт.",
   663  		},
   664  		{
   665  			idx:      11,
   666  			expected: "нояб.",
   667  		},
   668  		{
   669  			idx:      12,
   670  			expected: "дек.",
   671  		},
   672  	}
   673  
   674  	for _, tt := range tests {
   675  		s := trans.MonthAbbreviated(time.Month(tt.idx))
   676  		if s != tt.expected {
   677  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   678  		}
   679  	}
   680  }
   681  
   682  func TestMonthsNarrow(t *testing.T) {
   683  
   684  	trans := New()
   685  	months := trans.MonthsNarrow()
   686  
   687  	for i, month := range months {
   688  		s := trans.MonthNarrow(time.Month(i + 1))
   689  		if s != month {
   690  			t.Errorf("Expected '%s' Got '%s'", month, s)
   691  		}
   692  	}
   693  
   694  	tests := []struct {
   695  		idx      int
   696  		expected string
   697  	}{
   698  		{
   699  			idx:      1,
   700  			expected: "Я",
   701  		},
   702  		{
   703  			idx:      2,
   704  			expected: "Ф",
   705  		},
   706  		{
   707  			idx:      3,
   708  			expected: "М",
   709  		},
   710  		{
   711  			idx:      4,
   712  			expected: "А",
   713  		},
   714  		{
   715  			idx:      5,
   716  			expected: "М",
   717  		},
   718  		{
   719  			idx:      6,
   720  			expected: "И",
   721  		},
   722  		{
   723  			idx:      7,
   724  			expected: "И",
   725  		},
   726  		{
   727  			idx:      8,
   728  			expected: "А",
   729  		},
   730  		{
   731  			idx:      9,
   732  			expected: "С",
   733  		},
   734  		{
   735  			idx:      10,
   736  			expected: "О",
   737  		},
   738  		{
   739  			idx:      11,
   740  			expected: "Н",
   741  		},
   742  		{
   743  			idx:      12,
   744  			expected: "Д",
   745  		},
   746  	}
   747  
   748  	for _, tt := range tests {
   749  		s := trans.MonthNarrow(time.Month(tt.idx))
   750  		if s != tt.expected {
   751  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   752  		}
   753  	}
   754  }
   755  
   756  func TestMonthsWide(t *testing.T) {
   757  
   758  	trans := New()
   759  	months := trans.MonthsWide()
   760  
   761  	for i, month := range months {
   762  		s := trans.MonthWide(time.Month(i + 1))
   763  		if s != month {
   764  			t.Errorf("Expected '%s' Got '%s'", month, s)
   765  		}
   766  	}
   767  
   768  	tests := []struct {
   769  		idx      int
   770  		expected string
   771  	}{
   772  		{
   773  			idx:      1,
   774  			expected: "января",
   775  		},
   776  		{
   777  			idx:      2,
   778  			expected: "февраля",
   779  		},
   780  		{
   781  			idx:      3,
   782  			expected: "марта",
   783  		},
   784  		{
   785  			idx:      4,
   786  			expected: "апреля",
   787  		},
   788  		{
   789  			idx:      5,
   790  			expected: "мая",
   791  		},
   792  		{
   793  			idx:      6,
   794  			expected: "июня",
   795  		},
   796  		{
   797  			idx:      7,
   798  			expected: "июля",
   799  		},
   800  		{
   801  			idx:      8,
   802  			expected: "августа",
   803  		},
   804  		{
   805  			idx:      9,
   806  			expected: "сентября",
   807  		},
   808  		{
   809  			idx:      10,
   810  			expected: "октября",
   811  		},
   812  		{
   813  			idx:      11,
   814  			expected: "ноября",
   815  		},
   816  		{
   817  			idx:      12,
   818  			expected: "декабря",
   819  		},
   820  	}
   821  
   822  	for _, tt := range tests {
   823  		s := string(trans.MonthWide(time.Month(tt.idx)))
   824  		if s != tt.expected {
   825  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   826  		}
   827  	}
   828  }
   829  
   830  func TestFmtTimeFull(t *testing.T) {
   831  
   832  	loc, err := time.LoadLocation("America/Toronto")
   833  	if err != nil {
   834  		t.Errorf("Expected '<nil>' Got '%s'", err)
   835  	}
   836  
   837  	fixed := time.FixedZone("OTHER", -4)
   838  
   839  	tests := []struct {
   840  		t        time.Time
   841  		expected string
   842  	}{
   843  		{
   844  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
   845  			expected: "09:05:01 Восточная Америка, стандартное время",
   846  		},
   847  		{
   848  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
   849  			expected: "20:05:01 OTHER",
   850  		},
   851  	}
   852  
   853  	trans := New()
   854  
   855  	for _, tt := range tests {
   856  		s := trans.FmtTimeFull(tt.t)
   857  		if s != tt.expected {
   858  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   859  		}
   860  	}
   861  }
   862  
   863  func TestFmtTimeLong(t *testing.T) {
   864  
   865  	loc, err := time.LoadLocation("America/Toronto")
   866  	if err != nil {
   867  		t.Errorf("Expected '<nil>' Got '%s'", err)
   868  	}
   869  
   870  	tests := []struct {
   871  		t        time.Time
   872  		expected string
   873  	}{
   874  		{
   875  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
   876  			expected: "09:05:01 EST",
   877  		},
   878  		{
   879  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
   880  			expected: "20:05:01 EST",
   881  		},
   882  	}
   883  
   884  	trans := New()
   885  
   886  	for _, tt := range tests {
   887  		s := trans.FmtTimeLong(tt.t)
   888  		if s != tt.expected {
   889  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   890  		}
   891  	}
   892  }
   893  
   894  func TestFmtTimeMedium(t *testing.T) {
   895  
   896  	tests := []struct {
   897  		t        time.Time
   898  		expected string
   899  	}{
   900  		{
   901  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
   902  			expected: "09:05:01",
   903  		},
   904  		{
   905  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
   906  			expected: "20:05:01",
   907  		},
   908  	}
   909  
   910  	trans := New()
   911  
   912  	for _, tt := range tests {
   913  		s := trans.FmtTimeMedium(tt.t)
   914  		if s != tt.expected {
   915  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   916  		}
   917  	}
   918  }
   919  
   920  func TestFmtTimeShort(t *testing.T) {
   921  
   922  	tests := []struct {
   923  		t        time.Time
   924  		expected string
   925  	}{
   926  		{
   927  			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
   928  			expected: "09:05",
   929  		},
   930  		{
   931  			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
   932  			expected: "20:05",
   933  		},
   934  	}
   935  
   936  	trans := New()
   937  
   938  	for _, tt := range tests {
   939  		s := trans.FmtTimeShort(tt.t)
   940  		if s != tt.expected {
   941  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   942  		}
   943  	}
   944  }
   945  
   946  func TestFmtDateFull(t *testing.T) {
   947  
   948  	tests := []struct {
   949  		t        time.Time
   950  		expected string
   951  	}{
   952  		{
   953  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   954  			expected: "среда, 3 февраля 2016 г.",
   955  		},
   956  	}
   957  
   958  	trans := New()
   959  
   960  	for _, tt := range tests {
   961  		s := trans.FmtDateFull(tt.t)
   962  		if s != tt.expected {
   963  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   964  		}
   965  	}
   966  }
   967  
   968  func TestFmtDateLong(t *testing.T) {
   969  
   970  	tests := []struct {
   971  		t        time.Time
   972  		expected string
   973  	}{
   974  		{
   975  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   976  			expected: "3 февраля 2016 г.",
   977  		},
   978  	}
   979  
   980  	trans := New()
   981  
   982  	for _, tt := range tests {
   983  		s := trans.FmtDateLong(tt.t)
   984  		if s != tt.expected {
   985  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
   986  		}
   987  	}
   988  }
   989  
   990  func TestFmtDateMedium(t *testing.T) {
   991  
   992  	tests := []struct {
   993  		t        time.Time
   994  		expected string
   995  	}{
   996  		{
   997  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
   998  			expected: "3 февр. 2016 г.",
   999  		},
  1000  	}
  1001  
  1002  	trans := New()
  1003  
  1004  	for _, tt := range tests {
  1005  		s := trans.FmtDateMedium(tt.t)
  1006  		if s != tt.expected {
  1007  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1008  		}
  1009  	}
  1010  }
  1011  
  1012  func TestFmtDateShort(t *testing.T) {
  1013  
  1014  	tests := []struct {
  1015  		t        time.Time
  1016  		expected string
  1017  	}{
  1018  		{
  1019  			t:        time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
  1020  			expected: "03.02.2016", // date format changed from v29 dd.MM.yy to v30 dd.MM.y so adjusted test for new CLDR data
  1021  		},
  1022  		{
  1023  			t:        time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
  1024  			expected: "03.02.500",
  1025  		},
  1026  	}
  1027  
  1028  	trans := New()
  1029  
  1030  	for _, tt := range tests {
  1031  		s := trans.FmtDateShort(tt.t)
  1032  		if s != tt.expected {
  1033  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1034  		}
  1035  	}
  1036  }
  1037  
  1038  func TestFmtNumber(t *testing.T) {
  1039  
  1040  	tests := []struct {
  1041  		num      float64
  1042  		v        uint64
  1043  		expected string
  1044  	}{
  1045  		{
  1046  			num:      1123456.5643,
  1047  			v:        2,
  1048  			expected: "1 123 456,56",
  1049  		},
  1050  		{
  1051  			num:      1123456.5643,
  1052  			v:        1,
  1053  			expected: "1 123 456,6",
  1054  		},
  1055  		{
  1056  			num:      221123456.5643,
  1057  			v:        3,
  1058  			expected: "221 123 456,564",
  1059  		},
  1060  		{
  1061  			num:      -221123456.5643,
  1062  			v:        3,
  1063  			expected: "-221 123 456,564",
  1064  		},
  1065  		{
  1066  			num:      -221123456.5643,
  1067  			v:        3,
  1068  			expected: "-221 123 456,564",
  1069  		},
  1070  		{
  1071  			num:      0,
  1072  			v:        2,
  1073  			expected: "0,00",
  1074  		},
  1075  		{
  1076  			num:      -0,
  1077  			v:        2,
  1078  			expected: "0,00",
  1079  		},
  1080  		{
  1081  			num:      -0,
  1082  			v:        2,
  1083  			expected: "0,00",
  1084  		},
  1085  	}
  1086  
  1087  	trans := New()
  1088  
  1089  	for _, tt := range tests {
  1090  		s := trans.FmtNumber(tt.num, tt.v)
  1091  		if s != tt.expected {
  1092  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1093  		}
  1094  	}
  1095  }
  1096  
  1097  func TestFmtCurrency(t *testing.T) {
  1098  
  1099  	tests := []struct {
  1100  		num      float64
  1101  		v        uint64
  1102  		currency currency.Type
  1103  		expected string
  1104  	}{
  1105  		{
  1106  			num:      1123456.5643,
  1107  			v:        2,
  1108  			currency: currency.USD,
  1109  			expected: "1 123 456,56 USD",
  1110  		},
  1111  		{
  1112  			num:      1123456.5643,
  1113  			v:        1,
  1114  			currency: currency.USD,
  1115  			expected: "1 123 456,60 USD",
  1116  		},
  1117  		{
  1118  			num:      221123456.5643,
  1119  			v:        3,
  1120  			currency: currency.USD,
  1121  			expected: "221 123 456,564 USD",
  1122  		},
  1123  		{
  1124  			num:      -221123456.5643,
  1125  			v:        3,
  1126  			currency: currency.USD,
  1127  			expected: "-221 123 456,564 USD",
  1128  		},
  1129  		{
  1130  			num:      -221123456.5643,
  1131  			v:        3,
  1132  			currency: currency.CAD,
  1133  			expected: "-221 123 456,564 CAD",
  1134  		},
  1135  		{
  1136  			num:      0,
  1137  			v:        2,
  1138  			currency: currency.USD,
  1139  			expected: "0,00 USD",
  1140  		},
  1141  		{
  1142  			num:      -0,
  1143  			v:        2,
  1144  			currency: currency.USD,
  1145  			expected: "0,00 USD",
  1146  		},
  1147  		{
  1148  			num:      -0,
  1149  			v:        2,
  1150  			currency: currency.CAD,
  1151  			expected: "0,00 CAD",
  1152  		},
  1153  		{
  1154  			num:      1.23,
  1155  			v:        0,
  1156  			currency: currency.USD,
  1157  			expected: "1,00 USD",
  1158  		},
  1159  	}
  1160  
  1161  	trans := New()
  1162  
  1163  	for _, tt := range tests {
  1164  		s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
  1165  		if s != tt.expected {
  1166  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1167  		}
  1168  	}
  1169  }
  1170  
  1171  func TestFmtAccounting(t *testing.T) {
  1172  
  1173  	tests := []struct {
  1174  		num      float64
  1175  		v        uint64
  1176  		currency currency.Type
  1177  		expected string
  1178  	}{
  1179  		{
  1180  			num:      1123456.5643,
  1181  			v:        2,
  1182  			currency: currency.USD,
  1183  			expected: "1 123 456,56 USD",
  1184  		},
  1185  		{
  1186  			num:      1123456.5643,
  1187  			v:        1,
  1188  			currency: currency.USD,
  1189  			expected: "1 123 456,60 USD",
  1190  		},
  1191  		{
  1192  			num:      221123456.5643,
  1193  			v:        3,
  1194  			currency: currency.USD,
  1195  			expected: "221 123 456,564 USD",
  1196  		},
  1197  		{
  1198  			num:      -221123456.5643,
  1199  			v:        3,
  1200  			currency: currency.USD,
  1201  			expected: "-221 123 456,564 USD",
  1202  		},
  1203  		{
  1204  			num:      -221123456.5643,
  1205  			v:        3,
  1206  			currency: currency.CAD,
  1207  			expected: "-221 123 456,564 CAD",
  1208  		},
  1209  		{
  1210  			num:      -0,
  1211  			v:        2,
  1212  			currency: currency.USD,
  1213  			expected: "0,00 USD",
  1214  		},
  1215  		{
  1216  			num:      -0,
  1217  			v:        2,
  1218  			currency: currency.CAD,
  1219  			expected: "0,00 CAD",
  1220  		},
  1221  		{
  1222  			num:      1.23,
  1223  			v:        0,
  1224  			currency: currency.USD,
  1225  			expected: "1,00 USD",
  1226  		},
  1227  	}
  1228  
  1229  	trans := New()
  1230  
  1231  	for _, tt := range tests {
  1232  		s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
  1233  		if s != tt.expected {
  1234  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1235  		}
  1236  	}
  1237  }
  1238  
  1239  func TestFmtPercent(t *testing.T) {
  1240  
  1241  	tests := []struct {
  1242  		num      float64
  1243  		v        uint64
  1244  		expected string
  1245  	}{
  1246  		{
  1247  			num:      15,
  1248  			v:        0,
  1249  			expected: "15%",
  1250  		},
  1251  		{
  1252  			num:      15,
  1253  			v:        2,
  1254  			expected: "15,00%",
  1255  		},
  1256  		{
  1257  			num:      434.45,
  1258  			v:        0,
  1259  			expected: "434%",
  1260  		},
  1261  		{
  1262  			num:      34.4,
  1263  			v:        2,
  1264  			expected: "34,40%",
  1265  		},
  1266  		{
  1267  			num:      -34,
  1268  			v:        0,
  1269  			expected: "-34%",
  1270  		},
  1271  	}
  1272  
  1273  	trans := New()
  1274  
  1275  	for _, tt := range tests {
  1276  		s := trans.FmtPercent(tt.num, tt.v)
  1277  		if s != tt.expected {
  1278  			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1279  		}
  1280  	}
  1281  }
  1282  

View as plain text