|
| 1 | +using System.Linq; |
| 2 | +using System.Threading; |
| 3 | +using NUnit.Framework; |
| 4 | +using Rubberduck.Inspections.Inspections.Concrete; |
| 5 | +using RubberduckTests.Mocks; |
| 6 | + |
| 7 | +namespace RubberduckTests.Inspections |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class ObsoleteCallingConventionInspectionTests |
| 11 | + { |
| 12 | + [Test] |
| 13 | + [Category("Inspections")] |
| 14 | + public void ObsoleteCallingConvention_ReturnsResult() |
| 15 | + { |
| 16 | + const string inputCode = |
| 17 | +@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)"; |
| 18 | + |
| 19 | + var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); |
| 20 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 21 | + { |
| 22 | + |
| 23 | + var inspection = new ObsoleteCallingConventionInspection(state); |
| 24 | + var inspector = InspectionsHelper.GetInspector(inspection); |
| 25 | + var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; |
| 26 | + |
| 27 | + Assert.AreEqual(1, inspectionResults.Count()); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + [Test] |
| 32 | + [Category("Inspections")] |
| 33 | + public void ObsoleteCallingConvention_DoesNotReturnResult() |
| 34 | + { |
| 35 | + const string inputCode = |
| 36 | +@"Private Declare Sub Beep Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)"; |
| 37 | + |
| 38 | + var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); |
| 39 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 40 | + { |
| 41 | + |
| 42 | + var inspection = new ObsoleteCallingConventionInspection(state); |
| 43 | + var inspector = InspectionsHelper.GetInspector(inspection); |
| 44 | + var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; |
| 45 | + |
| 46 | + Assert.AreEqual(0, inspectionResults.Count()); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + [Category("Inspections")] |
| 52 | + public void ObsoleteCallingConvention_ReturnsMultipleResults() |
| 53 | + { |
| 54 | + const string inputCode = |
| 55 | +@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any) |
| 56 | +Private Declare Sub Sleep CDecl Lib ""kernel32"" (ByVal dwMilliseconds As Long)"; |
| 57 | + |
| 58 | + var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); |
| 59 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 60 | + { |
| 61 | + |
| 62 | + var inspection = new ObsoleteCallingConventionInspection(state); |
| 63 | + var inspector = InspectionsHelper.GetInspector(inspection); |
| 64 | + var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; |
| 65 | + |
| 66 | + Assert.AreEqual(2, inspectionResults.Count()); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + [Test] |
| 71 | + [Category("Inspections")] |
| 72 | + public void ObsoleteCallingConvention_ReturnsResults_SomeObsoleteCallingConventions() |
| 73 | + { |
| 74 | + const string inputCode = |
| 75 | +@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any) |
| 76 | +Private Declare Sub Sleep Lib ""kernel32"" (ByVal dwMilliseconds As Long)"; |
| 77 | + |
| 78 | + var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); |
| 79 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 80 | + { |
| 81 | + |
| 82 | + var inspection = new ObsoleteCallingConventionInspection(state); |
| 83 | + var inspector = InspectionsHelper.GetInspector(inspection); |
| 84 | + var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; |
| 85 | + |
| 86 | + Assert.AreEqual(1, inspectionResults.Count()); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + [Test] |
| 91 | + [Category("Inspections")] |
| 92 | + public void ObsoleteCallingConvention_Ignored_DoesNotReturnResult() |
| 93 | + { |
| 94 | + const string inputCode = |
| 95 | +@"'@Ignore ObsoleteCallingConvention |
| 96 | +Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)"; |
| 97 | + |
| 98 | + var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); |
| 99 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 100 | + { |
| 101 | + |
| 102 | + var inspection = new ObsoleteCallingConventionInspection(state); |
| 103 | + var inspector = InspectionsHelper.GetInspector(inspection); |
| 104 | + var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; |
| 105 | + |
| 106 | + Assert.IsFalse(inspectionResults.Any()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + [Test] |
| 111 | + [Category("Inspections")] |
| 112 | + public void InspectionName() |
| 113 | + { |
| 114 | + const string inspectionName = "ObsoleteCallingConventionInspection"; |
| 115 | + var inspection = new ObsoleteCallingConventionInspection(null); |
| 116 | + |
| 117 | + Assert.AreEqual(inspectionName, inspection.Name); |
| 118 | + } |
| 119 | + } |
| 120 | +} |
0 commit comments