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);
        }
Beispiel #2
0
        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 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);
        }
Beispiel #6
0
        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");
        }