4
namespace ICSharpCode.NRefactory.CSharp.AstVerifier
8
static bool IsMatch (string src1, string src2, out int i, out int j)
12
while (i < src1.Length && j < src2.Length) {
15
if (char.IsWhiteSpace (c1)) {
19
if (char.IsWhiteSpace (c2)) {
28
while (i < src1.Length && char.IsWhiteSpace (src1[i])) {
31
while (j < src2.Length && char.IsWhiteSpace (src2[j])) {
35
return i == src1.Length && j == src2.Length;
38
public static void Main (string[] args)
40
if (args.Length == 0) {
41
Console.WriteLine ("Usage: AstVerifier [-v|-verbose] [Directory]");
44
string directory = args[args.Length - 1];
45
bool verboseOutput = args.Length > 1 && (args[0] == "-v" || args[0] == "-verbose");
48
if (!Directory.Exists (directory)) {
49
Console.WriteLine ("Directory not found.");
52
} catch (IOException) {
53
Console.WriteLine ("Exception while trying to access the directory.");
56
int failed = 0, passed = 0;
57
Console.WriteLine ("search in " + directory);
58
foreach (var file in Directory.GetFileSystemEntries (directory, "*", SearchOption.AllDirectories)) {
59
if (!file.EndsWith (".cs"))
61
string text = File.ReadAllText (file);
62
var unit = SyntaxTree.Parse (text, file);
65
string generated = unit.GetText ();
67
if (!IsMatch (text, generated, out i, out j)) {
68
if (i > 0 && j > 0 && verboseOutput) {
69
Console.WriteLine ("fail :" + file + "----original:");
70
Console.WriteLine (text.Substring (0, Math.Min (text.Length, i + 1)));
71
Console.WriteLine ("----generated:");
72
Console.WriteLine (generated.Substring (0, Math.Min (generated.Length, j + 1)));
80
Console.WriteLine ("{0} passed, {1} failed", passed, failed);