|
1 | 1 | import { describe, test, expect, beforeEach } from "vitest"; |
2 | 2 | import Parser from "tree-sitter"; |
3 | 3 | import { CsharpExportResolver } from "."; |
4 | | -import { csharpParser } from "../../../helpers/treeSitter/parsers"; |
| 4 | +import { getCSharpFilesMap } from "../testFiles"; |
5 | 5 |
|
6 | 6 | describe("CsharpExportResolver", () => { |
7 | 7 | let resolver: CsharpExportResolver; |
8 | 8 | let files: Map<string, { path: string; rootNode: Parser.SyntaxNode }>; |
9 | 9 |
|
10 | 10 | beforeEach(() => { |
11 | 11 | try { |
12 | | - files = new Map([ |
13 | | - [ |
14 | | - "project/MyClass.cs", |
15 | | - { |
16 | | - path: "project/MyClass.cs", |
17 | | - rootNode: csharpParser.parse(` |
18 | | - public class MyClass |
19 | | - { |
20 | | - } |
21 | | - `).rootNode, |
22 | | - }, |
23 | | - ], |
24 | | - [ |
25 | | - "project/Models.cs", |
26 | | - { |
27 | | - path: "project/Models.cs", |
28 | | - rootNode: csharpParser.parse(` |
29 | | - public class User |
30 | | - { |
31 | | - public string Name { get; set; } |
32 | | - } |
33 | | - public struct Order |
34 | | - { |
35 | | - public int OrderId; |
36 | | - public string Description; |
37 | | - } |
38 | | - public enum OrderStatus |
39 | | - { |
40 | | - Pending, |
41 | | - Completed |
42 | | - } |
43 | | - `).rootNode, |
44 | | - }, |
45 | | - ], |
46 | | - [ |
47 | | - "project/empty.cs", |
48 | | - { |
49 | | - path: "project/empty.cs", |
50 | | - rootNode: csharpParser.parse("").rootNode, |
51 | | - }, |
52 | | - ], |
53 | | - ]); |
| 12 | + files = getCSharpFilesMap(); |
54 | 13 | resolver = new CsharpExportResolver(files); |
55 | 14 | } catch (error) { |
56 | 15 | console.error("Error in beforeEach:", error); |
57 | 16 | throw error; |
58 | 17 | } |
59 | 18 | }); |
60 | 19 |
|
61 | | - test("MyClass.cs", () => { |
| 20 | + test("Namespaced.cs", () => { |
62 | 21 | try { |
63 | | - const symbols = resolver.getSymbols("project/MyClass.cs"); |
64 | | - expect(symbols).toMatchObject([ |
65 | | - { |
66 | | - id: "MyClass", |
67 | | - identifierNode: { text: "MyClass" }, |
68 | | - type: "class", |
69 | | - }, |
70 | | - ]); |
| 22 | + const symbols = resolver.getSymbols("Namespaced.cs"); |
| 23 | + expect(symbols).toEqual( |
| 24 | + expect.arrayContaining([ |
| 25 | + { |
| 26 | + id: "MyClass", |
| 27 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 28 | + identifierNode: expect.objectContaining({ text: "MyClass" }), |
| 29 | + type: "class", |
| 30 | + }, |
| 31 | + ]), |
| 32 | + ); |
71 | 33 | } catch (error) { |
72 | | - console.error("Error in test MyClass.cs:", error); |
| 34 | + console.error("Error in test Namespaced.cs:", error); |
73 | 35 | throw error; |
74 | 36 | } |
75 | 37 | }); |
76 | 38 |
|
77 | 39 | test("Models.cs", () => { |
78 | 40 | try { |
79 | | - const symbols = resolver.getSymbols("project/Models.cs"); |
80 | | - expect(symbols).toMatchObject([ |
81 | | - { |
82 | | - id: "User", |
83 | | - identifierNode: { text: "User" }, |
84 | | - type: "class", |
85 | | - }, |
86 | | - { |
87 | | - id: "Order", |
88 | | - identifierNode: { text: "Order" }, |
89 | | - type: "class", |
90 | | - }, |
91 | | - { |
92 | | - id: "OrderStatus", |
93 | | - identifierNode: { text: "OrderStatus" }, |
94 | | - type: "class", |
95 | | - }, |
96 | | - ]); |
| 41 | + const symbols = resolver.getSymbols("Models.cs"); |
| 42 | + expect(symbols).toEqual( |
| 43 | + expect.arrayContaining([ |
| 44 | + { |
| 45 | + id: "User", |
| 46 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 47 | + identifierNode: expect.objectContaining({ text: "User" }), |
| 48 | + type: "class", |
| 49 | + }, |
| 50 | + { |
| 51 | + id: "Order", |
| 52 | + node: expect.objectContaining({ type: "struct_declaration" }), |
| 53 | + identifierNode: expect.objectContaining({ text: "Order" }), |
| 54 | + type: "struct", |
| 55 | + }, |
| 56 | + { |
| 57 | + id: "OrderStatus", |
| 58 | + node: expect.objectContaining({ type: "enum_declaration" }), |
| 59 | + identifierNode: expect.objectContaining({ text: "OrderStatus" }), |
| 60 | + type: "enum", |
| 61 | + }, |
| 62 | + ]), |
| 63 | + ); |
97 | 64 | } catch (error) { |
98 | 65 | console.error("Error in test Models.cs:", error); |
99 | 66 | throw error; |
100 | 67 | } |
101 | 68 | }); |
102 | 69 |
|
103 | | - test("empty.cs", () => { |
| 70 | + test("Variables.cs", () => { |
| 71 | + try { |
| 72 | + const symbols = resolver.getSymbols("Variables.cs"); |
| 73 | + expect(symbols).toEqual( |
| 74 | + expect.arrayContaining([ |
| 75 | + { |
| 76 | + id: "FarWest", |
| 77 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 78 | + identifierNode: expect.objectContaining({ text: "FarWest" }), |
| 79 | + type: "class", |
| 80 | + }, |
| 81 | + { |
| 82 | + id: "EastCoast", |
| 83 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 84 | + identifierNode: expect.objectContaining({ text: "EastCoast" }), |
| 85 | + type: "class", |
| 86 | + }, |
| 87 | + ]), |
| 88 | + ); |
| 89 | + } catch (error) { |
| 90 | + console.error("Error in test Variables.cs:", error); |
| 91 | + throw error; |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + test("SemiNamespaced.cs", () => { |
104 | 96 | try { |
105 | | - const symbols = resolver.getSymbols("project/empty.cs"); |
106 | | - expect(symbols).toEqual([]); |
| 97 | + const symbols = resolver.getSymbols("SemiNamespaced.cs"); |
| 98 | + expect(symbols).toEqual( |
| 99 | + expect.arrayContaining([ |
| 100 | + { |
| 101 | + id: "Gordon", |
| 102 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 103 | + identifierNode: expect.objectContaining({ text: "Gordon" }), |
| 104 | + type: "class", |
| 105 | + }, |
| 106 | + { |
| 107 | + id: "Freeman", |
| 108 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 109 | + identifierNode: expect.objectContaining({ text: "Freeman" }), |
| 110 | + type: "class", |
| 111 | + }, |
| 112 | + { |
| 113 | + id: "HeadCrab", |
| 114 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 115 | + identifierNode: expect.objectContaining({ text: "HeadCrab" }), |
| 116 | + type: "class", |
| 117 | + }, |
| 118 | + ]), |
| 119 | + ); |
107 | 120 | } catch (error) { |
108 | | - console.error("Error in test empty.cs:", error); |
| 121 | + console.error("Error in test SemiNamespaced.cs:", error); |
109 | 122 | throw error; |
110 | 123 | } |
111 | 124 | }); |
112 | 125 |
|
113 | | - test("Nested.cs", () => { |
| 126 | + test("IWillOnlyImportHalf.cs", () => { |
114 | 127 | try { |
115 | | - const symbols = resolver.getSymbols("project/Nested.cs"); |
116 | | - expect(symbols).toMatchObject([ |
117 | | - { |
118 | | - id: "OuterClass", |
119 | | - identifierNode: { text: "OuterClass" }, |
120 | | - type: "class", |
121 | | - }, |
122 | | - { |
123 | | - id: "InnerClass", |
124 | | - identifierNode: { text: "InnerClass" }, |
125 | | - type: "class", |
126 | | - }, |
127 | | - { |
128 | | - id: "InnerMethod", |
129 | | - identifierNode: { text: "InnerMethod" }, |
130 | | - type: "method", |
131 | | - }, |
132 | | - { |
133 | | - id: "OuterMethod", |
134 | | - identifierNode: { text: "OuterMethod" }, |
135 | | - type: "method", |
136 | | - }, |
137 | | - ]); |
| 128 | + const symbols = resolver.getSymbols("IWillOnlyImportHalf.cs"); |
| 129 | + expect(symbols).toEqual( |
| 130 | + expect.arrayContaining([ |
| 131 | + { |
| 132 | + id: "Steak", |
| 133 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 134 | + identifierNode: expect.objectContaining({ text: "Steak" }), |
| 135 | + type: "class", |
| 136 | + }, |
| 137 | + { |
| 138 | + id: "Salad", |
| 139 | + node: expect.objectContaining({ type: "class_declaration" }), |
| 140 | + identifierNode: expect.objectContaining({ text: "Salad" }), |
| 141 | + type: "class", |
| 142 | + }, |
| 143 | + ]), |
| 144 | + ); |
138 | 145 | } catch (error) { |
139 | | - console.error("Error in test Nested.cs:", error); |
| 146 | + console.error("Error in test IWillOnlyImportHalf.cs:", error); |
140 | 147 | throw error; |
141 | 148 | } |
142 | 149 | }); |
|
0 commit comments