Skip to content

Commit

Permalink
Test each of the expression statements
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Sep 21, 2023
1 parent c5643b9 commit 5857563
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions compiler/desugar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ _l0:
`,
},
{
name: "decompose nested function calls",
name: "decompose expressions in expr statements",
body: "a(b(c(d(e(1 + 2)))))",
expect: `
{
Expand All @@ -1081,7 +1081,17 @@ _l0:
`,
},
{
name: "decompose expressions in decls",
name: "decompose expressions in incdec statements",
body: "a(b())++",
expect: `
{
_v0 := b()
a(_v0)++
}
`,
},
{
name: "decompose expressions in decl statements",
body: "var _, _ int = a(b(0)), c(d(1))",
// See https://go.dev/play/p/PkwoJbDLgQV for order of evaluation.
expect: `
Expand All @@ -1095,7 +1105,7 @@ _l0:
`,
},
{
name: "decompose expressions in assignments",
name: "decompose expressions in assignment statements",
body: "ints[a(b(0))], ints[c(d(1))] = e(f(10)), g(h(11))",
// See https://go.dev/play/p/WvrxhauFbsA for order of evaluation
expect: `
Expand All @@ -1110,6 +1120,33 @@ _l0:
_v6 := g(_v7)
ints[_v0], ints[_v2] = _v4, _v6
}
`,
},
{
name: "decompose expressions in return statements",
body: "return a(b(0)), c(d(1))",
// See https://go.dev/play/p/PkwoJbDLgQV for order of evaluation.
expect: `
{
_v1 := b(0)
_v0 := a(_v1)
_v3 := d(1)
_v2 := c(_v3)
return _v0, _v2
}
`,
},
{
name: "decompose expressions in send statements",
body: "a(b()) <- c(d())",
expect: `
{
_v1 := b()
_v0 := a(_v1)
_v3 := d()
_v2 := c(_v3)
_v0 <- _v2
}
`,
},
} {
Expand Down

0 comments on commit 5857563

Please sign in to comment.