Changeset 75e2286


Ignore:
Timestamp:
Feb 11, 2024, 3:09:15 PM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
da22726
Parents:
7b93027e
Message:

add tests for getline and quoted input manipulators

Location:
tests/collections
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/.expect/string-istream-manip.txt

    r7b93027e r75e2286  
    707014
    717115
     7216 get this line
     7317 @# this line 1)-{}
     7418 @# this line 1)-{}
     7519 abc
     7620 abc 
     7721  d d
     78
     79d
     8022              ZC44%
     8123              ZC44%
    72821 yyyyyyyyyyyyyyyyyyyy
    73832 abcxxx
     
    859514
    869615
     9716 get this line
     9817 @# this line 1)-{}
     9918 @# this line 1)-{}
     10019 abc
     10120 abc 
     10221  d d
     103
     104d
     10522              ZC44%
     10623              ZC44%
  • tests/collections/.in/string-istream-manip.txt

    r7b93027e r75e2286  
    3838aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
    3939uuuuu
     40get this line
     41@# this line 1)-{}%
     42@# this line 2)-{}%
     43    "abc"
     44'abc  '
     45{ d d
     46
     47d }
     48X               ZC44%Y
     49X               ZC55%Y
    4050abc
    4151cccccb
     
    4555aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
    4656uuuuu
     57get this line
     58@# this line 1)-{}%
     59@# this line 2)-{}%
     60    "abc"
     61'abc  '
     62{ d d
     63
     64d }
     65X               ZC44%Y
     66X               ZC55%Y
  • tests/collections/string-istream-manip.cfa

    r7b93027e r75e2286  
    1010// The test cases that use plainjane(-) are exercising the via-manipulator code path,
    1111// just with trivial manipulation.
    12 static _Istream_Sstr plainjane( string     & s )  { return (_Istream_Sstr)@{  s, {{0p}, -1, {.flags.rwd : false}} }; }
     12static _Istream_Sstr plainjane( string & s )  { return (_Istream_Sstr)@{  s, {{0p}, -1, {.flags.rwd : false}} }; }
    1313static _Istream_Rstr plainjane( string_res & s )  { return (_Istream_Rstr)@{ &s, {{0p}, -1, {.flags.rwd : false}} }; }
    1414
    1515static void forceStringHeapFreeSpaceTo(int desiredSize) {
    16     for (1_000_000) {
    17         string x = "a";
    18         (void)x;
    19       if (desiredSize == DEBUG_string_bytes_avail_until_gc(DEBUG_string_heap())) return;
    20     }
    21     sout | "Unable to force size" | desiredSize | "in 1,000,000 tries";
     16        for (1_000_000) {
     17                string x = "a";
     18                (void)x;
     19                if (desiredSize == DEBUG_string_bytes_avail_until_gc(DEBUG_string_heap())) return;
     20        }
     21        sout | "Unable to force size" | desiredSize | "in 1,000,000 tries";
    2222}
    2323
    2424int main() {
    25     // These "pre" cases deal with issues analogous to the "pre" cases of io/manipulatorsInput.
    26     // The acceptance criterion is simpler but driving the cases is harder.
    27     // The tests just read strings and echo what they read; acceptance of simple echoing assures
    28     // no spurious splitting merging.
    29     // The lengths of the strings are chosen to match white-box knowledge of when the string layer
    30     // has tor drive the cstring layer through a second iteration:
    31     //  - for no-manip, lengths are near the room at end of string heap
    32     //    (chosen target size of 9 showed the original bug on preS2, aligned with the other cases)
    33     //  - for manip, lengths are near the auxiliary buffer size of 128
    34     // Only first case repeats for string_res; rest run only from the passthru string layer.
    35     // Similarly, the manipulator breadth isn't checked at the cstring layer either.
    36     {
    37         // S: string, no manipulator
    38         void echoTillX(const char * casename) {
    39             string s;
    40             // loop assumes behaviour not tested until main-case #15:
    41             // on reading nothing, the prior string value is left alone
    42             do {
    43                 s = "";
    44                 forceStringHeapFreeSpaceTo(9);
    45                 sin | s;
    46                 sout | casename | s;
    47             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    48         }
    49         echoTillX("preS1");
    50         echoTillX("preS2");
    51         echoTillX("preS3");
    52         echoTillX("preS4");
    53     }
    54     {
    55         // SMN: string, manipulator for no-op
    56         void echoTillX(const char * casename) {
    57             string s;
    58             do {
    59                 s = "";
    60                 sin | plainjane( s );
    61                 sout | casename | s;
    62             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    63         }
    64         echoTillX("preSMN1");
    65         echoTillX("preSMN2");
    66         echoTillX("preSMN3");
    67         echoTillX("preSMN4");
    68     }
    69     {
    70         // RMN: string_res, manipulator for no-op
    71         void echoTillX(const char * casename) {
    72             string_res s;
    73             do {
    74                 s = "";
    75                 sin | plainjane( s );
    76                 sout | casename | s;
    77             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    78         }
    79         echoTillX("preRMN1");
    80         echoTillX("preRMN2");
    81         echoTillX("preRMN3");
    82         echoTillX("preRMN4");
    83     }
    84     {
    85         // SMI: string, manipulator `incl`
    86         void echoTillX(const char * casename) {
    87             string s;
    88             do {
    89                 s = "";
    90                 sin | skip("-\n");
    91                 sin | incl( ".:|# x", s );
    92                 sout | casename | " \"" | s | "\"";
    93             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    94         }
    95         echoTillX("preSMI1");
    96         echoTillX("preSMI2");
    97         echoTillX("preSMI3");
    98         echoTillX("preSMI4");
    99     }
    100     {
    101         // SME: string, manipulator `excl`
    102         void echoTillX(const char * casename) {
    103             string s;
    104             do {
    105                 s = "";
    106                 sin | skip("-\n");
    107                 sin | excl( "-\n", s );
    108                 sout | casename | " \"" | s | "\"";
    109             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    110         }
    111         echoTillX("preSME1");
    112         echoTillX("preSME2");
    113         echoTillX("preSME3");
    114         echoTillX("preSME4");
    115     }
    116     sin | skip("-\n");
    117     {
    118         // SMG: string, manipulator `getline`
    119         void echoTillX(const char * casename) {
    120             string s;
    121             do {
    122                 s = "";
    123                 sin | getline( s );
    124                 sout | casename | s;
    125             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    126         }
    127         echoTillX("preSMG1");
    128         echoTillX("preSMG2");
    129         echoTillX("preSMG3");
    130         echoTillX("preSMG4");
    131     }
    132     {
    133         // SMD: string, manipulator (`getline` with custom) delimiter
    134         void echoTillX(const char * casename) {
    135             string s;
    136             do {
    137                 s = "";
    138                 sin | getline( s, '@' );
    139                 sout | casename | s;
    140             } while ( size(s) > 0 && s[size(s)-1] != 'x' );
    141             sin | skip(" \n");
    142         }
    143         echoTillX("preSMD1");
    144         echoTillX("preSMD2");
    145         echoTillX("preSMD3");
    146         echoTillX("preSMD4");
    147     }
    148 
    149     /* Keep harmonized with io/manipulatorsInput */
    150     {
    151         string s = "yyyyyyyyyyyyyyyyyyyy";
    152         char sk[] = "abc";
    153         sin | "abc " | skip( sk ) | skip( 5 );          sout | "1" | s;
    154         sin | s;                                        sout | "2" | s;
    155         sin | ignore( s );                              sout | "3" | s;
    156         sin | wdi( 8, s );                              sout | "4" | s;
    157         sin | ignore( wdi( 8, s ) );                    sout | "5" | s;
    158 
    159         sin | incl( "abc", s );                         sout | "6" | s;
    160         sin | excl( "abc", s );                         sout | "7" | s;
    161         sin | ignore( incl( "abc", s ) );               sout | "8" | s;
    162         sin | ignore( excl( "abc", s ) );               sout | "9" | s;
    163         sin | incl( "abc", wdi( 8, s ) );               sout | "10" | s;
    164         sin | excl( "abc", wdi( 8, s ) );               sout | "11" | s;
    165         sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    166         sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
     25        // These "pre" cases deal with issues analogous to the "pre" cases of io/manipulatorsInput.
     26        // The acceptance criterion is simpler but driving the cases is harder.
     27        // The tests just read strings and echo what they read; acceptance of simple echoing assures
     28        // no spurious splitting merging.
     29        // The lengths of the strings are chosen to match white-box knowledge of when the string layer
     30        // has tor drive the cstring layer through a second iteration:
     31        //  - for no-manip, lengths are near the room at end of string heap
     32        //      (chosen target size of 9 showed the original bug on preS2, aligned with the other cases)
     33        //  - for manip, lengths are near the auxiliary buffer size of 128
     34        // Only first case repeats for string_res; rest run only from the passthru string layer.
     35        // Similarly, the manipulator breadth isn't checked at the cstring layer either.
     36        {
     37                // S: string, no manipulator
     38                void echoTillX(const char * casename) {
     39                        string s;
     40                        // loop assumes behaviour not tested until main-case #15:
     41                        // on reading nothing, the prior string value is left alone
     42                        do {
     43                                s = "";
     44                                forceStringHeapFreeSpaceTo(9);
     45                                sin | s;
     46                                sout | casename | s;
     47                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     48                }
     49                echoTillX("preS1");
     50                echoTillX("preS2");
     51                echoTillX("preS3");
     52                echoTillX("preS4");
     53        }
     54        {
     55                // SMN: string, manipulator for no-op
     56                void echoTillX(const char * casename) {
     57                        string s;
     58                        do {
     59                                s = "";
     60                                sin | plainjane( s );
     61                                sout | casename | s;
     62                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     63                }
     64                echoTillX("preSMN1");
     65                echoTillX("preSMN2");
     66                echoTillX("preSMN3");
     67                echoTillX("preSMN4");
     68        }
     69        {
     70                // RMN: string_res, manipulator for no-op
     71                void echoTillX(const char * casename) {
     72                        string_res s;
     73                        do {
     74                                s = "";
     75                                sin | plainjane( s );
     76                                sout | casename | s;
     77                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     78                }
     79                echoTillX("preRMN1");
     80                echoTillX("preRMN2");
     81                echoTillX("preRMN3");
     82                echoTillX("preRMN4");
     83        }
     84        {
     85                // SMI: string, manipulator `incl`
     86                void echoTillX(const char * casename) {
     87                        string s;
     88                        do {
     89                                s = "";
     90                                sin | skip("-\n");
     91                                sin | incl( ".:|# x", s );
     92                                sout | casename | " \"" | s | "\"";
     93                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     94                }
     95                echoTillX("preSMI1");
     96                echoTillX("preSMI2");
     97                echoTillX("preSMI3");
     98                echoTillX("preSMI4");
     99        }
     100        {
     101                // SME: string, manipulator `excl`
     102                void echoTillX(const char * casename) {
     103                        string s;
     104                        do {
     105                                s = "";
     106                                sin | skip("-\n");
     107                                sin | excl( "-\n", s );
     108                                sout | casename | " \"" | s | "\"";
     109                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     110                }
     111                echoTillX("preSME1");
     112                echoTillX("preSME2");
     113                echoTillX("preSME3");
     114                echoTillX("preSME4");
     115        }
     116        sin | skip("-\n");
     117        {
     118                // SMG: string, manipulator `getline`
     119                void echoTillX(const char * casename) {
     120                        string s;
     121                        do {
     122                                s = "";
     123                                sin | getline( s );
     124                                sout | casename | s;
     125                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     126                }
     127                echoTillX("preSMG1");
     128                echoTillX("preSMG2");
     129                echoTillX("preSMG3");
     130                echoTillX("preSMG4");
     131        }
     132        {
     133                // SMD: string, manipulator (`getline` with custom) delimiter
     134                void echoTillX(const char * casename) {
     135                        string s;
     136                        do {
     137                                s = "";
     138                                sin | getline( s, '@' );
     139                                sout | casename | s;
     140                        } while ( size(s) > 0 && s[size(s)-1] != 'x' );
     141                        sin | skip(" \n");
     142                }
     143                echoTillX("preSMD1");
     144                echoTillX("preSMD2");
     145                echoTillX("preSMD3");
     146                echoTillX("preSMD4");
     147        }
     148        // Keep harmonized with io/manipulatorsInput.
     149        {
     150                string s = "yyyyyyyyyyyyyyyyyyyy";
     151                char sk[] = "abc";
     152                sin | "abc " | skip( sk ) | skip( 5 );                  sout | "1" | s;
     153                sin | s;                                                                                sout | "2" | s;
     154                sin | ignore( s );                                                              sout | "3" | s;
     155                sin | wdi( 8, s );                                                              sout | "4" | s;
     156                sin | ignore( wdi( 8, s ) );                                    sout | "5" | s;
     157
     158                sin | incl( "abc", s );                                                 sout | "6" | s;
     159                sin | excl( "abc", s );                                                 sout | "7" | s;
     160                sin | ignore( incl( "abc", s ) );                               sout | "8" | s;
     161                sin | ignore( excl( "abc", s ) );                               sout | "9" | s;
     162                sin | incl( "abc", wdi( 8, s ) );                               sout | "10" | s;
     163                sin | excl( "abc", wdi( 8, s ) );                               sout | "11" | s;
     164                sin | ignore( incl( "abc", wdi( 8, s ) ) );             sout | "12" | s;
     165                sin | ignore( excl( "abc", wdi( 8, s ) ) );             sout | "13" | s;
     166                sin | nl;
     167
     168                s = "q";
     169                sin | incl( "abc", s );                                                 sout | "14" | s;
     170                s = "q";
     171                sin | excl( "u", s );                                                   sout | "15" | s;
     172                sin | skip( "u" ) | nl;
     173
     174                sin | getline( s );                                                             sout | "16" | s;
     175                sin | getline( s, '%' ) | nl;                                   sout | "17" | s;
     176                sin | ignore( getline( s, '%' ) ) | nl;                 sout | "18" | s;
     177
     178                sin | quoted( s );                                                              sout | "19" | s;
     179                sin | quoted( s, '\'' );                                                sout | "20" | s;
     180                sin | quoted( s, '{', '}' );                                    sout | "21" | s;
     181                sin | quoted( s, 'X', 'Y' );                                    sout | "22" | s;
     182                sin | ignore( quoted( s, 'X', 'Y' ) );                  sout | "23" | s;
     183                sin | nl;
     184        }
     185        // Full repeat on string_res layer assures the full manipulator vocabulary is supported there.
     186        {
     187                string_res s = "yyyyyyyyyyyyyyyyyyyy";
     188                char sk[] = "abc";
     189                sin | "abc " | skip( sk ) | skip( 5 );                  sout | "1" | s;
     190                sin | s;                                                                                sout | "2" | s;
     191                sin | ignore( s );                                                              sout | "3" | s;
     192                sin | wdi( 8, s );                                                              sout | "4" | s;
     193                sin | ignore( wdi( 8, s ) );                                    sout | "5" | s;
     194
     195                sin | incl( "abc", s );                                                 sout | "6" | s;
     196                sin | excl( "abc", s );                                                 sout | "7" | s;
     197                sin | ignore( incl( "abc", s ) );                               sout | "8" | s;
     198                sin | ignore( excl( "abc", s ) );                               sout | "9" | s;
     199                sin | incl( "abc", wdi( 8, s ) );                               sout | "10" | s;
     200                sin | excl( "abc", wdi( 8, s ) );                               sout | "11" | s;
     201                sin | ignore( incl( "abc", wdi( 8, s ) ) );             sout | "12" | s;
     202                sin | ignore( excl( "abc", wdi( 8, s ) ) );             sout | "13" | s;
    167203                sin | "\n";
    168204
    169205                s = "q";
    170                 sin | incl( "abc", s );                         sout | "14" | s;
    171                 s = "q";
    172                 sin | excl( "u", s );                           sout | "15" | s;
     206                sin | incl( "abc", s );                                                 sout | "14" | s;
     207                s = "q";
     208                sin | excl( "u", s );                                                   sout | "15" | s;
    173209                sin | skip( "u" );
    174210                sin | "\n";
    175         }
    176     // Full repeat on string_res layer assures the full manipulator vocabulary is supported there.
    177     {
    178         string_res s = "yyyyyyyyyyyyyyyyyyyy";
    179         char sk[] = "abc";
    180         sin | "abc " | skip( sk ) | skip( 5 );          sout | "1" | s;
    181         sin | s;                                        sout | "2" | s;
    182         sin | ignore( s );                              sout | "3" | s;
    183         sin | wdi( 8, s );                              sout | "4" | s;
    184         sin | ignore( wdi( 8, s ) );                    sout | "5" | s;
    185 
    186         sin | incl( "abc", s );                         sout | "6" | s;
    187         sin | excl( "abc", s );                         sout | "7" | s;
    188         sin | ignore( incl( "abc", s ) );               sout | "8" | s;
    189         sin | ignore( excl( "abc", s ) );               sout | "9" | s;
    190         sin | incl( "abc", wdi( 8, s ) );               sout | "10" | s;
    191         sin | excl( "abc", wdi( 8, s ) );               sout | "11" | s;
    192         sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    193         sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
    194                 sin | "\n";
    195 
    196                 s = "q";
    197                 sin | incl( "abc", s );                         sout | "14" | s;
    198                 s = "q";
    199                 sin | excl( "u", s );                           sout | "15" | s;
    200                 sin | skip( "u" );
    201                 sin | "\n";
    202     }
     211                sin | getline( s );                                                             sout | "16" | s;
     212                sin | getline( s, '%' ) | nl;                                   sout | "17" | s;
     213                sin | ignore( getline( s, '%' ) ) | nl;                 sout | "18" | s;
     214
     215                sin | quoted( s );                                                              sout | "19" | s;
     216                sin | quoted( s, '\'' );                                                sout | "20" | s;
     217                sin | quoted( s, '{', '}' );                                    sout | "21" | s;
     218                sin | quoted( s, 'X', 'Y' );                                    sout | "22" | s;
     219                sin | ignore( quoted( s, 'X', 'Y' ) );                  sout | "23" | s;
     220        }
    203221}
Note: See TracChangeset for help on using the changeset viewer.