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 Unified Diffs Show Whitespace Changes Patch

Changes to test/num.test.

196
197
198
199
200
201
202




















203
204
205
206
207
208
209
  5.1   1   {sign:0 approx:0 e:0 m:1}
  5.2   1.0 {sign:0 approx:0 e:-1 m:10}
  5.3   1.  {sign:0 approx:0 e:0 m:1}
  5.4   1e0 {sign:0 approx:0 e:0 m:1}
} {
  do_test num-9.1.$tn { sqlite4_num_from_text $in } [list {*}$out]
}





















foreach {tn in out} {
  0     50                                            50
  1     -94                                           -94
  2     {sign:0 approx:0 e:4 m:2}                     20000
  3     9223372036854775807                           9223372036854775807
  4     -9223372036854775808                          -9223372036854775808







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  5.1   1   {sign:0 approx:0 e:0 m:1}
  5.2   1.0 {sign:0 approx:0 e:-1 m:10}
  5.3   1.  {sign:0 approx:0 e:0 m:1}
  5.4   1e0 {sign:0 approx:0 e:0 m:1}
} {
  do_test num-9.1.$tn { sqlite4_num_from_text $in } [list {*}$out]
}

#-------------------------------------------------------------------------
# Test ignore-whitespace and prefix-only flags
#
foreach {tn in len flags out} {
  0     {14 }      -1 _    true
  1     {14 }      -1 w    false
  2     {   14 }   -1 w    false
  3     {14 }      2  _    false
  4     {14 }      3  _    true
  5     {14abc}    -1 _    true
  6     {14abc}    -1 p    false
  7     {+Inf   }  -1 p    false
  8     {   14 z}  -1 w    true
  9     {   14 z}  -1 wp   false
} {
  do_test num-9.2.$tn { 
    sqlite4_num_isnan [sqlite4_num_from_text $in $len $flags]
  } $out
}

foreach {tn in out} {
  0     50                                            50
  1     -94                                           -94
  2     {sign:0 approx:0 e:4 m:2}                     20000
  3     9223372036854775807                           9223372036854775807
  4     -9223372036854775808                          -9223372036854775808

Changes to test/test_num.c.

87
88
89
90
91
92
93
94

95
96

97
98
99
100
101
102
103
104
105






106
107
108
109
110
111
112
113
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  int argc,              /* Number of arguments */
  char **argv            /* Text of each argument */
){
  sqlite4_num A;
  int len;
  if( argc!=2 && argc!=3 ){

    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
      " STRING\" or \"", argv[0], " STRING INTEGER\"", 0);

    return TCL_ERROR;
  }

  if( argc==3 ){
    if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; 
  }else{
    len = -1;
  }







  A = sqlite4_num_from_text(argv[1], len, 0, 0);
  append_num_result(interp, A);
  return TCL_OK;
}

static int test_num_text_is_real(
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */







|
>

|
>



|





>
>
>
>
>
>
|







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

  if( argc>=3 ){
    if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; 
  }else{
    len = -1;
  }

  flags = 0;
  if( argc>=4 ){
    if( strchr(argv[3], 'w') ) flags |= SQLITE4_IGNORE_WHITESPACE;
    if( strchr(argv[3], 'p') ) flags |= SQLITE4_PREFIX_ONLY; 
  }

  A = sqlite4_num_from_text(argv[1], len, flags, 0);
  append_num_result(interp, A);
  return TCL_OK;
}

static int test_num_text_is_real(
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */