github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/compiler/byte_conversion_test.go (about)

     1  package compiler_test
     2  
     3  import "testing"
     4  
     5  func TestStringToByteConversion(t *testing.T) {
     6  	src := `
     7  	package foo
     8  	func Main() []byte {
     9  		b := []byte("foo")
    10  		return b
    11  	}
    12  	`
    13  	eval(t, src, []byte("foo"))
    14  }
    15  
    16  func TestStringToByteAppend(t *testing.T) {
    17  	src := `
    18  	package foo
    19  	func Main() []byte {
    20  		b := []byte("foo")
    21  		c := []byte("bar")
    22  		e := append(b, c...)
    23  		return e
    24  	}
    25  	`
    26  	eval(t, src, []byte("foobar"))
    27  }
    28  
    29  func TestByteConversionInFunctionCall(t *testing.T) {
    30  	src := `
    31  	package foo
    32  	func Main() []byte {
    33  		b := []byte("foo")
    34  		return handle(b)
    35  	}
    36  
    37  	func handle(b []byte) []byte {
    38  		return b
    39  	}
    40  	`
    41  	eval(t, src, []byte("foo"))
    42  }
    43  
    44  func TestByteConversionDirectlyInFunctionCall(t *testing.T) {
    45  	src := `
    46  	package foo
    47  	func Main() []byte {
    48  		return handle([]byte("foo"))
    49  	}
    50  
    51  	func handle(b []byte) []byte {
    52  		return b
    53  	}
    54  	`
    55  	eval(t, src, []byte("foo"))
    56  }
    57  
    58  func TestByteConversionOfConstant(t *testing.T) {
    59  	src := `
    60  	package foo
    61  	const foo = "foo"
    62  	func Main() []byte {
    63  		b := []byte(foo)
    64  		return b
    65  	}
    66  	`
    67  	eval(t, src, []byte("foo"))
    68  }
    69  
    70  func TestByteConversionOfVariable(t *testing.T) {
    71  	src := `
    72  	package foo
    73  	func Main() []byte {
    74  		a := "fo"
    75  		a = a + "o"
    76  		b := []byte(a)
    77  		return b
    78  	}
    79  	`
    80  	eval(t, src, []byte("foo"))
    81  }