-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathColorizeData.cs
More file actions
73 lines (62 loc) · 2.65 KB
/
ColorizeData.cs
File metadata and controls
73 lines (62 loc) · 2.65 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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using ColorCode.Common;
using Xunit.Extensions;
namespace ColorCode
{
public class ColorizeData : DataAttribute
{
readonly Regex sourceFileRegex = new Regex(@"(?i)[a-z]+\.source\.([a-z0-9]+)", RegexOptions.Compiled);
public override IEnumerable<object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes)
{
List<object[]> colorizeData = new List<object[]>();
string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string[] dirNames = Directory.GetDirectories(Path.Combine(appPath, @"..\..\Data"));
foreach(string dirName in dirNames)
{
string[] sourceFileNames = Directory.GetFiles(dirName, "*.source.*");
foreach(string sourceFileName in sourceFileNames)
{
Match sourceFileMatch = sourceFileRegex.Match(sourceFileName);
if (sourceFileMatch.Success)
{
string fileExtension = sourceFileMatch.Groups[1].Captures[0].Value;
string languageId = GetLanguageId(fileExtension);
string expectedFileName = sourceFileName.Replace(".source.", ".expected.").Replace("." + fileExtension, ".html");
colorizeData.Add(new object[] {languageId, sourceFileName, expectedFileName});
}
}
}
return colorizeData;
}
private static string GetLanguageId(string fileExtension)
{
switch (fileExtension)
{
case "asax":
return LanguageId.Asax;
case "ashx":
return LanguageId.Ashx;
case "cs":
return LanguageId.CSharp;
case "php":
return LanguageId.Php;
case "css":
return LanguageId.Css;
case "vb":
return LanguageId.VbDotNet;
case "sql":
return LanguageId.Sql;
case "xml":
return LanguageId.Xml;
case "ps1":
return LanguageId.PowerShell;
default:
throw new ArgumentException(string.Format("Unexpected file extension: {0}.", fileExtension));
}
}
}
}