Skip to content

Commit

Permalink
invoke method
Browse files Browse the repository at this point in the history
  • Loading branch information
kemsky committed Dec 11, 2015
1 parent cfab7d9 commit 406fda0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
8 changes: 4 additions & 4 deletions source/com/kemsky/filters/invoke.as
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
package com.kemsky.filters
{
/**
* todo Creates function that extracts named property from value
* @param name name of the property or method (nested properties are supported: 'prop.prop1.prop2')
* @param rest
* @return function function that extracts named property or method from value
* Creates function that calls named method on value.
* @param name name of the method (nested properties are supported: 'prop.prop1.prop2.method').
* @param rest method arguments.
* @return function function that calls named method on value.
*/
public function invoke(name:String, ...rest):Function
{
Expand Down
5 changes: 5 additions & 0 deletions testSrc/Item.as
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ package
return name == item.name;
}

public function method(value:*):*
{
return name + value;
}

public function toString():String
{
return "Item(name=" + String(name) + ", price=" + String(price) + ")";
Expand Down
59 changes: 55 additions & 4 deletions testSrc/com/kemsky/filters/TestFilters.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,63 @@ package com.kemsky.filters

var s:Stream = $(item1, item2);

var i:Stream = s.filter(eq(invoke("equals", item1), true));
assertEquals(i.length, 1);
assertEquals(i.first, item1);
//todo coverage
var result:Stream = s.filter(eq(invoke("equals", item1), true));
assertEquals(result.length, 1);
assertEquals(result.first, item1);


var obj:Item = new Item("p0");
obj.item = new Item("p1");
obj.item.item = new Item("p2");
obj.item.item.item = new Item("p3");
obj.item.item.item.item = new Item("p4");

var nested:Stream = $(obj);

result = nested.filter(eq(invoke("method", 1), "p01"));
assertEquals(result.length, 1);

result = nested.filter(eq(invoke("method1", 1), undefined));
assertEquals(result.length, 1);


result = nested.filter(eq(invoke("item.method", 1), "p11"));
assertEquals(result.length, 1);

result = nested.filter(eq(invoke("item.method1", 1), undefined));
assertEquals(result.length, 1);


result = nested.filter(eq(invoke("item.item.method", 1), "p21"));
assertEquals(result.length, 1);

result = nested.filter(eq(invoke("item.item.method1", 1), undefined));
assertEquals(result.length, 1);


result = nested.filter(eq(invoke("item.item.item.method", 1), "p31"));
assertEquals(result.length, 1);

result = nested.filter(eq(invoke("item.item.item.method1", 1), undefined));
assertEquals(result.length, 1);


result = nested.filter(eq(invoke("item.item.item.item.method", 1), "p41"));
assertEquals(result.length, 1);

result = nested.filter(eq(invoke("item.item.item.item.method1", 1), undefined));
assertEquals(result.length, 1);

try
{
nested.filter(eq(invoke("item.item.item.item.item.method", 1), "p51"));
assertTrue(false);
}
catch(e:Error){}

}


[Test]
public function testType():void
{
Expand Down

0 comments on commit 406fda0

Please sign in to comment.