github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/signer/core/signed_data_internal_test.go (about)

     1  //  Copyright 2018 The go-ethereum Authors
     2  //  Copyright 2019 The go-aigar Authors
     3  //  This file is part of the go-aigar library.
     4  //
     5  //  The go-aigar library is free software: you can redistribute it and/or modify
     6  //  it under the terms of the GNU Lesser General Public License as published by
     7  //  the Free Software Foundation, either version 3 of the License, or
     8  //  (at your option) any later version.
     9  //
    10  //  The go-aigar library is distributed in the hope that it will be useful,
    11  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  //  GNU Lesser General Public License for more details.
    14  //
    15  //  You should have received a copy of the GNU Lesser General Public License
    16  //  along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package core
    19  
    20  import (
    21  	"math/big"
    22  	"testing"
    23  )
    24  
    25  func TestParseInteger(t *testing.T) {
    26  	for i, tt := range []struct {
    27  		t   string
    28  		v   interface{}
    29  		exp *big.Int
    30  	}{
    31  		{"uint32", "-123", nil},
    32  		{"int32", "-123", big.NewInt(-123)},
    33  		{"uint32", "0xff", big.NewInt(0xff)},
    34  		{"int8", "0xffff", nil},
    35  	} {
    36  		res, err := parseInteger(tt.t, tt.v)
    37  		if tt.exp == nil && res == nil {
    38  			continue
    39  		}
    40  		if tt.exp == nil && res != nil {
    41  			t.Errorf("test %d, got %v, expected nil", i, res)
    42  			continue
    43  		}
    44  		if tt.exp != nil && res == nil {
    45  			t.Errorf("test %d, got '%v', expected %v", i, err, tt.exp)
    46  			continue
    47  		}
    48  		if tt.exp.Cmp(res) != 0 {
    49  			t.Errorf("test %d, got %v expected %v", i, res, tt.exp)
    50  		}
    51  	}
    52  }