Permalink
Browse files

made MultipleWords and ContextRegex attributes use reflection to tole…

…rate different versions of StorEvil
  • Loading branch information...
1 parent 00d3737 commit c573e6d699cdeba60e72b3e7c93c46a8e1fd44ed @davidmfoley davidmfoley committed Sep 24, 2010
@@ -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);
}
@@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using StorEvil.Context.Matchers;
+using StorEvil.Utility;
namespace StorEvil.Interpreter
{
@@ -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);
}
}
}
@@ -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.