given( $iterator = new LUT\Map(['a', 'b', 'c']), $lookbehind = new LUT\Lookbehind($iterator) ) ->when($result = iterator_to_array($iterator)) ->then ->array($result) ->isEqualTo(['a', 'b', 'c']); } public function case_check_behind() { $this ->given( $iterator = new LUT\Map(['a', 'b', 'c']), $lookbehind = new LUT\Lookbehind($iterator) ) ->when( $lookbehind->rewind(), $key = $lookbehind->key(), $current = $lookbehind->current(), $hasPrevious = $lookbehind->hasPrevious(), $previous = $lookbehind->getPrevious() ) ->then ->integer($key) ->isEqualTo(0) ->string($current) ->isEqualTo('a') ->boolean($hasPrevious) ->isFalse() ->variable($previous) ->isNull() ->when( $lookbehind->next(), $key = $lookbehind->key(), $current = $lookbehind->current(), $hasPrevious = $lookbehind->hasPrevious(), $previous = $lookbehind->getPrevious() ) ->then ->integer($key) ->isEqualTo(1) ->string($current) ->isEqualTo('b') ->boolean($hasPrevious) ->isTrue() ->string($previous) ->isEqualTo('a') ->when( $lookbehind->next(), $key = $lookbehind->key(), $current = $lookbehind->current(), $hasPrevious = $lookbehind->hasPrevious(), $previous = $lookbehind->getPrevious() ) ->then ->integer($key) ->isEqualTo(2) ->string($current) ->isEqualTo('c') ->boolean($hasPrevious) ->isTrue() ->string($previous) ->isEqualTo('b'); } public function case_double_rewind() { $this ->given( $iterator = new LUT\Map(['a', 'b', 'c']), $lookbehind = new LUT\Lookbehind($iterator) ) ->when( $lookbehind->rewind(), $key = $lookbehind->key(), $current = $lookbehind->current(), $hasPrevious = $lookbehind->hasPrevious() ) ->then ->integer($key) ->isEqualTo(0) ->string($current) ->isEqualTo('a') ->boolean($hasPrevious) ->isFalse() ->when( $lookbehind->rewind(), $key = $lookbehind->key(), $current = $lookbehind->current(), $hasPrevious = $lookbehind->hasPrevious() ) ->then ->integer($key) ->isEqualTo(0) ->string($current) ->isEqualTo('a') ->boolean($hasPrevious) ->isFalse(); } public function case_empty() { $this ->given( $iterator = new LUT\Mock(), $lookbehind = new LUT\Lookbehind($iterator) ) ->when( $lookbehind->rewind(), $valid = $lookbehind->valid() ) ->then ->boolean($valid) ->isFalse(); } }