From fd9193b17dbd3bd47c964337aa0b4578bc481eb7 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 10 Mar 2023 18:05:55 +0000 Subject: [PATCH] decoder: Update legacy tests for ObjectExpr --- decoder/expression_candidates_legacy_test.go | 64 +++-- decoder/hover_expressions_legacy_test.go | 236 +++++++++---------- decoder/semantic_tokens_expr_legacy_test.go | 20 +- 3 files changed, 150 insertions(+), 170 deletions(-) diff --git a/decoder/expression_candidates_legacy_test.go b/decoder/expression_candidates_legacy_test.go index 260ba24c..cd2835c8 100644 --- a/decoder/expression_candidates_legacy_test.go +++ b/decoder/expression_candidates_legacy_test.go @@ -132,15 +132,13 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) { "object as expression", map[string]*schema.AttributeSchema{ "attr": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "first": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "second": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "first": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "second": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Number}, }, }, }, @@ -179,15 +177,13 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) { "object as expression - attribute", map[string]*schema.AttributeSchema{ "attr": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "first": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "second": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "first": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "second": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Number}, }, }, }, @@ -249,15 +245,13 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) { "object as expression - attributes partially declared", map[string]*schema.AttributeSchema{ "attr": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "first": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "second": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "first": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "second": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Number}, }, }, }, @@ -298,15 +292,13 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) { "object as expression - attribute key unknown", map[string]*schema.AttributeSchema{ "attr": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "first": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "second": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "first": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "second": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Number}, }, }, }, diff --git a/decoder/hover_expressions_legacy_test.go b/decoder/hover_expressions_legacy_test.go index c4c4ed1e..47b9d3b1 100644 --- a/decoder/hover_expressions_legacy_test.go +++ b/decoder/hover_expressions_legacy_test.go @@ -310,31 +310,29 @@ _object_`), { "list of object expressions", map[string]*schema.AttributeSchema{ - "objects": {Expr: schema.ExprConstraints{ - schema.ListExpr{ - Elem: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), - }, - "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), - }, - "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), - }, + "objects": { + Constraint: schema.List{ + Elem: schema.Object{ + Attributes: schema.ObjectAttributes{ + "source": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "bool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Bool}, + }, + "notbool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "nested_map": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, + }, + "nested_obj": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, }, - }}, + }, }, `objects = [ { @@ -366,31 +364,29 @@ _object_`), { "list of object expressions element", map[string]*schema.AttributeSchema{ - "objects": {Expr: schema.ExprConstraints{ - schema.ListExpr{ - Elem: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), - }, - "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), - }, - "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), - }, + "objects": { + Constraint: schema.List{ + Elem: schema.Object{ + Attributes: schema.ObjectAttributes{ + "source": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "bool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Bool}, + }, + "notbool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "nested_map": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, + }, + "nested_obj": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, }, - }}, + }, }, `objects = [ { @@ -422,35 +418,33 @@ _object_`), { "nested object expression", map[string]*schema.AttributeSchema{ - "object": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "object": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "nested": &schema.AttributeSchema{ - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), - }, - "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), - }, - "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "source": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "bool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Bool}, + }, + "notbool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "nested_map": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, + }, + "nested_obj": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, }, }, }, - }}, + }, }, `object = { nested = { @@ -492,35 +486,33 @@ _object_`), { "nested object expression inside", map[string]*schema.AttributeSchema{ - "object": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "object": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "nested": &schema.AttributeSchema{ - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), - }, - "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), - }, - "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), - }, - "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "source": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "bool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Bool}, + }, + "notbool": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.String}, + }, + "nested_map": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, + }, + "nested_obj": &schema.AttributeSchema{ + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, }, }, }, - }}, + }, }, `object = { nested = { @@ -552,27 +544,27 @@ _object_`), { "object as expression", map[string]*schema.AttributeSchema{ - "obj": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "obj": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), + Constraint: schema.LiteralType{Type: cty.Bool}, }, "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, }, "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, - }}, + }, }, `obj = { source = "blah" @@ -602,27 +594,27 @@ _object_`), { "object as expression with unknown key", map[string]*schema.AttributeSchema{ - "obj": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "obj": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), + Constraint: schema.LiteralType{Type: cty.Bool}, }, "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, }, "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, - }}, + }, }, `obj = { var.src = "blah" @@ -653,27 +645,27 @@ _object_`), { "object as expression - expression", map[string]*schema.AttributeSchema{ - "obj": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "obj": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), + Constraint: schema.LiteralType{Type: cty.Bool}, }, "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, }, "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, - }}, + }, }, `obj = { source = "blah" @@ -712,27 +704,27 @@ _object_`), { "object as expression - attribute", map[string]*schema.AttributeSchema{ - "obj": {Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ + "obj": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ "source": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "bool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Bool), + Constraint: schema.LiteralType{Type: cty.Bool}, }, "notbool": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.String), + Constraint: schema.LiteralType{Type: cty.String}, }, "nested_map": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Map(cty.String)), + Constraint: schema.LiteralType{Type: cty.Map(cty.String)}, }, "nested_obj": &schema.AttributeSchema{ - Expr: schema.LiteralTypeOnly(cty.Object(map[string]cty.Type{})), + Constraint: schema.LiteralType{Type: cty.Object(map[string]cty.Type{})}, }, }, }, - }}, + }, }, `obj = { source = "blah" diff --git a/decoder/semantic_tokens_expr_legacy_test.go b/decoder/semantic_tokens_expr_legacy_test.go index a21c1419..11386450 100644 --- a/decoder/semantic_tokens_expr_legacy_test.go +++ b/decoder/semantic_tokens_expr_legacy_test.go @@ -433,12 +433,10 @@ EOT "object as expression", map[string]*schema.AttributeSchema{ "obj": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "knownkey": { - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "knownkey": { + Constraint: schema.LiteralType{Type: cty.Number}, }, }, }, @@ -506,12 +504,10 @@ EOT "object as expression with unknown key", map[string]*schema.AttributeSchema{ "obj": { - Expr: schema.ExprConstraints{ - schema.ObjectExpr{ - Attributes: schema.ObjectExprAttributes{ - "knownkey": { - Expr: schema.LiteralTypeOnly(cty.Number), - }, + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "knownkey": { + Constraint: schema.LiteralType{Type: cty.Number}, }, }, },