Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1562

Show
Ignore:
Timestamp:
05/27/10 20:42:38 (15 years ago)
Author:
rsinfu
Message:

std.conv unittests: print warning messages for problematic strto*() implementations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/conv.d

    r1559 r1562  
    18721872    assert( f == 123e+2f ); 
    18731873 
    18741874    f = to!float( "123e-2" ); 
    18751875    assert( f == 123e-2f ); 
    18761876    f = to!float( "123." ); 
    18771877    assert( f == 123.f ); 
    18781878    f = to!float( ".456" ); 
    18791879    assert( f == .456f ); 
    18801880 
    18811881    // min and max 
    1882     f = to!float("1.17549e-38"); 
    1883     assert(feq(cast(real)f, cast(real)1.17549e-38)); 
    1884     assert(feq(cast(real)f, cast(real)float.min_normal)); 
    1885     f = to!float("3.4028e+38"); 
    1886     assert(to!string(f) == to!string(3.40282e+38)); 
     1882    try 
     1883    { 
     1884        f = to!float("1.17549e-38"); 
     1885        assert(feq(cast(real)f, cast(real)1.17549e-38)); 
     1886        assert(feq(cast(real)f, cast(real)float.min_normal)); 
     1887        f = to!float("3.40282e+38"); 
     1888        assert(to!string(f) == to!string(3.40282e+38)); 
     1889    } 
     1890    catch (ConvError e) // strtof() bug on some platforms 
     1891    { 
     1892        printf(" --- std.conv(%u) broken test ---\n", cast(uint) __LINE__); 
     1893        printf("   (%.*s)\n", e.msg); 
     1894    } 
    18871895 
    18881896    // nan 
    18891897    f = to!float("nan"); 
    18901898    assert(to!string(f) == to!string(float.nan)); 
    18911899 
    18921900    bool ok = false; 
    18931901    try 
    18941902    { 
    18951903        to!float("\x00"); 
    18961904    } 
     
    19211929    d = to!double( "123e-2" ); 
    19221930    assert( d == 123e-2 ); 
    19231931    d = to!double( "123." ); 
    19241932    assert( d == 123. ); 
    19251933    d = to!double( ".456" ); 
    19261934    assert( d == .456 ); 
    19271935    d = to!double( "1.23456E+2" ); 
    19281936    assert( d == 1.23456E+2 ); 
    19291937 
    19301938    // min and max 
    1931     d = to!double("2.22508e-308"); 
    1932     assert(feq(cast(real)d, cast(real)2.22508e-308)); 
    1933     assert(feq(cast(real)d, cast(real)double.min_normal)); 
    1934     d = to!double("1.79769e+308"); 
    1935     assert(to!string(d) == to!string(1.79769e+308)); 
    1936     assert(to!string(d) == to!string(double.max)); 
     1939    try 
     1940    { 
     1941        d = to!double("2.22508e-308"); 
     1942        assert(feq(cast(real)d, cast(real)2.22508e-308)); 
     1943        assert(feq(cast(real)d, cast(real)double.min_normal)); 
     1944        d = to!double("1.79769e+308"); 
     1945        assert(to!string(d) == to!string(1.79769e+308)); 
     1946        assert(to!string(d) == to!string(double.max)); 
     1947    } 
     1948    catch (ConvError e) // strtod() bug on some platforms 
     1949    { 
     1950        printf(" --- std.conv(%u) broken test ---\n", cast(uint) __LINE__); 
     1951        printf("   (%.*s)\n", e.msg); 
     1952    } 
    19371953 
    19381954    // nan 
    19391955    d = to!double("nan"); 
    19401956    assert(to!string(d) == to!string(double.nan)); 
    19411957    //assert(cast(real)d == cast(real)double.nan); 
    19421958 
    19431959    bool ok = false; 
    19441960    try 
    19451961    { 
    19461962        to!double("\x00"); 
     
    19741990    assert(r == 123L); 
    19751991    r = to!real(".456"); 
    19761992    assert(r == .456L); 
    19771993 
    19781994    r = to!real("1.23456e+2"); 
    19791995    assert(feq(r,  1.23456e+2L)); 
    19801996    r = to!real(to!string(real.max / 2L)); 
    19811997    assert(to!string(r) == to!string(real.max / 2L)); 
    19821998 
    19831999    // min and max 
    1984     r = to!real(to!string(real.min_normal)); 
    1985     assert(to!string(r) == to!string(real.min_normal)); 
    1986     r = to!real(to!string(real.max)); 
    1987     assert(to!string(r) == to!string(real.max)); 
     2000    try 
     2001    { 
     2002        r = to!real(to!string(real.min_normal)); 
     2003        assert(to!string(r) == to!string(real.min_normal)); 
     2004        r = to!real(to!string(real.max)); 
     2005        assert(to!string(r) == to!string(real.max)); 
     2006    } 
     2007    catch (ConvError e) // strtold() bug on some platforms 
     2008    { 
     2009        printf(" --- std.conv(%u) broken test ---\n", cast(uint) __LINE__); 
     2010        printf("   (%.*s)\n", e.msg); 
     2011    } 
    19882012 
    19892013    // nan 
    19902014    r = to!real("nan"); 
    19912015    assert(to!string(r) == to!string(real.nan)); 
    19922016    //assert(r == real.nan); 
    19932017 
    19942018    r = to!real(to!string(real.nan)); 
    19952019    assert(to!string(r) == to!string(real.nan)); 
    19962020    //assert(r == real.nan); 
    19972021