~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
 
 
4
namespace ICSharpCode.NRefactory.CSharp.AstVerifier
 
5
{
 
6
        class MainClass
 
7
        {
 
8
                static bool IsMatch (string src1, string src2, out int i, out int j)
 
9
                {
 
10
                        i = 0;
 
11
                        j = 0;
 
12
                        while (i < src1.Length && j < src2.Length) {
 
13
                                char c1 = src1 [i];
 
14
                                char c2 = src2 [j];
 
15
                                if (char.IsWhiteSpace (c1)) {
 
16
                                        i++;
 
17
                                        continue;
 
18
                                }
 
19
                                if (char.IsWhiteSpace (c2)) {
 
20
                                        j++;
 
21
                                        continue;
 
22
                                }
 
23
                                if (c1 != c2)
 
24
                                        return false;
 
25
                                i++;
 
26
                                j++;
 
27
                        }
 
28
                        while (i < src1.Length && char.IsWhiteSpace (src1[i])) {
 
29
                                i++;
 
30
                        }
 
31
                        while (j < src2.Length && char.IsWhiteSpace (src2[j])) {
 
32
                                j++;
 
33
                        }
 
34
 
 
35
                        return i == src1.Length && j == src2.Length;
 
36
                }
 
37
 
 
38
                public static void Main (string[] args)
 
39
                {
 
40
                        if (args.Length == 0) {
 
41
                                Console.WriteLine ("Usage: AstVerifier [-v|-verbose] [Directory]");
 
42
                                return;
 
43
                        }
 
44
                        string directory = args[args.Length - 1];
 
45
                        bool verboseOutput =  args.Length > 1 && (args[0] == "-v" || args[0] == "-verbose");
 
46
 
 
47
                        try {
 
48
                                if (!Directory.Exists (directory)) {
 
49
                                        Console.WriteLine ("Directory not found.");
 
50
                                        return;
 
51
                                }
 
52
                        } catch (IOException) {
 
53
                                Console.WriteLine ("Exception while trying to access the directory.");
 
54
                                return;
 
55
                        }
 
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"))
 
60
                                        continue;
 
61
                                string text = File.ReadAllText (file);
 
62
                                var unit = SyntaxTree.Parse (text, file);
 
63
                                if (unit == null)
 
64
                                        continue;
 
65
                                string generated = unit.GetText ();
 
66
                                int i, j;
 
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)));
 
73
                                        }
 
74
                                        failed++;
 
75
                                } else {
 
76
                                        passed++;
 
77
                                }
 
78
                        }
 
79
 
 
80
                        Console.WriteLine ("{0} passed, {1} failed", passed, failed);
 
81
                }
 
82
        }
 
83
}