Skip to content
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
6 changes: 3 additions & 3 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (c *checker) checkSelect(e *exprpb.Expr) {

// Interpret as field selection, first traversing down the operand.
c.check(sel.Operand)
targetType := c.getType(sel.Operand)
targetType := substitute(c.mappings, c.getType(sel.Operand), false)
// Assume error type by default as most types do not support field selection.
resultType := decls.Error
switch kindOf(targetType) {
Expand Down Expand Up @@ -224,7 +224,7 @@ func (c *checker) checkSelect(e *exprpb.Expr) {
if sel.TestOnly {
resultType = decls.Bool
}
c.setType(e, resultType)
c.setType(e, substitute(c.mappings, resultType, false))
}

func (c *checker) checkCall(e *exprpb.Expr) {
Expand Down Expand Up @@ -472,7 +472,7 @@ func (c *checker) checkComprehension(e *exprpb.Expr) {
c.check(comp.IterRange)
c.check(comp.AccuInit)
accuType := c.getType(comp.AccuInit)
rangeType := c.getType(comp.IterRange)
rangeType := substitute(c.mappings, c.getType(comp.IterRange), false)
var varType *exprpb.Type

switch kindOf(rangeType) {
Expand Down
55 changes: 55 additions & 0 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,61 @@ _&&_(_==_(list~type(list(dyn))^list,
__result__~list(list(list(int)))^__result__)~list(list(list(int)))
`,
},
{
in: `values.filter(i, i.content != "").map(i, i.content)`,
outType: decls.NewListType(decls.String),
env: testEnv{
idents: []*exprpb.Decl{
decls.NewVar("values", decls.NewListType(decls.NewMapType(decls.String, decls.String))),
},
},
out: `__comprehension__(
// Variable
i,
// Target
__comprehension__(
// Variable
i,
// Target
values~list(map(string, string))^values,
// Accumulator
__result__,
// Init
[]~list(map(string, string)),
// LoopCondition
true~bool,
// LoopStep
_?_:_(
_!=_(
i~map(string, string)^i.content~string,
""~string
)~bool^not_equals,
_+_(
__result__~list(map(string, string))^__result__,
[
i~map(string, string)^i
]~list(map(string, string))
)~list(map(string, string))^add_list,
__result__~list(map(string, string))^__result__
)~list(map(string, string))^conditional,
// Result
__result__~list(map(string, string))^__result__)~list(map(string, string)),
// Accumulator
__result__,
// Init
[]~list(string),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(string)^__result__,
[
i~map(string, string)^i.content~string
]~list(string)
)~list(string)^add_list,
// Result
__result__~list(string)^__result__)~list(string)`,
},
}

var testEnvs = map[string]testEnv{
Expand Down
20 changes: 10 additions & 10 deletions test/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import (
// Compare compares two strings, a for actual, e for expected, and returns true or false. The comparison is done,
// by filtering out whitespace (i.e. space, tabs and newline).
func Compare(a string, e string) bool {
a = strings.Replace(a, " ", "", -1)
a = strings.Replace(a, "\n", "", -1)
a = strings.Replace(a, "\t", "", -1)

e = strings.Replace(e, " ", "", -1)
e = strings.Replace(e, "\n", "", -1)
e = strings.Replace(e, "\t", "", -1)

return a == e
return stripWhitespace(a) == stripWhitespace(e)
}

// DiffMessage creates a diff dump message for test failures.
func DiffMessage(context string, actual interface{}, expected interface{}) string {
return fmt.Sprintf("%s: \ngot %q, \nwanted %q", context, actual, expected)
return fmt.Sprintf("%s: \ngot %q, \nwanted %q",
context, stripWhitespace(actual.(string)), stripWhitespace(expected.(string)))
}

func stripWhitespace(a string) string {
a = strings.Replace(a, " ", "", -1)
a = strings.Replace(a, "\n", "", -1)
a = strings.Replace(a, "\t", "", -1)
return strings.Replace(a, "\r", "", -1)
}