git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/countries/countryint32_test.go (about)

     1  package countries
     2  
     3  import "testing"
     4  
     5  func TestCountryInt32Value(t *testing.T) {
     6  	data := []CountryInt32{
     7  		"AA",
     8  		"AB",
     9  		"ZY",
    10  		"ZZ",
    11  	}
    12  	expected := []int32{
    13  		0x4141,
    14  		0x4142,
    15  		0x5A59,
    16  		0x5A5A,
    17  	}
    18  
    19  	for i, elem := range data {
    20  		v, _ := elem.Value()
    21  		if v != expected[i] {
    22  			t.Errorf("value (0x%x) != expected (0x%x)", v, expected[i])
    23  		}
    24  	}
    25  }
    26  
    27  func TestCountryInt32Scan(t *testing.T) {
    28  	data := []int32{
    29  		0x4141,
    30  		0x4142,
    31  		0x5A59,
    32  		0x5A5A,
    33  	}
    34  	expected := []CountryInt32{
    35  		"AA",
    36  		"AB",
    37  		"ZY",
    38  		"ZZ",
    39  	}
    40  
    41  	for i, elem := range data {
    42  		var country CountryInt32
    43  		err := country.Scan(elem)
    44  		if err != nil {
    45  			t.Errorf("Scanning: %x: %s", elem, err)
    46  		}
    47  		if country != expected[i] {
    48  			t.Errorf("value (%s) != expected (%s)", country, expected[i])
    49  		}
    50  	}
    51  }