forked from madelson/DistributedLock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeGenHelpers.cs
More file actions
37 lines (30 loc) · 1.56 KB
/
CodeGenHelpers.cs
File metadata and controls
37 lines (30 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace DistributedLockCodeGen;
internal static class CodeGenHelpers
{
public static string SolutionDirectory => Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", ".."));
public static IEnumerable<string> EnumerateSolutionFiles() => Directory.EnumerateFiles(SolutionDirectory, "*.csproj", SearchOption.AllDirectories)
.Select(Path.GetDirectoryName)
.Where(d => !Regex.IsMatch(Path.GetFileName(d), "^(DistributedLock|DistributedLock.Tests|DistributedLockCodeGen)$", RegexOptions.IgnoreCase))
.SelectMany(d => Directory.EnumerateFiles(d, "*.cs", SearchOption.AllDirectories));
public static string NormalizeCodeWhitespace(string code) => code.Trim().Replace("\r\n", "\n");
public static bool HasPublicType(string code, out (string typeName, bool isInterface) info)
{
var match = Regex.Match(code, @"\n( |\t)?public.*?(class|interface)\s+(?<name>\w+)");
if (match.Success)
{
info = (typeName: match.Groups["name"].Value, isInterface: match.Value.Contains("interface"));
return true;
}
info = default;
return false;
}
public static bool SupportsSyncApis(string path) =>
// zookeeper is inherently asynchronous (watch-based), so any synchronous APIs it has are just sync-over-async
!path.Contains("ZooKeeper", StringComparison.OrdinalIgnoreCase);
}