Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve result variable #3589

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions runtime/ast/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,13 @@ func (c *EmitCondition) Walk(walkChild func(Element)) {

// Conditions

type Conditions []Condition
type Conditions struct {
Conditions []Condition
Range
}

func (c *Conditions) IsEmpty() bool {
return c == nil || len(*c) == 0
return c == nil || len(c.Conditions) == 0
}

func (c *Conditions) Doc(keywordDoc prettier.Doc) prettier.Doc {
Expand All @@ -368,7 +371,7 @@ func (c *Conditions) Doc(keywordDoc prettier.Doc) prettier.Doc {

var doc prettier.Concat

for _, condition := range *c {
for _, condition := range c.Conditions {
doc = append(
doc,
prettier.HardLine{},
Expand All @@ -395,7 +398,7 @@ func (c *Conditions) Walk(walkChild func(Element)) {
return
}

for _, condition := range *c {
for _, condition := range c.Conditions {
walkChild(condition)
}
}
236 changes: 132 additions & 104 deletions runtime/ast/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,45 +220,57 @@ func TestFunctionBlock_MarshalJSON(t *testing.T) {
},
},
PreConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: false,
Range: Range{
StartPos: Position{Offset: 7, Line: 8, Column: 9},
EndPos: Position{Offset: 10, Line: 11, Column: 12},
Range: Range{
StartPos: Position{Offset: 44, Line: 45, Column: 46},
EndPos: Position{Offset: 47, Line: 48, Column: 49},
},
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: false,
Range: Range{
StartPos: Position{Offset: 7, Line: 8, Column: 9},
EndPos: Position{Offset: 10, Line: 11, Column: 12},
},
},
},
Message: &StringExpression{
Value: "Pre failed",
Range: Range{
StartPos: Position{Offset: 13, Line: 14, Column: 15},
EndPos: Position{Offset: 16, Line: 17, Column: 18},
Message: &StringExpression{
Value: "Pre failed",
Range: Range{
StartPos: Position{Offset: 13, Line: 14, Column: 15},
EndPos: Position{Offset: 16, Line: 17, Column: 18},
},
},
},
},
&EmitCondition{
InvocationExpression: &InvocationExpression{
InvokedExpression: &IdentifierExpression{
Identifier: Identifier{
Identifier: "foobar",
Pos: Position{Offset: 31, Line: 32, Column: 33},
&EmitCondition{
InvocationExpression: &InvocationExpression{
InvokedExpression: &IdentifierExpression{
Identifier: Identifier{
Identifier: "foobar",
Pos: Position{Offset: 31, Line: 32, Column: 33},
},
},
TypeArguments: []*TypeAnnotation{},
Arguments: []*Argument{},
ArgumentsStartPos: Position{Offset: 34, Line: 35, Column: 36},
EndPos: Position{Offset: 37, Line: 38, Column: 39},
},
TypeArguments: []*TypeAnnotation{},
Arguments: []*Argument{},
ArgumentsStartPos: Position{Offset: 34, Line: 35, Column: 36},
EndPos: Position{Offset: 37, Line: 38, Column: 39},
StartPos: Position{Offset: 40, Line: 41, Column: 42},
},
StartPos: Position{Offset: 40, Line: 41, Column: 42},
},
},
PostConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: true,
Range: Range{
StartPos: Position{Offset: 19, Line: 20, Column: 21},
EndPos: Position{Offset: 22, Line: 23, Column: 24},
Range: Range{
StartPos: Position{Offset: 50, Line: 51, Column: 52},
EndPos: Position{Offset: 53, Line: 54, Column: 55},
},
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: true,
Range: Range{
StartPos: Position{Offset: 19, Line: 20, Column: 21},
EndPos: Position{Offset: 22, Line: 23, Column: 24},
},
},
},
},
Expand All @@ -279,62 +291,70 @@ func TestFunctionBlock_MarshalJSON(t *testing.T) {
"StartPos": {"Offset": 1, "Line": 2, "Column": 3},
"EndPos": {"Offset": 4, "Line": 5, "Column": 6}
},
"PreConditions": [
{
"Type": "TestCondition",
"Test": {
"Type": "BoolExpression",
"Value": false,
"PreConditions": {
"StartPos": {"Offset": 44, "Line": 45, "Column": 46},
"EndPos": {"Offset": 47, "Line": 48, "Column": 49},
"Conditions": [
{
"Type": "TestCondition",
"Test": {
"Type": "BoolExpression",
"Value": false,
"StartPos": {"Offset": 7, "Line": 8, "Column": 9},
"EndPos": {"Offset": 10, "Line": 11, "Column": 12}
},
"Message": {
"Type": "StringExpression",
"Value": "Pre failed",
"StartPos": {"Offset": 13, "Line": 14, "Column": 15},
"EndPos": {"Offset": 16, "Line": 17, "Column": 18}
},
"StartPos": {"Offset": 7, "Line": 8, "Column": 9},
"EndPos": {"Offset": 10, "Line": 11, "Column": 12}
},
"Message": {
"Type": "StringExpression",
"Value": "Pre failed",
"StartPos": {"Offset": 13, "Line": 14, "Column": 15},
"EndPos": {"Offset": 16, "Line": 17, "Column": 18}
},
"StartPos": {"Offset": 7, "Line": 8, "Column": 9},
"EndPos": {"Offset": 16, "Line": 17, "Column": 18}
},
{
"Type": "EmitCondition",
"InvocationExpression": {
"Type": "InvocationExpression",
"InvokedExpression": {
"Type": "IdentifierExpression",
"Identifier": {
"Identifier": "foobar",
{
"Type": "EmitCondition",
"InvocationExpression": {
"Type": "InvocationExpression",
"InvokedExpression": {
"Type": "IdentifierExpression",
"Identifier": {
"Identifier": "foobar",
"StartPos": {"Offset": 31, "Line": 32, "Column": 33},
"EndPos": {"Offset": 36, "Line": 32, "Column": 38}
},
"StartPos": {"Offset": 31, "Line": 32, "Column": 33},
"EndPos": {"Offset": 36, "Line": 32, "Column": 38}
},
"StartPos": {"Offset": 31, "Line": 32, "Column": 33},
"EndPos": {"Offset": 36, "Line": 32, "Column": 38}
},
"TypeArguments": [],
"Arguments": [],
"ArgumentsStartPos": {"Offset": 34, "Line": 35, "Column": 36},
"StartPos": {"Offset": 31, "Line": 32, "Column": 33},
"EndPos": {"Offset": 37, "Line": 38, "Column": 39}
},
"TypeArguments": [],
"Arguments": [],
"ArgumentsStartPos": {"Offset": 34, "Line": 35, "Column": 36},
"StartPos": {"Offset": 31, "Line": 32, "Column": 33},
"StartPos": {"Offset": 40, "Line": 41, "Column": 42},
"EndPos": {"Offset": 37, "Line": 38, "Column": 39}
},
"StartPos": {"Offset": 40, "Line": 41, "Column": 42},
"EndPos": {"Offset": 37, "Line": 38, "Column": 39}
}
],
"PostConditions": [
{
"Type": "TestCondition",
"Test": {
"Type": "BoolExpression",
"Value": true,
}
]
},
"PostConditions": {
"StartPos": {"Offset": 50, "Line": 51, "Column": 52},
"EndPos": {"Offset": 53, "Line": 54, "Column": 55},
"Conditions": [
{
"Type": "TestCondition",
"Test": {
"Type": "BoolExpression",
"Value": true,
"StartPos": {"Offset": 19, "Line": 20, "Column": 21},
"EndPos": {"Offset": 22, "Line": 23, "Column": 24}
},
"Message": null,
"StartPos": {"Offset": 19, "Line": 20, "Column": 21},
"EndPos": {"Offset": 22, "Line": 23, "Column": 24}
},
"Message": null,
"StartPos": {"Offset": 19, "Line": 20, "Column": 21},
"EndPos": {"Offset": 22, "Line": 23, "Column": 24}
}
],
}
]
},
"StartPos": {"Offset": 1, "Line": 2, "Column": 3},
"EndPos": {"Offset": 4, "Line": 5, "Column": 6}
}
Expand Down Expand Up @@ -407,28 +427,32 @@ func TestFunctionBlock_Doc(t *testing.T) {
},
},
PreConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: false,
},
Message: &StringExpression{
Value: "Pre failed",
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: false,
},
Message: &StringExpression{
Value: "Pre failed",
},
},
},
&EmitCondition{
InvocationExpression: &InvocationExpression{
InvokedExpression: &IdentifierExpression{
Identifier: Identifier{
Identifier: "Foo",
&EmitCondition{
InvocationExpression: &InvocationExpression{
InvokedExpression: &IdentifierExpression{
Identifier: Identifier{
Identifier: "Foo",
},
},
},
},
},
},
PostConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: true,
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: true,
},
},
},
},
Expand Down Expand Up @@ -561,22 +585,26 @@ func TestFunctionBlock_String(t *testing.T) {
},
},
PreConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: false,
},
Message: &StringExpression{
Value: "Pre failed",
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: false,
},
Message: &StringExpression{
Value: "Pre failed",
},
},
},
},
PostConditions: &Conditions{
&TestCondition{
Test: &BoolExpression{
Value: true,
},
Message: &StringExpression{
Value: "Post failed",
Conditions: []Condition{
&TestCondition{
Test: &BoolExpression{
Value: true,
},
Message: &StringExpression{
Value: "Post failed",
},
},
},
},
Expand Down
Loading
Loading