|
| 1 | +import { checkConsistency } from "../../../src/model-editor/consistency-check"; |
| 2 | +import { createSourceModeledMethod } from "../../factories/model-editor/modeled-method-factories"; |
| 3 | +import { createMethod } from "../../factories/model-editor/method-factories"; |
| 4 | + |
| 5 | +describe("checkConsistency", () => { |
| 6 | + const notifier = { |
| 7 | + missingMethod: jest.fn(), |
| 8 | + inconsistentSupported: jest.fn(), |
| 9 | + }; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + notifier.missingMethod.mockReset(); |
| 13 | + notifier.inconsistentSupported.mockReset(); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should call missingMethod when method is missing", () => { |
| 17 | + checkConsistency( |
| 18 | + [], |
| 19 | + { |
| 20 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)": |
| 21 | + [createSourceModeledMethod()], |
| 22 | + }, |
| 23 | + notifier, |
| 24 | + ); |
| 25 | + |
| 26 | + expect(notifier.missingMethod).toHaveBeenCalledWith( |
| 27 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)", |
| 28 | + ); |
| 29 | + expect(notifier.inconsistentSupported).not.toHaveBeenCalled(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should call inconsistentSupported when support is inconsistent", () => { |
| 33 | + checkConsistency( |
| 34 | + [ |
| 35 | + createMethod({ |
| 36 | + signature: |
| 37 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)", |
| 38 | + packageName: "Microsoft.CodeAnalysis.CSharp", |
| 39 | + typeName: "SyntaxFactory", |
| 40 | + methodName: "SeparatedList`1", |
| 41 | + methodParameters: "(System.Collections.Generic.IEnumerable<TNode>)", |
| 42 | + supported: false, |
| 43 | + }), |
| 44 | + ], |
| 45 | + { |
| 46 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)": |
| 47 | + [createSourceModeledMethod({})], |
| 48 | + }, |
| 49 | + notifier, |
| 50 | + ); |
| 51 | + |
| 52 | + expect(notifier.inconsistentSupported).toHaveBeenCalledWith( |
| 53 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)", |
| 54 | + true, |
| 55 | + false, |
| 56 | + ); |
| 57 | + expect(notifier.missingMethod).not.toHaveBeenCalled(); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should call no methods when consistent", () => { |
| 61 | + checkConsistency( |
| 62 | + [ |
| 63 | + createMethod({ |
| 64 | + signature: |
| 65 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList<TNode>(System.Collections.Generic.IEnumerable<TNode>)", |
| 66 | + packageName: "Microsoft.CodeAnalysis.CSharp", |
| 67 | + typeName: "SyntaxFactory", |
| 68 | + methodName: "SeparatedList<TNode>", |
| 69 | + methodParameters: "(System.Collections.Generic.IEnumerable<TNode>)", |
| 70 | + supported: true, |
| 71 | + }), |
| 72 | + ], |
| 73 | + { |
| 74 | + "Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList<TNode>(System.Collections.Generic.IEnumerable<TNode>)": |
| 75 | + [createSourceModeledMethod({})], |
| 76 | + }, |
| 77 | + notifier, |
| 78 | + ); |
| 79 | + |
| 80 | + expect(notifier.missingMethod).not.toHaveBeenCalled(); |
| 81 | + expect(notifier.inconsistentSupported).not.toHaveBeenCalled(); |
| 82 | + }); |
| 83 | +}); |
0 commit comments