os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/indexObj.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # This file is a Tcl script to test out the the procedures in file
     2 # tkIndexObj.c, which implement indexed table lookups.  The tests here
     3 # are organized in the standard fashion for Tcl tests.
     4 #
     5 # Copyright (c) 1997 Sun Microsystems, Inc.
     6 # Copyright (c) 1998-1999 by Scriptics Corporation.
     7 #
     8 # See the file "license.terms" for information on usage and redistribution
     9 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    10 #
    11 # RCS: @(#) $Id: indexObj.test,v 1.7.18.4 2006/04/06 18:57:30 dgp Exp $
    12 
    13 if {[lsearch [namespace children] ::tcltest] == -1} {
    14     package require tcltest
    15     namespace import -force ::tcltest::*
    16 }
    17 
    18 if {[info commands testindexobj] == {}} {
    19     puts "This application hasn't been compiled with the \"testindexobj\""
    20     puts "command, so I can't test Tcl_GetIndexFromObj etc."
    21     ::tcltest::cleanupTests
    22     return 
    23 }
    24 
    25 test indexObj-1.1 {exact match} {
    26     testindexobj 1 1 xyz abc def xyz alm
    27 } {2}
    28 test indexObj-1.2 {exact match} {
    29     testindexobj 1 1 abc abc def xyz alm
    30 } {0}
    31 test indexObj-1.3 {exact match} {
    32     testindexobj 1 1 alm abc def xyz alm
    33 } {3}
    34 test indexObj-1.4 {unique abbreviation} {
    35     testindexobj 1 1 xy abc def xalb xyz alm
    36 } {3}
    37 test indexObj-1.5 {multiple abbreviations and exact match} {
    38     testindexobj 1 1 x abc def xalb xyz alm x
    39 } {5}
    40 test indexObj-1.6 {forced exact match} {
    41     testindexobj 1 0 xy abc def xalb xy alm
    42 } {3}
    43 test indexObj-1.7 {forced exact match} {
    44     testindexobj 1 0 x abc def xalb xyz alm x
    45 } {5}
    46 test indexObj-1.8 {exact match of empty values} {
    47     testindexobj 1 1 {} a aa aaa {} b bb bbb
    48 } 3
    49 test indexObj-1.9 {exact match of empty values} {
    50     testindexobj 1 0 {} a aa aaa {} b bb bbb
    51 } 3
    52 
    53 test indexObj-2.1 {no match} {
    54     list [catch {testindexobj 1 1 dddd abc def xalb xyz alm x} msg] $msg
    55 } {1 {bad token "dddd": must be abc, def, xalb, xyz, alm, or x}}
    56 test indexObj-2.2 {no match} {
    57     list [catch {testindexobj 1 1 dddd abc} msg] $msg
    58 } {1 {bad token "dddd": must be abc}}
    59 test indexObj-2.3 {no match: no abbreviations} {
    60     list [catch {testindexobj 1 0 xy abc def xalb xyz alm} msg] $msg
    61 } {1 {bad token "xy": must be abc, def, xalb, xyz, or alm}}
    62 test indexObj-2.4 {ambiguous value} {
    63     list [catch {testindexobj 1 1 d dumb daughter a c} msg] $msg
    64 } {1 {ambiguous token "d": must be dumb, daughter, a, or c}}
    65 test indexObj-2.5 {omit error message} {
    66     list [catch {testindexobj 0 1 d x} msg] $msg
    67 } {1 {}}
    68 test indexObj-2.6 {TCL_EXACT => no "ambiguous" error message} {
    69     list [catch {testindexobj 1 0 d dumb daughter a c} msg] $msg
    70 } {1 {bad token "d": must be dumb, daughter, a, or c}}
    71 test indexObj-2.7 {exact match of empty values} {
    72     list [catch {testindexobj 1 1 {} a b c} msg] $msg
    73 } {1 {ambiguous token "": must be a, b, or c}}
    74 test indexObj-2.8 {exact match of empty values: singleton case} {
    75     list [catch {testindexobj 1 0 {} a} msg] $msg
    76 } {1 {bad token "": must be a}}
    77 test indexObj-2.9 {non-exact match of empty values: singleton case} {
    78     # NOTE this is a special case.  Although the empty string is a
    79     # unique prefix, we have an established history of rejecting
    80     # empty lookup keys, requiring any unique prefix match to have
    81     # at least one character.
    82     list [catch {testindexobj 1 1 {} a} msg] $msg
    83 } {1 {bad token "": must be a}}
    84 
    85 test indexObj-3.1 {cache result to skip next lookup} {
    86     testindexobj check 42
    87 } {42}
    88 
    89 test indexObj-4.1 {free old internal representation} {
    90     set x {a b}
    91     lindex $x 1
    92     testindexobj 1 1 $x abc def {a b} zzz
    93 } {2}
    94 
    95 test indexObj-5.1 {Tcl_WrongNumArgs} {
    96     testwrongnumargs 1 "?option?" mycmd
    97 } "wrong # args: should be \"mycmd ?option?\""
    98 test indexObj-5.2 {Tcl_WrongNumArgs} {
    99     testwrongnumargs 2 "bar" mycmd foo
   100 } "wrong # args: should be \"mycmd foo bar\""
   101 test indexObj-5.3 {Tcl_WrongNumArgs} {
   102     testwrongnumargs 0 "bar" mycmd foo
   103 } "wrong # args: should be \"bar\""
   104 test indexObj-5.4 {Tcl_WrongNumArgs} {
   105     testwrongnumargs 0 "" mycmd foo
   106 } "wrong # args: should be \"\""
   107 test indexObj-5.5 {Tcl_WrongNumArgs} {
   108     testwrongnumargs 1 "" mycmd foo
   109 } "wrong # args: should be \"mycmd\""
   110 test indexObj-5.6 {Tcl_WrongNumArgs} {
   111     testwrongnumargs 2 "" mycmd foo
   112 } "wrong # args: should be \"mycmd foo\""
   113 
   114 test indexObj-6.1 {Tcl_GetIndexFromObjStruct} {
   115     set x a
   116     testgetindexfromobjstruct $x 0
   117 } "wrong # args: should be \"testgetindexfromobjstruct a 0\""
   118 test indexObj-6.2 {Tcl_GetIndexFromObjStruct} {
   119     set x a
   120     testgetindexfromobjstruct $x 0
   121     testgetindexfromobjstruct $x 0
   122 } "wrong # args: should be \"testgetindexfromobjstruct a 0\""
   123 test indexObj-6.3 {Tcl_GetIndexFromObjStruct} {
   124     set x c
   125     testgetindexfromobjstruct $x 1
   126 } "wrong # args: should be \"testgetindexfromobjstruct c 1\""
   127 test indexObj-6.4 {Tcl_GetIndexFromObjStruct} {
   128     set x c
   129     testgetindexfromobjstruct $x 1
   130     testgetindexfromobjstruct $x 1
   131 } "wrong # args: should be \"testgetindexfromobjstruct c 1\""
   132 
   133 # cleanup
   134 ::tcltest::cleanupTests
   135 return