Skip to content

Commit

Permalink
refactor(check template): rename T so we can use it for copied data
Browse files Browse the repository at this point in the history
structure form stdlib
  • Loading branch information
crhntr committed Dec 21, 2024
1 parent 47170ef commit 383e40a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
44 changes: 22 additions & 22 deletions internal/check/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func TestTree(t *testing.T) {
{
Name: "when accessing nil on an empty struct",
Template: `{{.Field}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, err, _ error, tp types.Type) {
require.EqualError(t, err, fmt.Sprintf(`type check failed: template:1:2: Field not found on %s`, tp))
},
},
{
Name: "when accessing the dot",
Template: `{{.}}`,
Data: T{},
Data: Void{},
},
{
Name: "when a method does not any results",
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestTree(t *testing.T) {
{
Name: "source provided function",
Template: `{{square 5}}`,
Data: T{},
Data: Void{},
},
{
Name: "with expression",
Expand All @@ -317,7 +317,7 @@ func TestTree(t *testing.T) {
{
Name: "with expression has action with wrong dot type used in call",
Template: `{{with $x := "wrong"}}{{expectInt .}}{{else}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.ErrorContains(t, execErr, "wrong type for value; expected int; got string")
require.ErrorContains(t, checkErr, "expectInt argument 0 has type untyped string expected int")
Expand All @@ -326,12 +326,12 @@ func TestTree(t *testing.T) {
{
Name: "with else expression has action with correct dot type used in call",
Template: `{{with $x := 12}}{{with $x := 1.2}}{{else}}{{expectInt $x}}{{end}}{{end}}`,
Data: T{},
Data: Void{},
},
{
Name: "with else expression has action with wrong dot type used in call",
Template: `{{with $outer := 12}}{{with $x := true}}{{else}}{{expectString .}}{{end}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.NoError(t, execErr)
require.ErrorContains(t, checkErr, "expectString argument 0 has type untyped int expected string")
Expand All @@ -340,17 +340,17 @@ func TestTree(t *testing.T) {
{
Name: "complex number parses",
Template: `{{$x := 2i}}{{printf "%T" $x}}`,
Data: T{},
Data: Void{},
},
{
Name: "template node without parameter",
Template: `{{define "t"}}{{end}}{{template "t"}}`,
Data: T{},
Data: Void{},
},
{
Name: "template wrong input type",
Template: `{{define "t"}}{{expectInt .}}{{end}}{{if false}}{{template "t" 1.2}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.NoError(t, execErr)
require.ErrorContains(t, checkErr, "expectInt argument 0 has type float64 expected int")
Expand All @@ -359,7 +359,7 @@ func TestTree(t *testing.T) {
{
Name: "it downgrades untyped integers",
Template: `{{define "t"}}{{expectInt8 .}}{{end}}{{if false}}{{template "t" 12}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.NoError(t, execErr)
require.ErrorContains(t, checkErr, "expectInt8 argument 0 has type int expected int8")
Expand All @@ -368,7 +368,7 @@ func TestTree(t *testing.T) {
{
Name: "it downgrades untyped floats",
Template: `{{define "t"}}{{expectFloat32 .}}{{end}}{{if false}}{{template "t" 1.2}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.NoError(t, execErr)
require.ErrorContains(t, checkErr, "expectFloat32 argument 0 has type float64 expected float32")
Expand All @@ -377,7 +377,7 @@ func TestTree(t *testing.T) {
{
Name: "it downgrades untyped complex",
Template: `{{define "t"}}{{expectComplex64 .}}{{end}}{{if false}}{{template "t" 2i}}{{end}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.NoError(t, execErr)
require.ErrorContains(t, checkErr, "expectComplex64 argument 0 has type complex128 expected complex64")
Expand Down Expand Up @@ -410,19 +410,19 @@ func TestTree(t *testing.T) {
{
Name: "empty",
Template: "",
Data: T{},
Data: Void{},
},
// {"text", "some text", "some text", nil, true},
{
Name: "text",
Template: "some text",
Data: T{},
Data: Void{},
},
// {"nil action", "{{nil}}", "", nil, false},
{
Name: "nil action",
Template: `{{nil}}`,
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.ErrorContains(t, checkErr, strings.TrimPrefix(execErr.Error(), "template: "))
},
Expand All @@ -433,37 +433,37 @@ func TestTree(t *testing.T) {
{
Name: "ideal int",
Template: `{{expectInt 3}}`,
Data: T{},
Data: Void{},
},
// {"ideal float", "{{typeOf 1.0}}", "float64", 0, true},
{
Name: "ideal int",
Template: `{{expectFloat64 1.0}}}`,
Data: T{},
Data: Void{},
},
// {"ideal exp float", "{{typeOf 1e1}}", "float64", 0, true},
{
Name: "ideal float",
Template: `{{expectFloat64 1e1}}`,
Data: T{},
Data: Void{},
},
// {"ideal complex", "{{typeOf 1i}}", "complex128", 0, true},
{
Name: "ideal complex",
Template: `{{expectComplex128 1i}}`,
Data: T{},
Data: Void{},
},
// {"ideal int", "{{typeOf " + bigInt + "}}", "int", 0, true},
{
Name: "ideal big int",
Template: fmt.Sprintf(`{{expectInt 0x%x}}}`, 1<<uint(reflect.TypeFor[int]().Bits()-1)-1),
Data: T{},
Data: Void{},
},
// {"ideal too big", "{{typeOf " + bigUint + "}}", "", 0, false},
{
Name: "ideal too big",
Template: fmt.Sprintf(`{{expectInt 0x%x}}}`, uint(1<<uint(reflect.TypeFor[int]().Bits()-1))),
Data: T{},
Data: Void{},
Error: func(t *testing.T, checkErr, execErr error, tp types.Type) {
require.ErrorContains(t, execErr, "expected integer")
require.NoError(t, checkErr, "don't report this exec error")
Expand Down Expand Up @@ -530,7 +530,7 @@ func TestTree(t *testing.T) {
//{"*[]int[1]", "{{index .PSI 1}}", "22", tVal, true},
//{"NIL", "{{.NIL}}", "<nil>", tVal, true},
//
//// Empty interfaces holding values.
//// Void interfaces holding values.
//{"empty nil", "{{.Empty0}}", "<no value>", tVal, true},
//{"empty with int", "{{.Empty1}}", "3", tVal, true},
//{"empty with string", "{{.Empty2}}", "empty2", tVal, true},
Expand Down
36 changes: 18 additions & 18 deletions internal/check/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package check_test

import "math"

type T struct{}
type Void struct{}

type TypeWithMethodSignatureNoResultMethod struct{}

Expand Down Expand Up @@ -52,55 +52,55 @@ type StructWithFuncFieldWithResultWithMethod struct {

type MethodWithIntParam struct{}

func (MethodWithIntParam) F(int) (_ T) { return }
func (MethodWithIntParam) F(int) (_ Void) { return }

type MethodWithInt8Param struct{}

func (MethodWithInt8Param) F(int8) (_ T) { return }
func (MethodWithInt8Param) F(int8) (_ Void) { return }

type MethodWithInt16Param struct{}

func (MethodWithInt16Param) F(int16) (_ T) { return }
func (MethodWithInt16Param) F(int16) (_ Void) { return }

type MethodWithInt32Param struct{}

func (MethodWithInt32Param) F(int32) (_ T) { return }
func (MethodWithInt32Param) F(int32) (_ Void) { return }

type MethodWithInt64Param struct{}

func (MethodWithInt64Param) F(int64) (_ T) { return }
func (MethodWithInt64Param) F(int64) (_ Void) { return }

type MethodWithUintParam struct{}

func (MethodWithUintParam) F(uint) (_ T) { return }
func (MethodWithUintParam) F(uint) (_ Void) { return }

type MethodWithUint8Param struct{}

func (MethodWithUint8Param) F(uint8) (_ T) { return }
func (MethodWithUint8Param) F(uint8) (_ Void) { return }

type MethodWithUint16Param struct{}

func (MethodWithUint16Param) F(uint16) (_ T) { return }
func (MethodWithUint16Param) F(uint16) (_ Void) { return }

type MethodWithUint32Param struct{}

func (MethodWithUint32Param) F(uint32) (_ T) { return }
func (MethodWithUint32Param) F(uint32) (_ Void) { return }

type MethodWithUint64Param struct{}

func (MethodWithUint64Param) F(uint64) (_ T) { return }
func (MethodWithUint64Param) F(uint64) (_ Void) { return }

type MethodWithBoolParam struct{}

func (MethodWithBoolParam) F(bool) (_ T) { return }
func (MethodWithBoolParam) F(bool) (_ Void) { return }

type MethodWithFloat64Param struct{}

func (MethodWithFloat64Param) F(float64) (_ T) { return }
func (MethodWithFloat64Param) F(float64) (_ Void) { return }

type MethodWithFloat32Param struct{}

func (MethodWithFloat32Param) F(float32) (_ T) { return }
func (MethodWithFloat32Param) F(float32) (_ Void) { return }

type TypeWithMethodSignatureResultMethodWithFloat32Param struct{}

Expand All @@ -122,19 +122,19 @@ type MethodWithKeyValForSlices struct {
Numbers []float64
}

func (MethodWithKeyValForSlices) F(int, float64) (_ T) { return }
func (MethodWithKeyValForSlices) F(int, float64) (_ Void) { return }

type MethodWithKeyValForArray struct {
Numbers [2]float64
}

func (MethodWithKeyValForArray) F(int, float64) (_ T) { return }
func (MethodWithKeyValForArray) F(int, float64) (_ Void) { return }

type MethodWithKeyValForMap struct {
Numbers map[int16]float32
}

func (MethodWithKeyValForMap) F(int16, float32) (_ T) { return }
func (MethodWithKeyValForMap) F(int16, float32) (_ Void) { return }

func square(n int) int {
return n * n
Expand Down Expand Up @@ -169,6 +169,6 @@ type (
C LetterChainD
}
LetterChainD struct {
D T
D Void
}
)

0 comments on commit 383e40a

Please sign in to comment.