Skip to content

Commit

Permalink
add tests for AddValueToListAttribute (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
swolchok authored and pmbethe09 committed Jun 22, 2017
1 parent 7ce605f commit eaf5ad1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions edit/edit_test.go
Expand Up @@ -131,3 +131,36 @@ load("other loc", "symbol")`,
}
}
}

func TestAddValueToListAttribute(t *testing.T) {
tests := []struct{ input, expected string }{
{`rule(name="rule")`, `rule(name="rule", attr=["foo"])`},
{`rule(name="rule", attr=["foo"])`, `rule(name="rule", attr=["foo"])`},
{`rule(name="rule", attr=IDENT)`, `rule(name="rule", attr=IDENT+["foo"])`},
{`rule(name="rule", attr=["foo"] + IDENT)`, `rule(name="rule", attr=["foo"] + IDENT)`},
{`rule(name="rule", attr=["bar"] + IDENT)`, `rule(name="rule", attr=["bar", "foo"] + IDENT)`},
{`rule(name="rule", attr=IDENT + ["foo"])`, `rule(name="rule", attr=IDENT + ["foo"])`},
{`rule(name="rule", attr=IDENT + ["bar"])`, `rule(name="rule", attr=IDENT + ["bar", "foo"])`},
}

for _, tst := range tests {
bld, err := build.Parse("BUILD", []byte(tst.input))
if err != nil {
t.Error(err)
continue
}
rule := bld.RuleAt(1)
AddValueToListAttribute(rule, "attr", "", &build.StringExpr{Value: "foo"}, nil)
got := strings.TrimSpace(string(build.Format(bld)))

wantBld, err := build.Parse("BUILD", []byte(tst.expected))
if err != nil {
t.Error(err)
continue
}
want := strings.TrimSpace(string(build.Format(wantBld)))
if got != want {
t.Errorf("AddValueToListAttribute(%s): got %s, expected %s", tst.input, got, want)
}
}
}

0 comments on commit eaf5ad1

Please sign in to comment.