-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathcsharp_interface_impl_test.go
More file actions
38 lines (32 loc) · 1.16 KB
/
Copy pathcsharp_interface_impl_test.go
File metadata and controls
38 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package languages
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
// TestCSharpExtractor_ExplicitInterfaceImpl locks the explicit interface
// implementation shape `void IFoo.Bar() {}`: the grammar keeps the name a
// bare identifier ("Bar") with the IFoo. qualifier as a separate
// explicit_interface_specifier child, so the method is extracted and
// owned by the *class* (C.Bar) — distinct from the interface's own
// declaration node (IFoo.Bar), not dropped and not fused with it.
func TestCSharpExtractor_ExplicitInterfaceImpl(t *testing.T) {
src := []byte(`public interface IFoo {
void Bar();
}
public class C : IFoo {
void IFoo.Bar() { }
}
`)
result, err := NewCSharpExtractor().Extract("X.cs", src)
require.NoError(t, err)
ids := map[string]bool{}
for _, m := range nodesOfKind(result.Nodes, graph.KindMethod) {
ids[m.ID] = true
}
assert.True(t, ids["X.cs::C.Bar"],
"explicit interface impl `void IFoo.Bar()` must be a method owned by class C")
assert.True(t, ids["X.cs::IFoo.Bar"],
"the interface's own declaration keeps its member node alongside the impl")
}