shad-go/illegal/field_test.go
2023-10-03 20:25:41 +03:00

28 lines
583 B
Go

package illegal_test
import (
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/manytask/itmo-go/public/illegal"
"gitlab.com/manytask/itmo-go/public/illegal/internal"
)
func TestIllegalField(t *testing.T) {
var s internal.Struct
illegal.SetPrivateField(&s, "a", 10)
illegal.SetPrivateField(&s, "b", "foo")
illegal.SetPrivateField(&s, "p", internal.NewPrivateType(42))
assert.Equal(t, "10 foo 42", s.String())
}
func TestIllegalWrongFieldType(t *testing.T) {
var s internal.Struct
assert.Panics(t, func() {
illegal.SetPrivateField(&s, "a", "1234")
})
}