| 1 | # | ||
| 2 | # Copyright (c) 2013-2021 Christian Jaeger, copying@christianjaeger.ch | ||
| 3 | # | ||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||
| 7 | # bundled with this file. | ||
| 8 | # | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | FP::Lazy::t -- tests for FP::Lazy | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | Had to move them here to avoid dependency cycle. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | package FP::Lazy::t; | ||
| 23 | |||
| 24 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 1 | ▶ | use warnings FATAL => 'uninitialized'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | |||
| 28 | 1 | ▶ | use FP::Lazy ":all"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 1 | ▶ | use Chj::TEST; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | 1 | ▶ | use FP::Show; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 31 | 1 | ▶ | use FP::List; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | |||
| 33 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 34 | 1 | our $foo = ""; | |
| 35 | |||
| 36 | 1 | ▶ | sub moo { |
|
Subroutine
moo: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 37 | 1 | my ($bar) = @_; | |
| 38 | 1 | local $foo = "Hello"; | |
| 39 | 1 | ▶ | lazy {"$foo $bar"} |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 40 | 1 | } | |
| 41 | 1 | moo("you")->force | |
| 42 | } | ||
| 43 | 1 | " you"; | |
| 44 | |||
| 45 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||
| 46 | 0 | ▶ | show(lazy { 1 / 0 }) |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 47 | 1 | } | |
| 48 | 1 | "lazy { 'DUMMY' }"; | |
| 49 | |||
| 50 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||
| 51 | 0 | ▶ | show(lazyT { 1 / 0 } "Fun") |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 52 | } | ||
| 53 | 1 | "lazyT { 'DUMMY' } 'Fun'"; | |
| 54 | |||
| 55 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 56 | 1 | ▶ | my $v = lazyT { cons(1, 2) } "FP::List::List"; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 57 | 1 | force $v; | |
| 58 | 1 | [is_promise($v), show($v)] | |
| 59 | } | ||
| 60 | 1 | [1, 'improper_list(1, 2)']; | |
| 61 | |||
| 62 | # method dispatch logic: | ||
| 63 | |||
| 64 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 65 | 1 | ▶ | (lazyT { list("a") } "FP::List::List")->rest |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 66 | } | ||
| 67 | 1 | null; | |
| 68 | |||
| 69 | 1 | ▶ | TEST { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 70 | 1 | ▶ | (lazyT { list("a") } "FP::List::Pair")->rest |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 71 | } | ||
| 72 | 1 | null; | |
| 73 | |||
| 74 | 1 | ▶ | TEST_EXCEPTION { |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||
| 75 | 0 | ▶ | (lazyT { 1 / 0 } "FP::List::Null")->rest |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 76 | } | ||
| 77 | 1 | 'can\'t take the rest of the empty list'; | |
| 78 | |||
| 79 | 1 | 1 | |