Ignore:
Timestamp:
Jan 19, 2024, 2:44:41 AM (20 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
ac939461
Parents:
59c8dff (diff), e8b3717 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/string-api-coverage.cfa

    r59c8dff rf988834  
    5151    sout | (s == "hello") | (s == "world");
    5252    sout | (s != "world") | (s != "hello");
    53     sout | ( frag == s(1,4) ) | ( s3   == s(1,4) );
    54     sout | ( s3   != s(1,4) ) | ( frag != s(1,4) );
    55     sout | ( s2(1,4) == s(1,4) ) | ( s3(1,4)   == s(1,4) );
    56     sout | ( s3(1,4) != s(1,4) ) | ( s2(1,4)   != s(1,4) );
    57     sout | ( s(1,4) == frag ) | ( s(1,4) == s3   );
    58     sout | ( s(1,4) != s3   ) | ( s(1,4) != frag );
    59     sout | ( s(1,4) == "ell"   ) | ( s(1,4) == "world" );
    60     sout | ( s(1,4) != "world" ) | ( s(1,4) != "ell"   );
     53    sout | ( frag == s(1,3) ) | ( s3   == s(1,3) );
     54    sout | ( s3   != s(1,3) ) | ( frag != s(1,3) );
     55    sout | ( s2(1,3) == s(1,3) ) | ( s3(1,3)   == s(1,3) );
     56    sout | ( s3(1,3) != s(1,3) ) | ( s2(1,3)   != s(1,3) );
     57    sout | ( s(1,3) == frag ) | ( s(1,3) == s3   );
     58    sout | ( s(1,3) != s3   ) | ( s(1,3) != frag );
     59    sout | ( s(1,3) == "ell"   ) | ( s(1,3) == "world" );
     60    sout | ( s(1,3) != "world" ) | ( s(1,3) != "ell"   );
    6161
    6262
     
    6666    //
    6767    {
    68         string b1 = { "1234567", 3 };
    69         sout | b1; // 123
     68        string b1 = "1234567";
     69        sout | b1; // 1234567
     70
     71        string b1x = { "1234567", 3 };
     72        sout | b1x; // 123
    7073
    7174        string b2 = s;
    7275        sout | b2; // hello
     76
     77        string b2x = { s, 4 };
     78        sout | b2x; // hell
    7379
    7480        // todo: a plain string &
     
    8894        b4 = s_constref;
    8995        sout | b4;  // world
     96
     97        string b5 = 'Q';
     98        sout | b5; // Q
     99
     100
    90101    }
    91102                                            assertWellFormedHandleList( 10 );
     103    //
     104    // Assignments
     105    //
     106    {
     107        string b = "xxx";
     108
     109        b = "1234567";
     110        sout | b; // 1234567
     111
     112        b = "xxx";
     113        b = s;
     114        sout | b; // hello
     115       
     116        b = "xxx";
     117        b = 'Q';
     118        sout | b; // Q
     119       
     120        b = "xxx";
     121        assign( b, "1234567", 3 );
     122        sout | b; // 123
     123
     124        b = "xxx";
     125        assign( b, s, 4 );
     126        sout | b; // hell
     127
     128        b = "xxx";
     129        strcpy(b, "1234567");
     130        sout | b; // 1234567
     131
     132        b = "xxx";
     133        strcpy(b, s);
     134        sout | b; // hello
     135       
     136        b = "xxx";
     137        strncpy( b, "1234567", 3 );
     138        sout | b; // 123
     139
     140        b = "xxx";
     141        strncpy( b, s, 4 );
     142        sout | b; // hell
     143    }
     144                                            assertWellFormedHandleList( 10 );
     145
     146
    92147
    93148    sout | size(s); // 5
     
    126181    sout | sx; // bye, friend
    127182
     183    sx = "o";
     184    strcat( sx, s );
     185    sout | sx; // ohello
     186
     187    sx = "o";
     188    append( sx, s, 4 );
     189    sout | sx; // ohell
     190
     191    sx = "o";
     192    strncat( sx, s, 4 );
     193    sout | sx; // ohell
     194
     195    sx = "o";
     196    strcat( sx, "mydarling" );
     197    sout | sx; // omydarling
     198
     199    sx = "o";
     200    append( sx, "mydarling", 2 );
     201    sout | sx; // omy
     202
     203    sx = "o";
     204    strncat( sx, "mydarling", 2 );
     205    sout | sx; // omy
     206
    128207    //
    129208    // repetition
    130209    //
     210
     211    sx = s;
     212    sx *= 4;
     213    sout | sx; // hellohellohellohello
     214
    131215    sx = s * 3;
    132216    sout | sx; // hellohellohello
     
    142226    //
    143227
    144     //...
     228    // Range cases treated thoroughly in "string-overwrite" test.
     229    // Composability with comparison and search are demoed above and below.
     230    // Coverage here adds the single-argument ("rest of string") overload.
     231
     232    sx = s;
     233    sout | sx(3); // lo
     234    sx(3) = "iocentric";
     235    sout | s | sx; // hello heliocentric
    145236
    146237    //
     
    244335        | find( alphabet        , "def")  // 3
    245336        | find( alphabet( 0, 26), "def")  // 3
    246         | find( alphabet( 2, 26), "def")  // 1
    247         | find( alphabet( 3, 26), "def")  // 0
    248         | find( alphabet( 4, 26), "def")  // 22, not found
    249         | find( alphabet( 4, 26),  "ef")  // 0
     337        | find( alphabet( 2, 24), "def")  // 1
     338        | find( alphabet( 3, 23), "def")  // 0
     339        | find( alphabet( 4, 22), "def")  // 22, not found
     340        | find( alphabet( 4, 22),  "ef")  // 0
    250341        | find( alphabet( 0,  6), "def")  // 3
    251342        | find( alphabet( 0,  5), "def")  // 5, not found
     
    255346        | includes( alphabet        , "def")  // true
    256347        | includes( alphabet( 0, 26), "def")  // true
    257         | includes( alphabet( 2, 26), "def")  // true
    258         | includes( alphabet( 3, 26), "def")  // true
    259         | includes( alphabet( 4, 26), "def")  // false
    260         | includes( alphabet( 4, 26),  "ef")  // true
     348        | includes( alphabet( 2, 24), "def")  // true
     349        | includes( alphabet( 3, 23), "def")  // true
     350        | includes( alphabet( 4, 22), "def")  // false
     351        | includes( alphabet( 4, 22),  "ef")  // true
    261352        | includes( alphabet( 0,  6), "def")  // true
    262353        | includes( alphabet( 0,  5), "def")  // false
     
    266357        | startsWith( alphabet        , "abc")  // true
    267358        | startsWith( alphabet( 0, 26), "abc")  // true
    268         | startsWith( alphabet( 1, 26), "abc")  // false
    269         | startsWith( alphabet( 1, 26),  "bc")  // true
     359        | startsWith( alphabet( 1, 25), "abc")  // false
     360        | startsWith( alphabet( 1, 25),  "bc")  // true
    270361        | startsWith( alphabet( 0, 26), "abc")  // true
    271362        | startsWith( alphabet( 0,  4), "abc")  // true
     
    281372        | endsWith( alphabet( 0, 25), "xy" )  // true
    282373        | endsWith( alphabet( 0, 26), "xyz")  // true
    283         | endsWith( alphabet(23, 26), "xyz")  // true
    284         | endsWith( alphabet(24, 26), "xyz")  // false
    285         | endsWith( alphabet(24, 26),  "yz")  // true
     374        | endsWith( alphabet(23,  3), "xyz")  // true
     375        | endsWith( alphabet(24,  2), "xyz")  // false
     376        | endsWith( alphabet(24,  2),  "yz")  // true
    286377        | endsWith( alphabet        , "abc"); // false
    287378
Note: See TracChangeset for help on using the changeset viewer.