-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from thinker227/analysis
Add analysis suite
- Loading branch information
Showing
38 changed files
with
1,899 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,55 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D92004B4-8D01-4BC3-B76B-A80D657FEC30}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal", "src\Rascal\Rascal.csproj", "{04DE173D-4E74-4104-94FA-2B1807FCD34D}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Tests", "src\Rascal.Tests\Rascal.Tests.csproj", "{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Playground", "src\Rascal.Playground\Rascal.Playground.csproj", "{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D92004B4-8D01-4BC3-B76B-A80D657FEC30}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal", "src\Rascal\Rascal.csproj", "{04DE173D-4E74-4104-94FA-2B1807FCD34D}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Tests", "src\Rascal.Tests\Rascal.Tests.csproj", "{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Analysis", "src\Rascal.Analysis\Rascal.Analysis.csproj", "{076764E7-54D5-41EF-99C9-96C483F15E31}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Analysis.Tests", "src\Rascal.Analysis.Tests\Rascal.Analysis.Tests.csproj", "{C2197909-F734-4435-869A-422CD571D061}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rascal.Playground", "src\Rascal.Playground\Rascal.Playground.csproj", "{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{076764E7-54D5-41EF-99C9-96C483F15E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{076764E7-54D5-41EF-99C9-96C483F15E31}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{076764E7-54D5-41EF-99C9-96C483F15E31}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{076764E7-54D5-41EF-99C9-96C483F15E31}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C2197909-F734-4435-869A-422CD571D061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C2197909-F734-4435-869A-422CD571D061}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C2197909-F734-4435-869A-422CD571D061}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C2197909-F734-4435-869A-422CD571D061}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{04DE173D-4E74-4104-94FA-2B1807FCD34D} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{291FDB2E-8AC8-4B7A-B6E6-6DF5DCBCEB58} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{076764E7-54D5-41EF-99C9-96C483F15E31} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{C2197909-F734-4435-869A-422CD571D061} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
{F5A7C08C-51B5-4043-9666-C8DCD4F9C1E4} = {D92004B4-8D01-4BC3-B76B-A80D657FEC30} | ||
EndGlobalSection | ||
EndGlobal |
164 changes: 164 additions & 0 deletions
164
src/Rascal.Analysis.Tests/Analyzers/ToSusTypeAnalyzerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using VerifyCS = Rascal.Analysis.Tests.Verifiers.AnalyzerVerifier<Rascal.Analysis.Analyzers.ToSusTypeAnalyzer>; | ||
|
||
namespace Rascal.Analysis.Analyzers.Tests; | ||
|
||
public class ToSusTypeAnalyzerTests | ||
{ | ||
[Fact] | ||
public async Task Reports_SameType_OnSameType() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(2); | ||
var r = x.To<{|RASCAL004:int|}>(); | ||
} | ||
} | ||
"""); | ||
|
||
[Fact] | ||
public async Task Reports_ImpossibleType_OnBothStructTypes() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(2); | ||
var r = x.To<{|RASCAL005:bool|}>(); | ||
} | ||
} | ||
"""); | ||
|
||
[Fact] | ||
public async Task Reports_ImpossibleType_OnBothClassTypes_OutsideHierarchy() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(new B()); | ||
var r = x.To<{|RASCAL005:C|}>(); | ||
} | ||
} | ||
class A {} | ||
class B : A {} | ||
class C : A {} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnBothClassTypes_InsideHierarchy_Up() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(new B()); | ||
var r = x.To<A>(); | ||
} | ||
} | ||
class A {} | ||
class B : A {} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnBothClassTypes_InsideHierarchy_Down() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(new A()); | ||
var r = x.To<B>(); | ||
} | ||
} | ||
class A {} | ||
class B : A {} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnFromInterfaceType() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Err<I>("error"); | ||
var r = x.To<int>(); | ||
} | ||
} | ||
interface I {} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnToInterfaceType() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var x = Ok(2); | ||
var r = x.To<I>(); | ||
} | ||
} | ||
interface I {} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnFromTypeParameter() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar<T>() | ||
{ | ||
var x = Err<T>("error"); | ||
var r = x.To<int>(); | ||
} | ||
} | ||
"""); | ||
|
||
[Fact] | ||
public async Task DoesNotReport_OnToTypeParameter() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar<T>() | ||
{ | ||
var x = Ok(2); | ||
var r = x.To<T>(); | ||
} | ||
} | ||
"""); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Rascal.Analysis.Tests/Analyzers/UnnecessaryIdMapAnalyzerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using VerifyCS = Rascal.Analysis.Tests.Verifiers.AnalyzerVerifier<Rascal.Analysis.Analyzers.UnnecessaryIdMapAnalyzer>; | ||
|
||
namespace Rascal.Analysis.Analyzers.Tests; | ||
|
||
public class UnnecessaryIdMapAnalyzerTests | ||
{ | ||
[Fact] | ||
public async Task DoesNotReport_OnMapOperationCall() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var result = Ok(2); | ||
var v = result.Map(x => x + 1); | ||
} | ||
} | ||
"""); | ||
|
||
[Fact] | ||
public async Task Reports_OnMapIdCall() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var result = Ok(2); | ||
var v = result.{|RASCAL003:Map(x => x)|}; | ||
} | ||
} | ||
"""); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Rascal.Analysis.Tests/Analyzers/UseGetValueOrForIdMatchAnalyzerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using VerifyCS = Rascal.Analysis.Tests.Verifiers.AnalyzerVerifier<Rascal.Analysis.Analyzers.UseGetValueOrForIdMatchAnalyzer>; | ||
|
||
namespace Rascal.Analysis.Analyzers.Tests; | ||
|
||
public class UseGetValueOrForIdMatchAnalyzerTests | ||
{ | ||
[Fact] | ||
public async Task DoesNotReport_OnOperation() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var r = Ok(2); | ||
var x = r.Match(x => x + 1, _ => 0); | ||
} | ||
} | ||
"""); | ||
|
||
[Fact] | ||
public async Task Reports_OnId() => await VerifyCS.VerifyAnalyzerAsync(""" | ||
using System; | ||
using Rascal; | ||
using static Rascal.Prelude; | ||
public static class Foo | ||
{ | ||
public static void Bar() | ||
{ | ||
var r = Ok(2); | ||
var x = r.{|RASCAL006:Match|}(x => x, _ => 0); | ||
} | ||
} | ||
"""); | ||
} |
Oops, something went wrong.