@@ -19,6 +19,7 @@ import {
19
19
Value ,
20
20
VariableExpression ,
21
21
} from './types' ;
22
+ import { Pattern , SearchDirection } from '../pattern' ;
22
23
23
24
// ID of next lambda; incremented each time one is created
24
25
let lambdaNumber = 1 ;
@@ -620,7 +621,11 @@ export class EvaluationContext {
620
621
case '>' :
621
622
return lhs . value > rhs . value ;
622
623
case '=~' :
623
- return false ; // TODO
624
+ const pattern = Pattern . parser ( {
625
+ direction : SearchDirection . Forward ,
626
+ delimiter : '/' , // TODO: Are these params right?
627
+ } ) . tryParse ( toString ( lhs ) ) ;
628
+ return pattern . regex . test ( toString ( rhs ) ) ;
624
629
}
625
630
}
626
631
}
@@ -706,25 +711,43 @@ export class EvaluationContext {
706
711
) ;
707
712
}
708
713
// TODO: assert_inrange()
709
- // TODO: assert_match()
714
+ case 'assert_match' : {
715
+ const [ pattern , actual , msg ] = getArgs ( 2 , 3 ) ;
716
+ if ( this . evaluateComparison ( '=~' , true , actual ! , pattern ! ) ) {
717
+ return assertPassed ( ) ;
718
+ }
719
+ return assertFailed (
720
+ msg
721
+ ? toString ( msg )
722
+ : `Pattern '${ toString ( pattern ! ) } ' does not match '${ toString ( actual ! ) } '` ,
723
+ ) ;
724
+ }
710
725
case 'assert_nobeep' : {
711
726
return assertPassed ( ) ;
712
727
}
713
728
case 'assert_notequal' : {
714
729
const [ expected , actual , msg ] = getArgs ( 2 , 3 ) ;
715
- if ( this . evaluateComparison ( '!= ' , true , expected ! , actual ! ) ) {
730
+ if ( this . evaluateComparison ( '=~ ' , true , expected ! , actual ! ) ) {
716
731
return assertPassed ( ) ;
717
732
}
718
733
return assertFailed (
719
734
msg ? toString ( msg ) : `Expected not equal to ${ displayValue ( expected ! ) } ` ,
720
735
) ;
721
736
}
722
- // TODO: assert_notmatch()
737
+ case 'assert_notmatch' : {
738
+ const [ pattern , actual , msg ] = getArgs ( 2 , 3 ) ;
739
+ if ( this . evaluateComparison ( '=~' , true , actual ! , pattern ! ) ) {
740
+ return assertPassed ( ) ;
741
+ }
742
+ return assertFailed (
743
+ msg ? toString ( msg ) : `Pattern '${ toString ( pattern ! ) } ' does match '${ toString ( actual ! ) } '` ,
744
+ ) ;
745
+ }
723
746
case 'assert_report' : {
724
747
return assertFailed ( toString ( getArgs ( 1 ) [ 0 ] ! ) ) ;
725
748
}
726
749
case 'assert_true' : {
727
- const [ actual , msg ] = getArgs ( 2 , 3 ) ;
750
+ const [ actual , msg ] = getArgs ( 1 , 2 ) ;
728
751
if ( this . evaluateComparison ( '==' , true , bool ( true ) , actual ! ) ) {
729
752
return assertPassed ( ) ;
730
753
}
0 commit comments