SQLite4
Check-in [19f7a96631]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for prefix-only and ignore-whitespace flags of sqlite4_num_from_text
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 19f7a96631d65cd2e15d47a23f7288f4a9b6b89f
User & Date: peterreid 2013-10-25 00:33:44
Context
2013-10-25
01:27
Test sqlite4_num_from_text with UTF16BE and UTF16LE check-in: 9c4e33cc5b user: peterreid tags: trunk
00:33
Add tests for prefix-only and ignore-whitespace flags of sqlite4_num_from_text check-in: 19f7a96631 user: peterreid tags: trunk
2013-10-24
23:59
Fixed flagging infinity as a real (instead of an integer) in sqlite4_num_from_text check-in: 73b8f01f49 user: peterreid tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/num.test.

   196    196     5.1   1   {sign:0 approx:0 e:0 m:1}
   197    197     5.2   1.0 {sign:0 approx:0 e:-1 m:10}
   198    198     5.3   1.  {sign:0 approx:0 e:0 m:1}
   199    199     5.4   1e0 {sign:0 approx:0 e:0 m:1}
   200    200   } {
   201    201     do_test num-9.1.$tn { sqlite4_num_from_text $in } [list {*}$out]
   202    202   }
          203  +
          204  +#-------------------------------------------------------------------------
          205  +# Test ignore-whitespace and prefix-only flags
          206  +#
          207  +foreach {tn in len flags out} {
          208  +  0     {14 }      -1 _    true
          209  +  1     {14 }      -1 w    false
          210  +  2     {   14 }   -1 w    false
          211  +  3     {14 }      2  _    false
          212  +  4     {14 }      3  _    true
          213  +  5     {14abc}    -1 _    true
          214  +  6     {14abc}    -1 p    false
          215  +  7     {+Inf   }  -1 p    false
          216  +  8     {   14 z}  -1 w    true
          217  +  9     {   14 z}  -1 wp   false
          218  +} {
          219  +  do_test num-9.2.$tn { 
          220  +    sqlite4_num_isnan [sqlite4_num_from_text $in $len $flags]
          221  +  } $out
          222  +}
   203    223   
   204    224   foreach {tn in out} {
   205    225     0     50                                            50
   206    226     1     -94                                           -94
   207    227     2     {sign:0 approx:0 e:4 m:2}                     20000
   208    228     3     9223372036854775807                           9223372036854775807
   209    229     4     -9223372036854775808                          -9223372036854775808

Changes to test/test_num.c.

    87     87     void *NotUsed,
    88     88     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
    89     89     int argc,              /* Number of arguments */
    90     90     char **argv            /* Text of each argument */
    91     91   ){
    92     92     sqlite4_num A;
    93     93     int len;
    94         -  if( argc!=2 && argc!=3 ){
           94  +  int flags;
           95  +  if( argc<2 || argc>4 ){
    95     96       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    96         -      " STRING\" or \"", argv[0], " STRING INTEGER\"", 0);
           97  +      " STRING\" or \"", argv[0], " STRING INTEGER\" or \"",
           98  +      argv[0], " STRING INTEGER STRING\"", 0);
    97     99       return TCL_ERROR;
    98    100     }
    99    101   
   100         -  if( argc==3 ){
          102  +  if( argc>=3 ){
   101    103       if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; 
   102    104     }else{
   103    105       len = -1;
   104    106     }
   105    107   
   106         -  A = sqlite4_num_from_text(argv[1], len, 0, 0);
          108  +  flags = 0;
          109  +  if( argc>=4 ){
          110  +    if( strchr(argv[3], 'w') ) flags |= SQLITE4_IGNORE_WHITESPACE;
          111  +    if( strchr(argv[3], 'p') ) flags |= SQLITE4_PREFIX_ONLY; 
          112  +  }
          113  +
          114  +  A = sqlite4_num_from_text(argv[1], len, flags, 0);
   107    115     append_num_result(interp, A);
   108    116     return TCL_OK;
   109    117   }
   110    118   
   111    119   static int test_num_text_is_real(
   112    120     void *NotUsed,
   113    121     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */