Skip to content

Commit

Permalink
add doc comment and tests for ast.ContainsExpression function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 9, 2024
1 parent 0b34b0f commit 053a36a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type String struct {
Pos *Pos
}

// ContainsExpression checks if the given string contains a ${{ }} placeholder or not. This function
// is identical to String.ContainsExpression method except for taking a standard string value.
func ContainsExpression(s string) bool {
i := strings.Index(s, "${{")
return i >= 0 && i < strings.Index(s, "}}")
Expand Down
8 changes: 5 additions & 3 deletions ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func TestStringContainsExpression(t *testing.T) {
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
s := &String{Value: tc.input}
have := s.ContainsExpression()
if tc.want != have {
t.Fatalf("wanted %v but got %v for input %q", tc.want, have, tc.input)
if have := s.ContainsExpression(); tc.want != have {
t.Fatalf("wanted %v but the method returned %v for input %q", tc.want, have, tc.input)
}
if have := ContainsExpression(tc.input); tc.want != have {
t.Fatalf("wanted %v but the function returned %v for input %q", tc.want, have, tc.input)
}
})
}
Expand Down

0 comments on commit 053a36a

Please sign in to comment.