public void Test_SyntaxReceiver_for_debugging_when_needed(bool useVB) { var receiver = Utils.LanguageUtils(useVB).FindCandidatesWithSyntaxReceiver(@$ "..\..\..\Temp.{Utils.Extension(useVB)}"); receiver.Candidates.Should().NotBeNullOrEmpty(); receiver.Candidates.Should().HaveCount(1); }
public void CommandSource_generator_produces_correct_code(bool useVB, string generatedCodeName) { var source = useVB ? vbClassSource : csharpClassSource; generatedCodeName = $"CliRoot{generatedCodeName}"; var output = Utils.LanguageUtils(useVB).GenerateAndTestSource(generatedCodeName, source, null); NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}"; Approvals.Verify(output); }
public void Generate_CommandSource_for_debugging_when_needed(bool useVB, string generatedCodeName) { Utils utils = Utils.LanguageUtils(useVB); var testProject = "PlaySpace"; var outputPath = $"{Path.Combine(outputRootPath, testProject)}.{Utils.Extension(useVB)}"; var input = @$ "PutYourCodeHere.{Utils.Extension(useVB)}"; input = Path.Combine(outputPath, input); var output = utils.GenerateAndTest(generatedCodeName, input, outputPath); output.Length.Should().BeGreaterThan(1000); }
public void Command_with_argument(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(string)), descriptor.CommandDescriptor, "Argument1", new RawInfoForProperty(null, namespaceName, className))); var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public void CliFromMethod_creates_code_that_will_compile_to_run(bool useVB, string generatedCodeName) { Utils utils = Utils.LanguageUtils(useVB); var testProject = "FromMethodOutput"; var outputPath = $"{Path.Combine(outputRootPath, testProject)}.{Utils.Extension(useVB)}"; var input = @$ "Program.{Utils.Extension(useVB)}"; input = Path.Combine(outputPath, input); var output = utils.GenerateAndTest(generatedCodeName, input, outputPath, isExe: true); output.Length.Should().BeGreaterThan(1000); NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}"; Approvals.Verify(output); }
public void CliRoot_creates_code_that_will_compile(bool useVB, string generatedCodeName) { Utils utils = Utils.LanguageUtils(useVB); var testProject = "Output"; var input = $"CliRoot.{Utils.Extension(useVB)}"; var outputPath = $"{Path.Combine(outputRootPath, testProject)}.{Utils.Extension(useVB)}"; generatedCodeName = $"CliRoot{generatedCodeName}"; var output = utils.GenerateAndTest(generatedCodeName, input, outputPath); output.Length.Should().BeGreaterThan(1000); NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}"; Approvals.Verify(output); }
public void Command_with_option(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.Options.Add(new OptionDescriptor(descriptor.CommandDescriptor, "Option1", new RawInfoForProperty(null, namespaceName, className))); var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public void Simple_command(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.CliName = "my-command"; var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public void SyntaxReceiver_finds_root_class_via_interface(bool useVB) { var(source, expectedType) = useVB ? (vbSource, typeof(VB.ClassBlockSyntax)) : (cSharpSource, typeof(CSharp.ClassDeclarationSyntax)); var receiver = Utils.Receiver(useVB); var classDeclarations = Utils.ClassDeclarations(useVB, source); receiver = VisitSyntaxNodes(receiver, classDeclarations); receiver.Candidates.Should().HaveCount(1); var poco = receiver.Candidates.First(); poco.Should().BeOfType(expectedType); GetName(useVB, poco).Should().Be("CliRoot"); }
public void CliRoot_creates_a_single_CommandSource_set_for_multiple_indicators_of_root(bool useVB, string generatedCodeName) { generatedCodeName = $"CliRoot{generatedCodeName}"; var extension = SourceGeneratorUtilities.Extension(useVB); var sourceCode = useVB ? vbMultipleGenericAndInterfaceIndicators : csMultipleGenericAndInterfaceIndicators; var cliRootCompilation = Utils.LanguageUtils(useVB).GetCliRootCompilation(sourceCode) ?? throw new InvalidOperationException(); var outputPairs = Utils.LanguageUtils(useVB).Generate(cliRootCompilation, out var outputCompilation, out var generationDiagnostics); var matchingPairs = outputPairs.Where(x => x.compilationName.EndsWith($"{generatedCodeName}.generated.{extension}")); matchingPairs.Should().HaveCount(1); generationDiagnostics.Should().NotHaveErrors($"{generatedCodeName} - Generation diagnostics"); outputCompilation.Should().NotHaveErrors($"{generatedCodeName} - Generation compilation"); }
public void SyntaxReceiver_finds_root_class_in_generic(bool useVB) { var(source, expectedType) = useVB ? (vbSource, typeof(VB.IdentifierNameSyntax)) : (cSharpSource, typeof(CSharp.IdentifierNameSyntax)); var receiver = Utils.Receiver(useVB); var statementList = Utils.StatementsForMethod(useVB, source, "Main"); statementList.Should().NotBeNull(); var statements = statementList.ToArray(); receiver.OnVisitSyntaxNode(statements[0].ChildNodes().First()); receiver.Candidates.Should().HaveCount(1); var poco = receiver.Candidates.First(); poco.Should().BeOfType(expectedType); GetName(useVB, poco).Should().Be("CliRoot"); }
public void SyntaxReceiver_finds_entry_method_in_another_class(bool useVB) { var(source, expectedType) = useVB ? (vbSource, typeof(VB.ClassBlockSyntax)) : (cSharpSource, typeof(CSharp.ClassDeclarationSyntax)); var receiver = Utils.Receiver(useVB); var statementList = Utils.StatementsForMethod(useVB, source, "Main"); statementList.Should().NotBeNull(); var statements = statementList.ToArray(); receiver.OnVisitSyntaxNode(statements[2].ChildNodes().First()); receiver.Candidates.Should().HaveCount(1); if (useVB) { var methodType = receiver.Candidates.First() as VB.MemberAccessExpressionSyntax; methodType.Should().NotBeNull(); var classIdentifier = methodType !.Expression as VB.IdentifierNameSyntax; var methodIdentifier = methodType.Name as VB.IdentifierNameSyntax; classIdentifier.Should().NotBeNull(); methodIdentifier.Should().NotBeNull(); classIdentifier !.Identifier.ValueText.Should().Be("A"); methodIdentifier !.Identifier.ValueText.Should().Be("RunThatMethod"); } else { var methodType = receiver.Candidates.First() as CSharp.MemberAccessExpressionSyntax; methodType.Should().NotBeNull(); var classIdentifier = methodType !.Expression as CSharp.IdentifierNameSyntax; var methodIdentifier = methodType.Name as CSharp.IdentifierNameSyntax; classIdentifier.Should().NotBeNull(); methodIdentifier.Should().NotBeNull(); classIdentifier !.Identifier.ValueText.Should().Be("A"); methodIdentifier !.Identifier.ValueText.Should().Be("RunThatMethod"); } }