-
Notifications
You must be signed in to change notification settings - Fork 158
/
Externals.fs
107 lines (86 loc) · 3.14 KB
/
Externals.fs
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
#if INTERACTIVE
#r "../../bin/FSharp.Formatting.Markdown.dll"
#r "../../packages/test/NUnit/lib/net45/nunit.framework.dll"
#r "../../packages/test/FsUnit/lib/net45/FsUnit.NUnit.dll"
#else
[<NUnit.Framework.TestFixture>]
module FSharp.Markdown.Tests.Externals
#endif
open FsUnit
open NUnit.Framework
open FSharp.Formatting.Markdown
open System.IO
open System.Text.RegularExpressions
let removeWhitespace (s: string) =
// Standardize line endings
let s = s.Replace("\r\n", "\n") // DOS to Unix
let s = s.Replace("\r", "\n") // Mac to Unix
// remove any tabs entirely
let s = s.Replace("\t", "")
// remove empty newlines
let s = Regex.Replace(s, @"^\n", "", RegexOptions.Multiline)
// remove leading space at the start of lines
let s = Regex.Replace(s, @"^\s+", "", RegexOptions.Multiline)
// remove all newlines
let s = s.Replace("\n", "")
s
let failingTests =
set
[ "Auto_links.text"
"Inline_HTML_comments.text"
"Ordered_and_unordered_lists.text"
"markdown-readme.text"
"nested-emphasis.text"
"Email auto links.text"
"Emphasis.text"
"Inline HTML (Span).text"
"Ins & del.text"
"Links, inline style.text"
"Nesting.text"
"Parens in URL.text" ]
let rec genTestCases (dir: string) =
seq {
for file in Directory.GetFiles(dir, "*.text") do
yield TestCaseData(dir, file, (Path.ChangeExtension(file, "2.html")), (Path.ChangeExtension(file, "html")))
for d in Directory.GetDirectories(dir) do
yield! genTestCases d
}
let (++) a b = Path.Combine(a, b)
let testdir =
__SOURCE_DIRECTORY__
++ Path.Combine("..", "..", "tests", "Benchmarks", "testfiles")
let getTest () = genTestCases testdir
let executeTest (dir: string) (source: string) (target: string) (verify: string) =
try
if File.Exists(verify) then
let text = File.ReadAllText(source)
(use wr = new StreamWriter(target)
Markdown.WriteHtml(text, wr, "\r\n"))
let contents = File.ReadAllLines(verify)
File.WriteAllLines(verify, contents)
let targetHtml = removeWhitespace (File.ReadAllText(target))
let verifyHtml = removeWhitespace (File.ReadAllText(verify))
if not <| Set.contains (Path.GetFileName(source)) failingTests then
Some(source, target, verifyHtml, targetHtml)
else
None
else
None
with e ->
printfn " - %s (failed)\n %A" (target.Substring(dir.Length)) e
None
[<Test>]
[<TestCaseSource("getTest")>]
let ``Run external test`` (actualName: string) (expectedName: string) (actual: string) (expected: string) =
match executeTest actualName expectedName actual expected with
| Some(actualName, expectedName, actual, expected) ->
if actual = expected then
File.Delete(expectedName)
Assert.That(
actual,
Is.EqualTo(expected),
"Mismatch between '{0}' and the transformed '{1}'.",
actualName,
expectedName
)
| None -> ()