Created
July 26, 2024 12:48
-
-
Save JKamsker/d3dff82803e54b89da7b9dfe469e7ead to your computer and use it in GitHub Desktop.
Generatorunittest.cs
This file contains hidden or 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
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.CSharp; | |
using SourceGeneratorTestHelpers; | |
namespace Generator.Equals.DynamicGenerationTests; | |
public class UnitTest1 | |
{ | |
[Fact] | |
public void Test1() | |
{ | |
string input = """ | |
using Generator.Equals; | |
namespace Tests; | |
[EquatableAttribute] | |
partial class MyRecord( | |
[property: OrderedEquality] string[] Fruits | |
); | |
"""; | |
var references = new List<MetadataReference>() | |
{ | |
MetadataReference.CreateFromFile(typeof(object).Assembly.Location), | |
MetadataReference.CreateFromFile(typeof(EquatableAttribute).Assembly.Location), | |
}; | |
// add netstandard | |
references.Add(MetadataReference.CreateFromFile(typeof(System.Runtime.GCSettings).Assembly.Location)); | |
var result = IncrementalGenerator.Run<EqualsGenerator> | |
( | |
input, | |
new Microsoft.CodeAnalysis.CSharp.CSharpParseOptions() | |
{ | |
}, | |
references | |
); | |
var gensource = result.Results | |
.SelectMany(x => x.GeneratedSources) | |
.Select(x => x.SourceText) | |
.ToList() | |
; | |
Assert.NotNull(gensource); | |
//var genSourceString = gensource.ToString(); | |
//// Assert in the same namespace | |
//Assert.Contains("namespace Tests", genSourceString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment