MCPcopy Create free account
hub / github.com/goadesign/goa / TestPrimitiveIsCompatible

Function TestPrimitiveIsCompatible

expr/types_test.go:550–704  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

548}
549
550func TestPrimitiveIsCompatible(t *testing.T) {
551 var (
552 b = bool(true)
553 i = int(1)
554 i8 = int8(2)
555 i16 = int16(3)
556 i32 = int32(4)
557 ui = uint(5)
558 ui8 = uint8(6)
559 ui16 = uint16(7)
560 ui32 = uint32(8)
561 i64 = int64(9)
562 ui64 = uint64(10)
563 f32 = float32(10.1)
564 f64 = float64(20.2)
565 s = string("string")
566 bs = []byte("bytes")
567 ss = []string{"foo", "bar"}
568 is = []int{1, 2}
569 )
570 cases := map[string]struct {
571 p Primitive
572 values []any
573 expected bool
574 }{
575 "any": {
576 p: Any,
577 values: []any{b},
578 expected: true,
579 },
580 "boolean compatible": {
581 p: Boolean,
582 values: []any{b},
583 expected: true,
584 },
585 "boolean not compatible": {
586 p: Boolean,
587 values: []any{i, i8, i16, i32, ui, ui8, ui16, ui32, i64, ui64, f32, f64, s, bs},
588 expected: false,
589 },
590 "int compatible": {
591 p: Int,
592 values: []any{i, i8, i16, i32, ui, ui8, ui16, ui32},
593 expected: true,
594 },
595 "int not compatible": {
596 p: Int,
597 values: []any{b, i64, ui64, f32, f64, s, bs},
598 expected: false,
599 },
600 "int32 compatible": {
601 p: Int32,
602 values: []any{i, i8, i16, i32, ui, ui8, ui16, ui32},
603 expected: true,
604 },
605 "int32 not compatible": {
606 p: Int32,
607 values: []any{b, i64, ui64, f32, f64, s, bs},

Callers

nothing calls this directly

Calls 1

IsCompatibleMethod · 0.65

Tested by

no test coverage detected