Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

include scanner tests. copied regex from jamplus.

  • Loading branch information...
commit e45502b48e181538a33491f8bd7c4b30e5f05edd 1 parent 6eef101
Lucas Meijer authored
Showing with 46 additions and 0 deletions.
  1. +10 −0 IncludeScanner.cs
  2. +35 −0 Tests/IncludeScannerTest.cs
  3. +1 −0  bs.csproj
View
10 IncludeScanner.cs
@@ -1,13 +1,23 @@
using System;
using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
namespace bs
{
internal class IncludeScanner
{
+ Regex _regex = new Regex("^[ ]*#[ ]*include[ ]*[<\"]([^\">]*)[\">].*$", RegexOptions.Multiline);
+
public IEnumerable<string> Scan(string file)
{
yield break;
}
+
+ public IEnumerable<string> ScanText(string fileContents)
+ {
+ var matches = _regex.Matches(fileContents);
+ return from Match match in matches select match.Groups[1].ToString();
+ }
}
}
View
35 Tests/IncludeScannerTest.cs
@@ -0,0 +1,35 @@
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+
+namespace bs.Tests
+{
+ [TestFixture]
+ public class IncludeScannerTest
+ {
+ [Test]
+ public void CanFindSimpleInclude()
+ {
+ RunTest("#include \"windows.h\"", new [] {"windows.h"});
+ }
+
+ [Test]
+ public void CanFindIncludeWithSquareBrackets()
+ {
+ RunTest("#include <windows.h>", new[] { "windows.h" });
+ }
+
+ [Test]
+ public void CanFindMultipleIncludes()
+ {
+ RunTest("#include <windows.h>\n#include \"myfolder/myfile.h\"", new[] { "windows.h", "myfolder/myfile.h" });
+ }
+
+ private static void RunTest(string fileContents, IEnumerable<string> expected)
+ {
+ var scanner = new IncludeScanner();
+ var result = scanner.ScanText(fileContents).ToList();
+ CollectionAssert.AreEquivalent(expected, result);
+ }
+ }
+}
View
1  bs.csproj
@@ -58,6 +58,7 @@
<Compile Include="MissingDependencyException.cs" />
<Compile Include="Tests\DifferentInputFiles.cs" />
<Compile Include="IncludeScanner.cs" />
+ <Compile Include="Tests\IncludeScannerTest.cs" />
<Compile Include="Tests\SimpleCopyDepGraph.cs" />
<Compile Include="Tests\TargetWithoutSources.cs" />
</ItemGroup>
Please sign in to comment.
Something went wrong with that request. Please try again.