| 24 | ) |
| 25 | |
| 26 | func TestScopeSubScope(t *testing.T) { |
| 27 | var ( |
| 28 | root = NewScope() |
| 29 | sub1 = root.SubScope("x") |
| 30 | sub2 = root.SubScope("x") |
| 31 | sub1a = sub1.SubScope("y") |
| 32 | sub2a = sub2.SubScope("y") |
| 33 | ) |
| 34 | testdata := []struct { |
| 35 | scope *Scope |
| 36 | name string |
| 37 | }{ |
| 38 | {root, "Const"}, |
| 39 | {sub1, "x/Const"}, |
| 40 | {sub1a, "x/y/Const"}, |
| 41 | {sub2, "x_1/Const"}, |
| 42 | {sub2a, "x_1/y/Const"}, |
| 43 | } |
| 44 | for _, test := range testdata { |
| 45 | c := Const(test.scope, int64(1)) |
| 46 | if err := test.scope.Err(); err != nil { |
| 47 | t.Fatalf("%q: %v", test.name, err) |
| 48 | } |
| 49 | if got := c.Op.Name(); got != test.name { |
| 50 | t.Errorf("%q: Got %q", test.name, got) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestScopeSubScopeErrors(t *testing.T) { |
| 56 | var ( |