-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTester.cs
146 lines (123 loc) · 3.66 KB
/
Tester.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.IO;
using NUnit.Framework;
namespace MarkdownSharpPlus
{
public class Tester
{
static void Main(String[] args)
{
new Tester().run("testfiles\\mdtest-1.1\\Code_Blocks.text").reportFirst();
//new Markdown_Tests().list();
Console.WriteLine("-the end-");
}
public void reportFirst()
{
foreach (var e in es)
e.emitException();
}
private void report()
{
foreach (var e in es)
{
Console.WriteLine(e.Message);
}
}
public abstract class Err
{
public abstract String Message
{
get;
}
public abstract void emitException();
}
private List<Err> es = new List<Err>();
public class FailureError : Err
{
public Exception e;
public FailureError(Exception e) { this.e = e; }
public override String Message
{
get
{
return e.Message;
}
}
public override void emitException()
{
throw e;
}
}
public class MismatchError : Err
{
public String file;
public String kind;
public String exepcted;
public String actual;
public MismatchError(String k, String f, String ex, String ac)
{
kind = k;
file = f;
exepcted = ex;
actual = ac;
}
public override String ToString() { return kind + ": " + file; }
public override String Message
{
get
{
return "Expected\n" + exepcted + "\n--------------\n\nBut got\n" + actual + "\n-----------------\n";
}
}
public override void emitException()
{
Assert.AreEqual(exepcted, actual);
}
}
public Tester run(String file)
{
var m = new Markdown();
var expected = FileContents(Path.ChangeExtension(file, "html"));
try
{
var output = m.Transform(FileContents(file));
if (output != expected)
es.Add(new MismatchError("mismatch", file, expected, output));
}
catch (Exception e)
{
es.Add(new FailureError(e));
}
return this;
}
static string FileContents(string filename)
{
try
{
return File.ReadAllText(Path.Combine(ExecutingAssemblyPath, filename));
}
catch (FileNotFoundException)
{
return "";
}
}
static private string ExecutingAssemblyPath
{
get
{
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
// removes executable part
path = Path.GetDirectoryName(path);
// we're typically in \bin\debug or bin\release so move up two folders
path = Path.Combine(path, "..");
path = Path.Combine(path, "..");
path = Path.Combine(path, "..");
path = Path.Combine(path, "MarkdownSharpTests");
return path;
}
}
}
}