[go: up one dir, main page]

Menu

[94a2b6]: / test / s4expect.d  Maximize  Restore  History

Download this file

109 lines (94 with data), 1.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
import std.stdio;
import std.traits: isAssignable, isCopyable, hasIndirections, Unqual;
import std.meta : AliasSeq, Filter, NoDuplicates;
import core.lifetime : forward;
import std.sumtype: SumType;
import io ;
version(none)
{
alias Result(T) = SumType!(T, Error);
}
auto
mod11(int i)
{
int r = i % 11 ;
if ( r )
return err!int(ERR.TEST, "not modulo");
// return err!int(551);
// return err!void(551);
return ok!int( r );
}
auto
pfce(int i)
{
static int s ;
if ( i )
{
s = i ;
return ok!(void*)(&s) ;
}
if ( i == 82 )
return err!(void*)(ERR.TEST ,"too ugly #");
return err!(void*)(57) ;
}
class C
{
int i ;
this(int ii)
{
this.i = ii ;
}
RV!C
add(int j)
{
if ( j % 2 )
return err!C(ERR.TEST);
this.i += j ;
return ok!C(null);
}
}
int
main()
{
version ( re_less_match ) {
string[] n = [ "abcd.h" , "efgh.zc" ] ;
string[] match = [ ".h", ".zc" ] ;
foreach ( nth, a ; n )
{
string[2] tail ;
tail[0] = a[$-2..$] ;
tail[1] = a[$-3..$] ;
foreach( i, m ; match )
foreach( j, t ; tail )
if ( m == t )
writeln("MATCHES! ", i, "/", j, "," , match[j], " => ", n[nth] );
}
}
auto rv = mod11(33);
writeln("Got : ", rv );
assert(rv);
assert(!rv.isErr);
assert(rv.hasValue);
assert(!rv.hasError);
assert(rv.value == 0);
writeln("Got : ", rv.hasError );
auto rv2 = mod11(42);
writeln("Got : ", rv2 );
assert(rv2.isErr);
assert(!rv2.hasValue);
assert(rv2.hasError);
// assert(rv2.error == "not modulo");
assert(rv2.error == ERR.TEST);
writeln("Msg: ", rv2.getmsg );
int ival = 42 ;
auto p = pfce(ival);
if (p.isErr)
writeln("E pfce : ", p.error , " ", p.getmsg );
else
writeln("pfce : ", typeof(p.value).stringof , " ", p.value );
return 0 ;
}
/* Local Variables: */
/* mode: d */
/* buffer-save-without-query: t */
/* End: */