|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import { CSharpNamespaceResolver, File } from "."; |
| 3 | +import { getCSharpFilesMap } from "../testFiles"; |
| 4 | + |
| 5 | +describe("NamespaceResolver", () => { |
| 6 | + const files: Map<string, File> = getCSharpFilesMap(); |
| 7 | + const nsResolver: CSharpNamespaceResolver = new CSharpNamespaceResolver(); |
| 8 | + |
| 9 | + test("2Namespaces1File.cs", () => { |
| 10 | + const file = files.get("2Namespaces1File.cs") as File; |
| 11 | + const namespaces = nsResolver.getNamespacesFromFile(file); |
| 12 | + expect(namespaces).toMatchObject([ |
| 13 | + { |
| 14 | + name: "", |
| 15 | + exports: [], |
| 16 | + childrenNamespaces: [ |
| 17 | + { |
| 18 | + name: "BeefBurger", |
| 19 | + exports: [ |
| 20 | + { name: "Steak", filepath: "2Namespaces1File.cs" }, |
| 21 | + { name: "Cheese", filepath: "2Namespaces1File.cs" }, |
| 22 | + { name: "Bun", filepath: "2Namespaces1File.cs" }, |
| 23 | + ], |
| 24 | + childrenNamespaces: [], |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "ChickenBurger", |
| 28 | + exports: [ |
| 29 | + { name: "Chicken", filepath: "2Namespaces1File.cs" }, |
| 30 | + { name: "Salad", filepath: "2Namespaces1File.cs" }, |
| 31 | + { name: "Bun", filepath: "2Namespaces1File.cs" }, |
| 32 | + ], |
| 33 | + childrenNamespaces: [], |
| 34 | + }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + ]); |
| 38 | + }); |
| 39 | + |
| 40 | + test("Models.cs", () => { |
| 41 | + const file = files.get("Models.cs") as File; |
| 42 | + const namespaces = nsResolver.getNamespacesFromFile(file); |
| 43 | + expect(namespaces).toMatchObject([ |
| 44 | + { |
| 45 | + name: "MyApp.Models", |
| 46 | + exports: [ |
| 47 | + { name: "User", type: "class", filepath: "Models.cs" }, |
| 48 | + { name: "Order", type: "struct", filepath: "Models.cs" }, |
| 49 | + { name: "OrderStatus", type: "enum", filepath: "Models.cs" }, |
| 50 | + { name: "IOrder", type: "interface", filepath: "Models.cs" }, |
| 51 | + { name: "OrderDelegate", type: "delegate", filepath: "Models.cs" }, |
| 52 | + ], |
| 53 | + childrenNamespaces: [], |
| 54 | + }, |
| 55 | + ]); |
| 56 | + }); |
| 57 | + |
| 58 | + test("Namespaced.cs", () => { |
| 59 | + const file = files.get("Namespaced.cs") as File; |
| 60 | + const namespaces = nsResolver.getNamespacesFromFile(file); |
| 61 | + expect(namespaces).toMatchObject([ |
| 62 | + { |
| 63 | + name: "", |
| 64 | + exports: [], |
| 65 | + childrenNamespaces: [ |
| 66 | + { |
| 67 | + name: "MyNamespace", |
| 68 | + exports: [{ name: "MyClass", filepath: "Namespaced.cs" }], |
| 69 | + childrenNamespaces: [], |
| 70 | + }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + ]); |
| 74 | + }); |
| 75 | + |
| 76 | + test("Nested.cs", () => { |
| 77 | + const file = files.get("Nested.cs") as File; |
| 78 | + const namespaces = nsResolver.getNamespacesFromFile(file); |
| 79 | + expect(namespaces).toMatchObject([ |
| 80 | + { |
| 81 | + name: "", |
| 82 | + exports: [], |
| 83 | + childrenNamespaces: [ |
| 84 | + { |
| 85 | + name: "OuterNamespace", |
| 86 | + exports: [{ name: "OuterClass", filepath: "Nested.cs" }], |
| 87 | + childrenNamespaces: [ |
| 88 | + { |
| 89 | + name: "InnerNamespace", |
| 90 | + exports: [{ name: "InnerClass", filepath: "Nested.cs" }], |
| 91 | + childrenNamespaces: [], |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + ], |
| 96 | + }, |
| 97 | + ]); |
| 98 | + }); |
| 99 | + |
| 100 | + test("SemiNamespaced.cs", () => { |
| 101 | + const file = files.get("SemiNamespaced.cs") as File; |
| 102 | + const namespaces = nsResolver.getNamespacesFromFile(file); |
| 103 | + expect(namespaces).toMatchObject([ |
| 104 | + { |
| 105 | + name: "", |
| 106 | + exports: [ |
| 107 | + { name: "Freeman", filepath: "SemiNamespaced.cs" }, |
| 108 | + { name: "HeadCrab", filepath: "SemiNamespaced.cs" }, |
| 109 | + ], |
| 110 | + childrenNamespaces: [ |
| 111 | + { |
| 112 | + name: "HalfNamespace", |
| 113 | + exports: [{ name: "Gordon", filepath: "SemiNamespaced.cs" }], |
| 114 | + childrenNamespaces: [], |
| 115 | + }, |
| 116 | + ], |
| 117 | + }, |
| 118 | + ]); |
| 119 | + }); |
| 120 | +}); |
0 commit comments