Created Tests
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace File_Folder_Helper.ADO2024.PI1;
|
||||
@ -7,11 +9,18 @@ namespace File_Folder_Helper.ADO2024.PI1;
|
||||
internal static partial class Helper20240108
|
||||
{
|
||||
|
||||
private record Method(string Name,
|
||||
private record Method(int EndLine,
|
||||
string FirstLine,
|
||||
int FirstUsedLine,
|
||||
string Name,
|
||||
int ParameterCount,
|
||||
int StartLine,
|
||||
int EndLine,
|
||||
int FirstUsedLine);
|
||||
int StartLine);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Method[]))]
|
||||
private partial class MethodCollectionCommonSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"(?<method>[A-Z]{1}[A-Za-z_0-9]*)\(")]
|
||||
private static partial Regex CSharpMethodName();
|
||||
@ -40,7 +49,7 @@ internal static partial class Helper20240108
|
||||
for (int j = i - 1; j > -1; j--)
|
||||
{
|
||||
line = lines[j].Trim();
|
||||
if (!line.StartsWith('[') && !line.StartsWith("/// "))
|
||||
if (!line.StartsWith('[') && !line.StartsWith('#') && !line.StartsWith("/// "))
|
||||
break;
|
||||
result--;
|
||||
}
|
||||
@ -155,7 +164,9 @@ internal static partial class Helper20240108
|
||||
string line;
|
||||
string? name;
|
||||
int startLine;
|
||||
Method method;
|
||||
string search;
|
||||
string firstLine;
|
||||
string innerLine;
|
||||
string searchNot;
|
||||
string searchWrap;
|
||||
@ -186,12 +197,18 @@ internal static partial class Helper20240108
|
||||
startLine = GetStartLine(lines, i);
|
||||
searchConstructor = $"{name.ToLower()} = new(";
|
||||
parameterCount = GetParameterCount(line, search);
|
||||
isLinq = lines[i + 1].Trim() != "{";
|
||||
if (!lines[startLine].StartsWith("#pragma"))
|
||||
firstLine = lines[startLine].Trim();
|
||||
else
|
||||
firstLine = lines[startLine + 1].Trim();
|
||||
isLinq = !lines[i + 1].StartsWith("#pragma") && lines[i + 1].Trim() != "{";
|
||||
if (isLinq)
|
||||
blocks++;
|
||||
for (int j = i + 1; j < lines.Length; j++)
|
||||
{
|
||||
innerLine = lines[j].Trim();
|
||||
if (innerLine.StartsWith("#pragma"))
|
||||
continue;
|
||||
if (isLinq && string.IsNullOrEmpty(innerLine))
|
||||
{
|
||||
if (line.EndsWith(';'))
|
||||
@ -218,7 +235,8 @@ internal static partial class Helper20240108
|
||||
}
|
||||
if (j > lines.Length - 2)
|
||||
throw new Exception();
|
||||
results.Add(new(name, parameterCount, startLine, endLine, firstUsedLine.Value));
|
||||
method = new(endLine, firstLine, firstUsedLine.Value, name, parameterCount, startLine);
|
||||
results.Add(method);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -230,6 +248,8 @@ internal static partial class Helper20240108
|
||||
{
|
||||
bool result;
|
||||
List<string> results = [];
|
||||
if (methods.Count == 0)
|
||||
File.WriteAllText(".vscode/.json", JsonSerializer.Serialize(methods.ToArray(), MethodCollectionCommonSourceGenerationContext.Default.MethodArray));
|
||||
ReadOnlyCollection<int> methodLines = GetMethodLines(methods);
|
||||
int minMethodLines = methodLines.Min();
|
||||
for (int i = 0; i < minMethodLines; i++)
|
||||
|
Reference in New Issue
Block a user