Skip to content

ohmrun/stx_expect

Repository files navigation

Expect

includes Predicate, Expectation

Usage

Expectations

using stx.Pico;//Wildcard
using stx.Expect;

class Main{
 static public function main(){
   __.expect().equals(1,2);//returns false
   __.expect().ok(1,2)//returns false

  var a = 1;
   __.expect().exists().and(
    __.expect().equals().bindI(1)
   ).is_ok(a)//returns true
 }
}

Expectations

function equals<T>(lhs:T,rhs:T)                              
function alike<E:StdEnumValue>(lhs:E,rhs:E)
// lhs is greater than rhs
function gt<T>(lhs:T,rhs:T)
// lhs is greater than or equal to rhs
function gt_eq<T>(lhs:T,rhs:T)                              
function lt<T>(lhs:T,rhs:T)                                  
function lt_eq<T>(lhs:T,rhs:T)                              

Predicates

function always<T>(t:T)                                     
function never<T,E>(t:T)                                    
function is<A>(a:A,clazz:Class<A>)                          
function throws<E>(fn:Block)                                
function void<T>(t:T)                                       
function exists<T>(t:T)                                     
function matches<E>(string:String,reg:String,opt:String)    

Predicate Grammar

ands produces a predicate that succeeds if all input predicates succeed.

ands<T,E>(self: Predicate<T,E>,rest: Iterable<Predicate<T,E>>): Predicate<T,E> 

ors produces a predicate that succeeds if any of the input predicates succeeds.

ors<T,E>(self: Predicate<T,E>,rest: Iterable<Predicate<T,E>>): Predicate<T,E >

and produces a predicate that succeeds if both succeed.

and<T,E>(self: Predicate<T,E>,that: Predicate<T,E>): Predicate<T,E>

or produces a predicate that succeeds if one or other predicates succeed.

or<T,E>(self: Predicate<T,E>,that: Predicate<T,E>): Predicate<T,E>

xor produces a predicate that succeeds if one or other , but not both predicates succeed.

xor<T,E>(self: Predicate<T,E>, that: Predicate<T,E>): Predicate<T,E>

not produces a predicate that succeeds if the input predicate fails.

not<T,E>(self: Predicate<T,E>):Predicate<T,E>

errata maps the stx.fail.Report datatype.

  errata<T,E,EE>(self: Predicate<T,E>,fn:Report<E>->Report<EE>):Predicate<T,EE>

Explainable

Predicates and Expectations can be explained to arbitrary depth via the stx.expect.Explainable.ExplainableApi

for example, from Or

public function explain(){
  return SN.Make(
    x -> x.Scalar(x -> x.String("Should pass Either or Both Predicates")),
    _ -> l.explain(),
    _ -> r.explain()
  );
}

About

composable predicates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages