2021-04-14 15:41:01 +00:00
|
|
|
package illegal_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-04-17 15:28:33 +00:00
|
|
|
|
2023-10-02 19:32:41 +00:00
|
|
|
"gitlab.com/manytask/itmo-go/private/illegal"
|
|
|
|
"gitlab.com/manytask/itmo-go/private/illegal/internal"
|
2021-04-14 15:41:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIllegalField(t *testing.T) {
|
|
|
|
var s internal.Struct
|
|
|
|
|
|
|
|
illegal.SetPrivateField(&s, "a", 10)
|
|
|
|
illegal.SetPrivateField(&s, "b", "foo")
|
2023-04-23 10:55:18 +00:00
|
|
|
illegal.SetPrivateField(&s, "p", internal.NewPrivateType(42))
|
2021-04-14 15:41:01 +00:00
|
|
|
|
2023-04-23 10:55:18 +00:00
|
|
|
assert.Equal(t, "10 foo 42", s.String())
|
2021-04-14 15:41:01 +00:00
|
|
|
}
|
2023-04-23 09:26:15 +00:00
|
|
|
|
|
|
|
func TestIllegalWrongFieldType(t *testing.T) {
|
|
|
|
var s internal.Struct
|
|
|
|
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
illegal.SetPrivateField(&s, "a", "1234")
|
|
|
|
})
|
|
|
|
}
|