Skip to content

Commit

Permalink
made MultipleWords and ContextRegex attributes use reflection to tole…
Browse files Browse the repository at this point in the history
…rate different versions of StorEvil
  • Loading branch information
davidmfoley committed Sep 24, 2010
1 parent 00d3737 commit c573e6d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Expand Up @@ -13,7 +13,7 @@ public WordFilter GetParameterFilter(ParameterInfo parameterInfo)
if (parameterInfo.ParameterType.IsEnum)
return new EnumParameterWordFilter(parameterInfo);

if (parameterInfo.GetCustomAttributes(typeof(MultipleWordsAttribute), false).Any())
if (parameterInfo.GetCustomAttributes(false).Any(x=>x.GetType().Name == typeof(MultipleWordsAttribute).Name))
return new MultipleWordsParameterWordFilter(parameterInfo);
return new SimpleParameterMatchWordFilter(parameterInfo);
}
Expand Down
12 changes: 8 additions & 4 deletions Core/StorEvil/Interpreter/ContextTypes/RegExMatcherFactory.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using StorEvil.Context.Matchers;
using StorEvil.Utility;

namespace StorEvil.Interpreter
{
Expand All @@ -14,13 +15,16 @@ public IEnumerable<IMemberMatcher> GetMatchers(Type type)
{
foreach (MemberInfo member in _memberReader.GetMembers(type, BindingFlags.Instance | BindingFlags.Public))
{
var regexAttrs = member.GetCustomAttributes(typeof(ContextRegexAttribute), true);
foreach (var regexAttr in regexAttrs.Cast<ContextRegexAttribute>())
var regexAttrs = member.GetCustomAttributes( true).Where(x=>x.GetType().Name == typeof(ContextRegexAttribute).Name);

foreach (var regexAttr in regexAttrs)
{
var pattern = (string)regexAttr.ReflectionGet("Pattern");

DebugTrace.Trace(GetType().Name,
"Added regex matcher: " + member.Name + ", \"" + regexAttr.Pattern + "\"");
"Added regex matcher: " + member.Name + ", \"" + pattern + "\"");

yield return new RegexMatcher(regexAttr.Pattern, member);
yield return new RegexMatcher(pattern, member);
}
}
}
Expand Down
65 changes: 65 additions & 0 deletions Tests/StorEvil.Tests/Utility/PathTree_Specs.cs
@@ -0,0 +1,65 @@
using NUnit.Framework;
using StorEvil.Assertions;

namespace StorEvil.Utility
{
public class PathTree_Specs
{
protected PathTree PathTree;


[TestFixture]
public class Empty_tree : PathTree_Specs
{
[SetUp]
public void SetUpContext()
{
PathTree = new PathTree();
}

[Test]
public void count_is_zero()
{
PathTree.Count.ShouldEqual(0);

}

[Test]
public void Root_is_an_empty_node()
{
var count = this.PathTree.Root.Children.Count;
count.ShouldEqual(0);
}
}

[TestFixture]
public class Adding_nodes : PathTree_Specs
{
[SetUp]
public void SetUpContext()
{
PathTree = new PathTree();
PathTree.Put(new[] { "foo", "bar" }, "foo/bar");
}

[Test]
public void Can_retrieve_node()
{
var o = PathTree.Get(new[] { "foo", "bar" });
o.ShouldEqual("foo/bar");
}

[Test]
public void returns_null_for_unknown_sub_path()
{
PathTree.Get(new[] { "foo", "bar", "baz" }).ShouldBe(null);
}

[Test]
public void returns_null_for_completely_unknown_path()
{
PathTree.Get(new[] { "bar", "baz" }).ShouldBe(null);
}
}
}
}

0 comments on commit c573e6d

Please sign in to comment.