#############################
#
# hugelist v 1.0 tests
#
# v 1.0
#
# ulis, 2002
#
# ---------------------------
# 2002-12-16: deleted the buggy source line
#############################

# ---------------------
#
# Tk & options default
#
# ---------------------

package require Tk 8.4
option add *Listbox.borderWidth 3
option add *Listbox.selectBorderwidth 1
option add *Listbox.highlightThickness 2
option add *Listbox.font {Helvetica -12 bold}

# ---------------------
#
# packages
#
# ---------------------

package require Hugelist 1.2.2
namespace import -force ::hugelist::hugelist
package require tcltest 2.1
namespace import -force ::tcltest::test

# ---------------------
#
# init
#
# ---------------------

set fixed {Courier -12}
set data "
  #define v_width 8
  #define v_height 10
  static unsigned char v_bits[] = { 0xff, 0xff, 0x7e, 0x7e, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x00 };"
image create bitmap _image_ -data $data
proc bgerror {args} { eval set ::bgerror $args }
proc record {key args} \
{ 
  if {$key == "-init"} \
  { 
    array unset ::record 
    foreach name $args { set ::record($name) "" }
  } \
  else \
  { 
    set ::record($key) $args  
  }
}
proc print {args} \
{ 
  set res {}
  set val 0
  foreach key $args \
  { 
    if {$val} \
    { lappend res $key; set val 0 } \
    elseif {$key == "-v"} \
    { set val 1 } \
    else \
    { 
      set value $::record($key)
      if {$value == ""} { lappend res {} } \
      else { lappend res [concat $key $value ] }
    }
  }
  return $res
}
proc deleteWindows {} \
{
  eval destroy [winfo children .]
}
proc getSizes {w} \
{
  set ::colwidth [$w info colwidth]
  set ::rowheight [$w info rowheight]
  foreach {x1 x2} [$w xview] break
  set ::pixwidth [expr {round(1.0 / ($x2 - $x1) * [$w cget -width] * $::colwidth)}]
  foreach {y1 y2} [$w yview] break
  set ::pixheight [expr {round(1.0 / ($y2 - $y1) * [$w cget -height] * $::rowheight)}]
}
proc checkBbox {w index} \
{
  set text [$w get $index]
  set bbox [$w bbox $index]
  set first [$w index @0,0]
  set old $index
  set index [$w index $index]
  if {$old == "end"} { incr index -1 }
  set row [expr {$index - $first}]
  if {$row < 0 || $row >= [$w cget -height]} \
  { if {$bbox == ""} { return {0 0 0 0} } else { return $bbox } }
  set ww [font measure [$w info font] $text]
  set hh [$w info charheight]
  set rh [$w info rowheight]
  set d [$w cget -borderwidth]
  incr d [$w cget -selectborderwidth]
  incr d [$w cget -highlightthickness]
  set xx $d
  set yy [expr {$d + $row * $rh}]
  return [diff [list $xx $yy $ww $hh] $bbox]
}
proc getXview {w} \
{
  set ll 0
  for {set i 0} {$i < [$w info count]} {incr i} \
  {
    set l [string length [$w get $i]]
    if {$ll < $l} { set ll $l }
  }
  set ww [expr {[$w info colwidth] * $ll}]
  foreach {f1 f2} [$w xview] break
  return [list [expr {round($f1 * $ww)}] [expr {round($f2 * $ww)}]]
}
proc getYview {w} \
{
  set hh [expr {[$w info rowheight] * [$w info count]}]
  foreach {f1 f2} [$w yview] break
  return [list [expr {round($f1 * $hh)}] [expr {round($f2 * $hh)}]]
}
proc diff {list1 list2} \
{
  foreach l1 $list1 l2 $list2 { lappend res [expr {$l2 - $l1}] }
  return $res
}

# ---------------------
#
# options setting
#
# ---------------------

hugelist .l
pack .l
update

set tests \
{
  {-activestyle under underline foo {bad activestyle "foo": must be dotbox, none, or underline}}
  {-alternatecolor #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  {-background #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  {-bd 4 4 badValue {bad screen distance "badValue"}}
  {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
  {-colwidth 7 7 badValue {bad screen distance "badValue"}}
  {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
  {-deep 4 4 badValue {expected integer but got "badValue"}}
  {-disabledforeground #110022 #110022 bogus {unknown color name "bogus"}}
  {-exportselection yes 1 xyzzy {expected boolean value but got "xyzzy"}}
  {-fg #110022 #110022 bogus {unknown color name "bogus"}}
  {-font {Helvetica 12} {Helvetica 12} {bogus font} {expected integer but got "font"}}
  {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
  {-height 30 30 20p {expected integer but got "20p"}}
  {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
  {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}}
  {-highlightthickness 6 6 bogus {bad screen distance "bogus"}}
  {-highlightthickness -2 0 {} {}}
  {-img _image_ _image_ badValue {image "badValue" doesn't exist}}
  {-image _image_ _image_ badValue {image "badValue" doesn't exist}}
  {-ipadx 1 1 badValue {bad screen distance "badValue"}}
  {-ipady 4 4 badValue {bad screen distance "badValue"}}
  {-left 15 15 badValue {bad screen distance "badValue"}}
  {-listvar testVariable testVariable {} {}}
  {-listvar ::testVariable ::testVariable {} {}}
  {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
  {-rowheight 20 20 badValue {bad screen distance "badValue"}}
  {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
  {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
  {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
  {-selectmode string string {} {}}
  {-setgrid false 0 lousy {expected boolean value but got "lousy"}}
  {-state disabled disabled foo {bad state "foo": must be disabled or normal}}
  {-text "any string" "any string" {} {}}
  {-takefocus "any string" "any string" {} {}}
  {-width 45 45 3p {expected integer but got "3p"}}
  {-xscrollcommand {Some command} {Some command} {} {}}
  {-yscrollcommand {Another command} {Another command} {} {}}
} 

set i 1
foreach test $tests \
{
  set name [lindex $test 0]
  test hugelist-1.$i $name \
    {
      .l configure $name [lindex $test 1]
      list [lindex [.l configure $name] 4] [.l cget $name]
    } \
    [list [lindex $test 2] [lindex $test 2]]
  incr i
  if {[lindex $test 3] != ""} \
  {
    test hugelist-1.$i $name \
      {
        list [catch {.l configure $name [lindex $test 3]} msg] $msg
      } \
      [list 1 [lindex $test 4]]
  }
  .l configure $name [lindex [.l configure $name] 3]
  incr i
}

# ---------------------
#
# items options default value
#
# ---------------------

destroy .l
hugelist .l -list ::list 
pack .l
update
set tests \
{
  {-background red red}
  {-bg blue blue}
  {-fg brown brown}
  {-font {Courier -12} {Courier -12}}
  {-foreground green green}
  {-img _image_ _image_}
  {-image _image_ _image_}
  {-left 15 15}
  {-selectbackground gold gold}
  {-selectforeground gray gray}
  {-text "any text" "any text"}
} 

set i 1
foreach test $tests \
{
  set name [lindex $test 0]
  set value [lindex $test 1]
  test hugelist-1.1.$i $name \
  {
    .l configure $name $value
    set ::list {0 1 2 3 4 5 6 7 8 9 10 ""}      
    .l itemcget $i $name
  } $value
  incr i
}

# ---------------------
#
# constructor
#
# ---------------------

test hugelist-2.1 \
  {hugelist procedure} \
  {
    list [catch {hugelist} msg] $msg
  } \
  {1 {unknown option "": should be pathName, item or version}}
test hugelist-2.2 \
  {hugelist procedure} \
  {
    list [catch {hugelist gorp} msg] $msg
  } \
  {1 {unknown option "gorp": should be pathName, item or version}}
test hugelist-2.3 \
  {hugelist procedure} \
  {
    catch {destroy .l}
    hugelist .l
    list [winfo exists .l] [winfo class .l] [info commands .l]
  } \
  {1 Hugelist .l}
test hugelist-2.4 \
  {hugelist procedure} \
  {
    catch {destroy .l}
    list [catch {hugelist .l -gorp foo} msg] $msg [winfo exists .l] [info commands .l]
  } \
  {1 {unknown option "-gorp"} 0 {}}
test hugelist-2.5 \
  {hugelist procedure} \
  {
    catch {destroy .l}
    hugelist .l
  } \
  {.l}

# ---------------------
#
# operations
#
# ---------------------

catch {destroy .l}
hugelist .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2
pack .l
.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 el15 el16 el17
update

# dispatch

test hugelist-3.1 \
  {dispatch procedure} \
  {
    list [catch .l msg] $msg
  } \
  {1 {wrong # args: should be ".l option ?arg arg ...?"}}
  
  
# activate operation

test hugelist-3.2 \
  {activate operation} \
  {
    list [catch {.l activate} msg] $msg
  } \
  {1 {wrong # args: should be ".l activate index"}}
test hugelist-3.3 \
  {activate operation} \
  {
    list [catch {.l activate a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l activate index"}}
test hugelist-3.4 \
  {activate operation} \
  {
    list [catch {.l activate fooey} msg] $msg
  } \
  {1 {bad hugelist index "fooey": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.5 \
  {activate operation} \
  {
    .l activate 3
    .l index active
  } \
  {3}
test hugelist-3.6 \
  {activate operation} \
  {
    .l activate -1
    .l index active
  } \
  {0}
test hugelist-3.7 \
  {activate operation} \
  {
    .l activate 30
    .l index active
  } \
  {17}
test hugelist-3.8 \
  {activate operation} \
  {
    .l activate end
    .l index active
  } \
  {17}
  
# bbox operation

test hugelist-3.9 \
  {bbox operation} \
  {
    list [catch {.l bbox} msg] $msg
  } \
  {1 {wrong # args: should be ".l bbox index"}}
test hugelist-3.10 \
  {bbox operation} \
  {
    list [catch {.l bbox a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l bbox index"}}
test hugelist-3.11 \
  {bbox operation} \
  {
    list [catch {.l bbox fooey} msg] $msg
  } \
  {1 {bad hugelist index "fooey": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.12 \
  {bbox operation} \
  {
    .l yview 3
    update
    list [.l bbox 2] [.l bbox 8]
  } \
  {{} {}}
test hugelist-3.13 \
  {bbox operation} \
  {
    hugelist .l2
    pack .l2 -side top
    tkwait visibility .l2
    set x [.l2 bbox 0]
    destroy .l2
    set x
  } \
  {}
test hugelist-3.14 \
  {bbox operation} \
  {
    .l yview 3
    update
    list [checkBbox .l 3] [checkBbox .l 4]
  } \
  {{0 0 0 0} {0 0 0 0}}
test hugelist-3.15 \
  {bbox operation} \
  {
    .l yview 0
    update
    list [checkBbox .l -1] [checkBbox .l 0]
  } \
  {{0 0 0 0} {0 0 0 0}}
test hugelist-3.16 \
  {bbox operation} \
  {
    .l yview end
    update
    list [checkBbox .l 17] [checkBbox .l end] [checkBbox .l 18]
  } \
  {{0 0 0 0} {0 0 0 0} {0 0 0 0}}
test hugelist-3.17 \
  {bbox operation} \
  {
    catch {destroy .t}
    toplevel .t
    wm geom .t +0+0
    hugelist .t.l -width 10 -height 5
    .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short"
    pack .t.l
    update
    .t.l xview moveto .2
    checkBbox .t.l 2
  } \
  {0 0 0 0}
  catch { destroy .t; update }
# hugelist-3.18

# cget operation

test hugelist-3.19 \
  {cget operation} \
  {
    list [catch {.l cget} msg] $msg
  } \
  {1 {wrong # args: should be ".l cget option"}}
test hugelist-3.20 \
  {cget operation} \
  {
    list [catch {.l cget a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l cget option"}}
test hugelist-3.21 \
  {cget operation} \
  {
    list [catch {.l cget -gorp} msg] $msg
  } \
  {1 {unknown option "-gorp"}}
test hugelist-3.22 \
  {cget operation} \
  {
    .l cget -setgrid
  } \
  {0}
  
# configure operation

test hugelist-3.23 \
  {configure operation} \
  {
    llength [.l configure]
  } \
  {39}
test hugelist-3.24 \
  {configure operation} \
  {
    list [catch {.l configure -gorp} msg] $msg
  } \
  {1 {unknown option "-gorp"}}
test hugelist-3.25 \
  {configure operation} \
  {
    .l configure -setgrid
  } \
  {-setgrid setGrid SetGrid 0 0}
test hugelist-3.26 \
  {configure operation} \
  {
    list [catch {.l configure -gorp is_messy} msg] $msg
  } \
  {1 {unknown option "-gorp"}}
test hugelist-3.27 \
  {configure operation} \
  {
    set oldbd [.l cget -bd]
    set oldht [.l cget -highlightthickness]
    .l configure -bd 3 -highlightthickness 0
    set x "[.l cget -bd] [.l cget -highlightthickness]"
    .l configure -bd $oldbd -highlightthickness $oldht
    set x
  } \
  {3 0}

# curselection operation

test hugelist-3.28 \
  {curselection operation} \
  {
    list [catch {.l curselection a} msg] $msg
  } \
  {1 {wrong # args: should be ".l curselection"}}
test hugelist-3.29 \
  {curselection operation} \
  {
    .l selection clear 0 end
    .l selection set 3 6
    .l selection set 9
    .l curselection
  } \
  {3 4 5 6 9}
  
# delete operation

test hugelist-3.30 \
  {delete operation} \
  {
    list [catch {.l delete} msg] $msg
  } \
  {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}}
test hugelist-3.31 \
  {delete operation} \
  {
    list [catch {.l delete a b c} msg] $msg
  } \
  {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}}
test hugelist-3.32 \
  {delete operation} \
  {
    list [catch {.l delete badIndex} msg] $msg
  } \
  {1 {bad hugelist index "badIndex": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.33 \
  {delete operation} \
  {
    list [catch {.l delete 2 123ab} msg] $msg
  } \
  {1 {bad hugelist index "123ab": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.34 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 3
    list [.l2 get 2] [.l2 get 3] [.l2 index end]
  } \
  {el2 el4 7}
test hugelist-3.35 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 2 4
    list [.l2 get 1] [.l2 get 2] [.l2 index end]
  } \
  {el1 el5 5}
test hugelist-3.36 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete -3 2
    .l2 get 0 end
  } \
  {el3 el4 el5 el6 el7}
test hugelist-3.37 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete -3 -1
    .l2 get 0 end
  } \
  {el0 el1 el2 el3 el4 el5 el6 el7}
test hugelist-3.38 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 2 end
    .l2 get 0 end
  } \
  {el0 el1}
test hugelist-3.39 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 5 20
    .l2 get 0 end
  } \
  {el0 el1 el2 el3 el4}
test hugelist-3.40 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete end 20
    .l2 get 0 end
  } \
  {el0 el1 el2 el3 el4 el5 el6}
test hugelist-3.41 \
  {delete operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 8 20
    .l2 get 0 end
  } \
  {el0 el1 el2 el3 el4 el5 el6 el7}

# get operation

test hugelist-3.42 \
  {get operation} \
  {
    list [catch {.l get} msg] $msg
  } \
  {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}}
test hugelist-3.43 \
  {get operation} \
  {
    list [catch {.l get a b c} msg] $msg
  } \
  {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}}
test hugelist-3.44 \
  {get operation} \
  {
    list [catch {.l get 2.4} msg] $msg
  } \
  {1 {bad hugelist index "2.4": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.45 \
  {get operation} \
  {
    list [catch {.l get end bogus} msg] $msg
  } \
  {1 {bad hugelist index "bogus": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.46 \
  {get operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    list [.l2 get 0] [.l2 get 3] [.l2 get end]
  } \
  {el0 el3 el7}
test hugelist-3.47 \
  {get operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    list [.l2 get 0] [.l2 get end]
  } \
  {{} {}}
test hugelist-3.48 \
  {get operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 el0 el1 el2 "two words" el4 el5 el6 el7
    .l2 get 3 end
  } \
  {{two words} el4 el5 el6 el7}
test hugelist-3.49 \
  {get operation} \
  {
    .l get -1
  } \
  {}
test hugelist-3.50 \
  {get operation} \
  {
    .l get -2 -1
  } \
  {}
test hugelist-3.51 \
  {get operation} \
  {
    .l get -2 3
  } \
  {el0 el1 el2 el3}
test hugelist-3.52 \
  {get operation} \
  {
    .l get 12 end
  } \
  {el12 el13 el14 el15 el16 el17}
test hugelist-3.53 \
  {get operation} \
  {
    .l get 12 20
  } \
  {el12 el13 el14 el15 el16 el17}
test hugelist-3.54 \
  {get operation} \
  {
    .l get end
  } \
  {el17}
test hugelist-3.55 \
  {get operation} \
  {
    .l get 30
  } \
  {}
test hugelist-3.56 \
  {get operation} \
  {
    .l get 30 35
  } \
  {}

# index operation

test hugelist-3.57 \
  {index operation} \
  {
    list [catch {.l index} msg] $msg
  } \
  {1 {wrong # args: should be ".l index index"}}
test hugelist-3.58 \
  {index operation} \
  {
    list [catch {.l index a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l index index"}}
test hugelist-3.59 \
  {index operation} \
  {
    list [catch {.l index @} msg] $msg
  } \
  {1 {bad hugelist index "@": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.60 \
  {index operation} \
  {
    .l index 2
  } \
  {2}
test hugelist-3.61 \
  {index operation} \
  {
    .l index -1
  } \
  {-1}
test hugelist-3.62 \
  {index operation} \
  {
    .l index end
  } \
  {18}
test hugelist-3.63 \
  {index operation} \
  {
    .l index 34
  } \
  {34}

# info operation

catch {destroy .l2}
hugelist .l2 -font {Courier -12} -ipadx 0 -ipady 4 -rowheight 20 -colwidth 0
.l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
test hugelist-3b.99 \
  {info operation} \
  {
    list [catch { .l2 info bogus } errmsg] $errmsg
  } \
  {1 {unknown info name "bogus"}}
test hugelist-3b.100 \
  {info operation} \
  {
    .l2 info font
  } \
  {Courier -12}
test hugelist-3b.101 \
  {info operation} \
  {
    expr [.l2 info charheight] - [font metrics [.l2 info font] -linespace]
  } \
  {0}
test hugelist-3b.102 \
  {info operation} \
  {
    expr [.l2 info charwidth] - [font measure [.l2 info font] "0"]
  } \
  {0}
test hugelist-3b.103 \
  {info operation} \
  {
    expr [.l2 info colwidth] - [.l2 info charwidth]
  } \
  {0}
test hugelist-3b.104 \
  {info operation} \
  {
    .l2 info count
  } \
  {8}
test hugelist-3b.105 \
  {info operation} \
  {
    expr [.l2 info rowheight] - 20
  } \
  {0}
test hugelist-3b.106 \
  {info operation} \
  {
    .l2 configure -rowheight 0 -ipady 4
    expr [.l2 info rowheight] - [.l2 info charheight] - 4
  } \
  {0}
test hugelist-3b.107 \
  {info operation} \
  {
    .l2 configure -rowheight 21
    expr [.l2 info rowheight] - 21
  } \
  {0}
test hugelist-3b.108 \
  {info operation} \
  {
    .l2 configure -colwidth 0 -ipadx 2
    expr [.l2 info colwidth] - [.l2 info charwidth] - 2
  } \
  {0}
test hugelist-3b.109 \
  {info operation} \
  {
    .l2 configure -colwidth 8
    expr [.l2 info colwidth] - 8
  } \
  {0}

# insert operation

test hugelist-3.64 \
  {insert operation} \
  {
    list [catch {.l insert} msg] $msg
  } \
  {1 {wrong # args: should be ".l insert index ?element element ...?"}}
test hugelist-3.65 \
  {insert operation} \
  {
    list [catch {.l insert badIndex} msg] $msg
  } \
  {1 {bad hugelist index "badIndex": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.66 \
  {insert operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert end a b c d e
    .l2 insert 3 x y z
    .l2 get 0 end
  } \
  {a b c x y z d e}
test hugelist-3.67 \
  {insert operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert end a b c
    .l2 insert -1 x
    .l2 get 0 end
  } \
  {x a b c}
test hugelist-3.68 \
  {insert operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert end a b c
    .l2 insert end x
    .l2 get 0 end
  } \
  {a b c x}
test hugelist-3.69 \
  {insert operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert end a b c
    .l2 insert 43 x
    .l2 get 0 end
  } \
  {a b c x}

# nearest operation

test hugelist-3.70 \
  {nearest operation} \
  {
    list [catch {.l nearest} msg] $msg
  } \
  {1 {wrong # args: should be ".l nearest y"}}
test hugelist-3.71 \
  {nearest operation} \
  {
    list [catch {.l nearest a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l nearest y"}}
test hugelist-3.72 \
  {nearest operation} \
  {
    list [catch {.l nearest 20p} msg] $msg
  } \
  {1 {bad hugelist index "@0,20p": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.73 \
  {nearest operation} \
  {
    .l yview 3
    .l nearest 1000
  } \
  {7}

# scan operation

test hugelist-3.74 \
  {scan operation} \
  {
    list [catch {.l scan a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l scan mark|dragto x y"}}
test hugelist-3.75 \
  {scan operation} \
  {
    list [catch {.l scan a b c d} msg] $msg
  } \
  {1 {wrong # args: should be ".l scan mark|dragto x y"}}
test hugelist-3.76 \
  {scan operation} \
  {
    list [catch {.l scan foo bogus 2} msg] $msg
  } \
  {1 {expected integer but got "bogus"}}
test hugelist-3.77 \
  {scan operation} \
  {
    list [catch {.l scan foo 2 2.3} msg] $msg
  } \
  {1 {expected integer but got "2.3"}}
test hugelist-3.78 \
  {scan operation} \
  {
    catch {destroy .t}
    toplevel .t
    wm geom .t +0+0
    hugelist .t.l -width 10 -height 5
    .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short" a b c d e f g h i j
    pack .t.l
    update
    set lx [getXview .t.l]
    set ly [getYview .t.l]
    .t.l scan mark 100 140
    .t.l scan dragto 90 137
    update
    list [diff $lx [getXview .t.l]] [diff $ly [getYview .t.l]]
  } \
  {{100 100} {30 30}}
  catch { destroy .t; update }
test hugelist-3.79 \
  {scan operation} \
  {
    list [catch {.l scan foo 2 4} msg] $msg
  } \
  {1 {bad option "foo": must be mark or dragto}}

# see operation

test hugelist-3.80 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    list [catch {.l see} msg] $msg
  } \
  {1 {wrong # args: should be ".l see index"}}
test hugelist-3.81 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    list [catch {.l see a b} msg] $msg
  } \
  {1 {wrong # args: should be ".l see index"}}
test hugelist-3.82 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    list [catch {.l see gorp} msg] $msg
  } \
  {1 {bad hugelist index "gorp": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.83 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 7
    .l index @0,0
  } \
  {7}
test hugelist-3.84 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 11
    .l index @0,0
  } \
  {7}
test hugelist-3.85 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 6
    .l index @0,0
  } \
  {6}
test hugelist-3.86 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 5
    .l index @0,0
  } \
  {3}
test hugelist-3.87 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 12
    .l index @0,0
  } \
  {8}
test hugelist-3.88 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 13
    .l index @0,0
  } \
  {11}
test hugelist-3.89 \
  {ListboxWidgetCmd procedure, "see" option} {
    .l yview 7
    .l see -1
    .l index @0,0
  } \
  {0}
test hugelist-3.90 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see end
    .l index @0,0
  } \
  {13}
test hugelist-3.91 \
  {ListboxWidgetCmd procedure, "see" option} \
  {
    .l yview 7
    .l see 322
    .l index @0,0
  } \
  {13}
# hugelist-3.92 

# selection operation

test hugelist-3.93 \
  {selection operation} \
  {
    list [catch {.l select a} msg] $msg
  }  \
  {1 {wrong # args: should be ".l selection option index ?index?"}}
test hugelist-3.94 \
  {selection operation} \
  {
    list [catch {.l select a b c d} msg] $msg
  }  \
  {1 {wrong # args: should be ".l selection option index ?index?"}}
test hugelist-3.95 \
  {selection operation} \
  {
    list [catch {.l selection a bogus} msg] $msg
  }  \
  {1 {bad hugelist index "bogus": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.96 \
  {selection operation} \
  {
    list [catch {.l selection a 0 lousy} msg] $msg
  }  \
  {1 {bad hugelist index "lousy": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.97 \
  {selection operation} \
  {
    list [catch {.l selection anchor 0 0} msg] $msg
  }  \
  {1 {wrong # args: should be ".l selection anchor index"}}
test hugelist-3.98 \
  {selection operation} \
  {
    list [.l selection anchor 5; .l index anchor] \
      [.l selection anchor 0; .l index anchor]
  }  \
  {5 0}
test hugelist-3.99 \
  {selection operation} \
  {
    .l selection anchor -1
    .l index anchor
  }  \
  {0}
test hugelist-3.100 \
  {selection operation} \
  {
    .l selection anchor end
    .l index anchor
  }  \
  {17}
test hugelist-3.101 \
  {selection operation} \
  {
    .l selection anchor 44
    .l index anchor
  }  \
  {17}
test hugelist-3.102 \
  {selection operation} \
  {
    .l selection clear 0 end
    .l selection set 2 8
    .l selection clear 3 4
    .l curselection
  }  \
  {2 5 6 7 8}
test hugelist-3.103 \
  {selection operation} \
  {
    list [catch {.l selection includes 0 0} msg] $msg
  }  \
  {1 {wrong # args: should be ".l selection includes index"}}
test hugelist-3.104 \
  {selection operation} \
  {
    .l selection clear 0 end
    .l selection set 2 8
    .l selection clear 4
    list [.l selection includes 3] [.l selection includes 4] \
      [.l selection includes 5]
  }  \
  {1 0 1}
test hugelist-3.105 \
  {selection operation} \
  {
    .l selection set 0 end
    .l selection includes -1
  }  \
  {0}
test hugelist-3.106 \
  {selection operation} \
  {
    .l selection clear 0 end
    .l selection set end
    .l selection includes end
  }  \
  {1}
test hugelist-3.107 \
  {selection operation} \
  {
    .l selection set 0 end
    .l selection includes 44
  }  \
  {0}
test hugelist-3.108 \
  {selection operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 selection includes 0
  }  \
  {0}
test hugelist-3.109 \
  {selection operation} \
  {
    .l selection clear 0 end
    .l selection set 2
    .l selection set 5 7
    .l curselection
  }  \
  {2 5 6 7}
test hugelist-3.110 \
  {selection operation} \
  {
    .l selection set 5 7
    .l curselection
  }  \
  {2 5 6 7}
test hugelist-3.111 \
  {selection operation} \
  {
    list [catch {.l selection badOption 0 0} msg] $msg
  }  \
  {1 {bad option "badOption": must be anchor, clear, includes, or set}}

# size operation

test hugelist-3.112 \
  {size operation} \
  {
    list [catch {.l size a} msg] $msg
  }  \
  {1 {wrong # args: should be ".l size"}}
test hugelist-3.113 \
  {size operation} \
  {
    .l size
  }  \
  {18}

# xview operation

test hugelist-3.114 \
  {xview operation} \
  {
    catch {destroy .l2}
    hugelist .l2
    update
    .l2 xview
  }  \
  {0 1}
test hugelist-3.115 \
  {xview operation} \
  {
    catch {destroy .l}
    hugelist .l -width 10 -height 5 -font $fixed
    .l insert 0 a b c d e f g h i j k l m n o p q r s t
    pack .l
    update
    .l xview
  }  \
  {0 1}
catch {destroy .l}
hugelist .l -width 10 -height 5 -font $fixed
.l insert 0 a b c d e f g h i j k l m n o p q r s t
.l insert 1 "0123456789a123456789b123456789c123456789d123456789"
pack .l
update
test hugelist-3.116 \
  {xview operation} \
  {
    .l xview 4
    .l xview
    foreach {x -} [getXview .l] break
    set font [.l cget -font]
    expr $x - [font measure $font 0] * 4
  }  \
  {0}
test hugelist-3.117 \
  {xview operation} \
  {
    list [catch {.l xview foo} msg] $msg
  }  \
  {1 {expected integer but got "foo"}}
test hugelist-3.118 \
  {xview operation} \
  {
    list [catch {.l xview zoom a b} msg] $msg
  }  \
  {1 {unknown option "zoom": must be moveto or scroll}}
test hugelist-3.119 \
  {xview operation} \
  {
    .l xview 0
    .l xview moveto .4
    update
    .l xview
  }  \
  {0.4 0.6}
test hugelist-3.120 \
  {xview operation} \
  {
    .l xview 0
    .l xview scroll 2 units
    update
    .l xview
  }  \
  {0.04 0.24}
test hugelist-3.121 \
  {xview operation} \
  {
    .l xview 30
    .l xview scroll -1 pages
    update
    .l xview
  }  \
  {0.4 0.6}
test hugelist-3.122 \
  {xview operation} \
  {
    .l configure -width 1
    update
    .l xview 30
    .l xview scroll -4 pages
    update
    .l xview
  }  \
  {0.52 0.54}

# yview operation

test hugelist-3.123 \
  {yview operation} \
  {
    catch {destroy .l}
    hugelist .l
    pack  .l
    update
    .l yview
  }  \
  {0 1}
test hugelist-3.124 \
  {yview operation} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert 0 el1
    pack  .l
    update
    .l yview
  }  \
  {0 1}
catch {destroy .l}
hugelist .l -width 10 -height 5 -font $fixed
.l insert 0 a b c d e f g h i j k l m n o p q r s t
pack .l
update
test hugelist-3.125 \
  {yview operation} \
  {
    .l yview 4
    update
    .l yview
  } \
  {0.2 0.45}
# hugelist-3.126
test hugelist-3.127 \
  {yview operation} \
  {
    list [catch {.l yview foo} msg] $msg
  }  \
  {1 {bad hugelist index "foo": must be active, anchor, end, @x,y, or a number}}
test hugelist-3.128 \
  {yview operation} \
  {
    list [catch {.l yview foo a b} msg] $msg
  }  \
  {1 {unknown option "foo": must be moveto or scroll}}
test hugelist-3.129 \
  {yview operation} \
  {
    .l yview 0
    .l yview moveto .31
    set f [lindex [.l yview] 0]
    expr {abs($f - 0.31) < 1.e-2}
  }  \
  {1}
test hugelist-3.130 \
  {yview operation} \
  {
    .l yview 2
    .l yview scroll 2 pages
    .l yview
  }  \
  {0.6 0.85}
test hugelist-3.131 \
  {yview operation} \
  {
    .l yview 10
    .l yview scroll -3 units
    .l yview
  }  \
  {0.35 0.6}
test hugelist-3.132 \
  {yview operation} \
  {
    .l configure -height 2
    update
    .l yview 15
    .l yview scroll -4 pages
    .l yview
  }  \
  {0.35 0.45}

# operations dispatch

test hugelist-3.133 \
  {operations dispatch} \
  {
    list [catch {.l whoknows} msg] $msg
  }  \
  {1 {bad option "whoknows": must be activate, bbox, cget, configure, curselection, delete, get, index, info, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
test hugelist-3.134 \
  {operations dispatch} \
  {
    list [catch {.l c} msg] $msg
  }  \
  {1 {ambiguous option "c":activate, bbox, cget, configure, curselection, delete, get, index, info, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
test hugelist-3.135 \
  {operations dispatch} \
  {
    list [catch {.l in} msg] $msg
  }  \
  {1 {ambiguous option "in":activate, bbox, cget, configure, curselection, delete, get, index, info, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
test hugelist-3.136 \
  {operations dispatch} \
  {
    list [catch {.l s} msg] $msg
  }  \
  {1 {ambiguous option "s":activate, bbox, cget, configure, curselection, delete, get, index, info, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
test hugelist-3.137 \
  {operations dispatch} \
  {
    list [catch {.l se} msg] $msg
  }  \
  {1 {ambiguous option "se":activate, bbox, cget, configure, curselection, delete, get, index, info, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}

# ---------------------
#
# options fonctionality
#
# ---------------------

# hugelist-4.1

# -highlightthickness option

test hugelist-4.2 \
  {-highlightthickness option} \
  {
    .l configure -highlightthickness -3
    .l cget -highlightthickness
  } \
  {0}
  
# -exportselection option

test hugelist-4.3 \
  {-exportselection option} \
  {
    .l configure -exportselection 0
    .l delete 0 end
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
    .l selection set 3 5
    .l configure -exportselection 1
    selection get
  } \
  {el3
el4
el5}
test hugelist-4.4 \
  {-exportselection option} \
  {
    catch {destroy .e}
    entry .e
    .e insert 0 abc
    .e select from 0
    .e select to 2
    .l configure -exportselection 0
    .l delete 0 end
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
    .l selection set 3 5
    .l selection clear 3 5
    .l configure -exportselection 1
    list [selection own] [selection get]
  } \
  {.e ab}
test hugelist-4.5 \
  {-exportselection option} \
  {
    selection clear .
    .l configure -exportselection 1
    .l delete 0 end
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
    .l selection set 1 1
    set x {}
    lappend x [catch {selection get} msg] $msg [.l curselection]
    .l config -exportselection 0
    lappend x [catch {selection get} msg] $msg [.l curselection]
    .l selection clear 0 end
    lappend x [catch {selection get} msg] $msg [.l curselection]
    .l selection set 1 3
    lappend x [catch {selection get} msg] $msg [.l curselection]
    .l config -exportselection 1
    lappend x [catch {selection get} msg] $msg [.l curselection]
  } \
  {0 el1 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {1 2 3} 0 {el1
el2
el3} {1 2 3}}
# hugelist-4.6
# hugelist-4.7

# x/yscrollcommand options

wm geom . {}
catch {destroy .l}
test hugelist-4.8 \
  {x/yscrollcommand options} \
  {
    catch {destroy .l}
    record -init x y
    hugelist .l -width 15 -height 20 -xscrollcommand "record x" -yscrollcommand "record y"
    pack .l
    update
    .l insert 0 a
    update
    print y x
  } \
  {{y 0 1} {x 0 1}}

# -listvar option

test hugelist-4.9 \
  {-listvar option} \
  {
    catch {destroy .l}
    set x {a b c d}
    hugelist .l -listvar x
    .l get 0 end
  } \
  {a b c d}
test hugelist-4.10 \
  {-listvar option} \
  {
    catch {destroy .l}
    set x {a b c d}
    hugelist .l
    .l insert end 1 2 3 4
    .l configure -listvar x
    .l get 0 end
  } \
  {a b c d}
test hugelist-4.11 \
  {-listvar option} \
  {
    catch {destroy .l}
    set x {a b c d}
    hugelist .l -listvar x
    .l configure -listvar {}
    .l insert end 1 2 3 4
    list $x [.l get 0 end]
  } \
  {{a b c d} {a b c d 1 2 3 4}}
test hugelist-4.12 \
  {-listvar option} \
  {
    catch {destroy .l}
    set x {a b c d}
    set y {1 2 3 4}
    hugelist .l 
    .l configure -listvar x
    .l configure -listvar y
    .l insert end 5 6 7 8
    list $x $y
  } \
  {{a b c d} {1 2 3 4 5 6 7 8}}
test hugelist-4.13 \
  {-listvar option} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l
    .l insert end a b c d
    .l configure -listvar x
    set x
  } \
  {a b c d}
test hugelist-4.14 \
  {-listvar option} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x
    list [info exists x] $x
  } \
  {1 {}}
test hugelist-4.15 \
  {-listvar option} \
  {
    catch {destroy .l}
    catch {unset y}
    set x [list a b c d]
    hugelist .l -listvar x
    .l configure -listvar y
    list [info exists y] $y
  } \
  {1 {a b c d}}
test hugelist-4.16 \
  {-listvar option} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    .l configure -listvar x
    set x
  } \
  {a b c d}
test hugelist-4.17 \
  {-listvar option} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c d
    .l configure -listvar {}
    .l get 0 end
  } \
  {a b c d}
test hugelist-4.18 \
  {-listvar option} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c d
    set x "this is a \" bad list"
    catch {.l configure -listvar x} result
    list [.l get 0 end] [.l cget -listvar] $result
  } \
  {{a b c d} {} {unmatched open quote in list}}
test hugelist-4.19 \
  {-listvar option} \
  {
    catch {destroy .l}
    hugelist .l -listvar foo
    .l insert end a b c d
    catch {.l configure -listvar ::zoo::bar::foo} result
    list [.l get 0 end] [.l cget -listvar] $foo $result
  } \
  {{a b c d} foo {a b c d} {can't set "::zoo::bar::foo": parent namespace doesn't exist}}

# geometry

test hugelist-5.1 \
  {geometry} \
  {
    catch {destroy .l}
    hugelist .l -font $fixed -width 15 -height 20 -bd 0 -highlightthickness 0
    pack .l
    update
    getSizes .l
    set x [expr {round([winfo reqwidth .l] / double($::colwidth))}]
    set y [expr {round([winfo reqheight .l] / double($::rowheight))}]
    list $x $y
  } \
  {15 20}
test hugelist-5.2 \
  {geometry} \
  {
    catch {destroy .l}
    hugelist .l -font $fixed -width 0 -height 10 -bd 0 -highlightthickness 0
    pack .l
    update
    getSizes .l
    set x [expr {round([winfo reqwidth .l] / double($::colwidth))}]
    set y [expr {round([winfo reqheight .l] / double($::rowheight))}]
    list $x $y
  } \
  {0 10}
test hugelist-5.3 \
  {geometry} \
  {
    catch {destroy .l}
    hugelist .l -font $fixed -width 0 -height 10 -bd 3 -highlightthickness 0
    .l insert 0 Short "Really much longer" Longer
    pack .l
    update
    getSizes .l
    set x [expr {round(([winfo reqwidth .l] - 6) / double($::colwidth))}]
    set y [expr {round(([winfo reqheight .l] - 6) / double($::rowheight))}]
    list $x $y
  } \
  {18 10}
test hugelist-5.4 \
  {geometry} \
  {
    catch {destroy .l}
    hugelist .l -font $fixed -width 10 -height 0 -bd 0 -highlightthickness 0
    pack .l
    update
    getSizes .l
    set x [expr {round([winfo reqwidth .l] / double($::colwidth))}]
    set y [expr {round([winfo reqheight .l] / double($::rowheight))}]
    list $x $y
  } \
  {10 0}
test hugelist-5.5 \
  {geometry} \
  {
    catch {destroy .l}
    hugelist .l -font $fixed -width 10 -height 0 -bd 0 -highlightthickness 0
    .l insert 0 Short "Really much longer" Longer
    pack .l
    update
    getSizes .l
    set x [expr {round([winfo reqwidth .l] / double($::colwidth))}]
    set y [expr {round([winfo reqheight .l] / double($::rowheight))}]
    list $x $y
  } \
  {10 3}
test hugelist-5.6 \
  {geometry} \
  {
    catch {destroy .l}
    pack [hugelist .l -font {{open look glyph}}]
    update
  } \
  {}
    
# insert items

catch {destroy .l}
hugelist .l -height 2 -xscrollcommand "record x" -yscrollcommand "record y"
pack .l
update
test hugelist-6.1 \
  {insert items} \
  {
    .l delete 0 end
    .l insert end a b c d
    .l insert 5 x y z
    .l insert 2 A
    .l insert 0 q r s
    .l get 0 end
  } \
  {q r s a b A c d x y z}
test hugelist-6.2 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l insert 2 A B
    .l index anchor
  } \
  {4}
test hugelist-6.3 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l insert 3 A B
    .l index anchor
  } \
  {2}
test hugelist-6.4 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l insert 2 A B
    .l index @0,0
  } \
  {5}
test hugelist-6.5 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l insert 3 A B
    .l index @0,0
  } \
  {3}
test hugelist-6.6 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 5
    .l insert 5 A B
    .l index active
  } \
  {7}
test hugelist-6.7 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 5
    .l insert 6 A B
    .l index active
  } \
  {5}
test hugelist-6.8 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b c
    .l index active
  } \
  {2}
test hugelist-6.9 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0
    .l index active
  } \
  {0}
test hugelist-6.10 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b "two words"  c d e f g h i j
    update
    record -init x y
    .l insert 0 word
    update
    print y
  } \
  {{y 0 0.166667}}
test hugelist-6.11 \
  {insert items} \
  {
    .l delete 0 end
    .l insert 0 a b "two words"  c d e f g h i j
    update
    record -init x y
    .l insert 0 "much longer entry"
    update
    print y x
  } \
  {{y 0 0.166667} {x 0 1}}
test hugelist-6.12 \
  {insert items} \
  {
    catch {destroy .l2}
    hugelist .l2 -width 0 -height 0 -bd 0 -highlightthickness 0
    pack .l2 -side top
    .l2 insert 0 a b "two words"  c d
    update
    getSizes .l2
    set x [expr {round([winfo reqwidth .l2] / double($::colwidth))}]
    set y [expr {round([winfo reqheight .l2] / double($::rowheight))}]
    list $x $y
  } \
  {9 5}

# listvar update

test hugelist-6.13 \
  {listvar update} \
  {
    catch {destroy .l2}
    set x [list a b c d]
    hugelist .l2 -listvar x
    .l2 insert 0 1 2 3 4
    set x
  } \
  {1 2 3 4 a b c d}
test hugelist-6.14 \
  {listvar update} \
  {
    catch {destroy .l2}
    hugelist .l2
    .l2 insert 0 0 1 2 3 4
    .l2 selection set 2 4
    .l2 insert 0 a
    .l2 curselection
  } \
  {3 4 5}

# delete items

test hugelist-7.1 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection set 1 6
    .l delete 4 3
    list [.l size] [selection get]
  } \
  {10 {b
c
d
e
f
g}}
test hugelist-7.2 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection set 3 6
    .l delete 4 4
    list [.l size] [.l get 4] [.l curselection]
  } \
  {9 f {3 4 5}}
test hugelist-7.3 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l delete 0 3
    list [.l size] [.l get 0] [.l get 1]
  } \
  {6 e f}
test hugelist-7.4 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l delete 8 1000
    list [.l size] [.l get 7]
  } \
  {8 h}
test hugelist-7.5 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l delete 0 1
    .l index anchor
  } \
  {0}
test hugelist-7.6 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l delete 2
    .l index anchor
  } \
  {2}
test hugelist-7.7 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 4
    .l delete 2 5
    .l index anchor
  } \
  {2}
test hugelist-7.8 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 3
    .l delete 4 5
    .l index anchor
  } \
  {3}
test hugelist-7.9 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 1 2
    .l index @0,0
  } \
  {1}
test hugelist-7.10 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 3 4
    .l index @0,0
  } \
  {3}
test hugelist-7.11 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 4 6
    .l index @0,0
  } \
  {3}
test hugelist-7.12 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 3 end
    .l index @0,0
  } \
  {1}
# hugelist-7.13
test hugelist-7.14 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 3 4
    .l index active
  } \
  {4}
test hugelist-7.15 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 5 7
    .l index active
  } \
  {5}
test hugelist-7.16 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 5 end
    .l index active
  } \
  {4}
test hugelist-7.17 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 0 end
    .l index active
  } \
  {0}
test hugelist-7.18 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c "two words" d e f g h i j
    update
    record -init x y
    .l delete 4 6
    update
    print y
  } \
  {{y 0 0.25}}
test hugelist-7.19 \
  {delete items} \
  {
    .l delete 0 end
    .l insert 0 a b c "two words" d e f g h i j
    update
    record -init x y
    .l delete 3
    update
    print y x
  } \
  {{y 0 0.2} {x 0 1}}
# hugelist-7.20
test hugelist-7.21 \
  {delete items} \
  {
    catch {destroy .l2}
    set x {a b c d}
    hugelist .l2 -listvar x
    .l2 delete 0 1
    set x
  } \
  {c d}

# events

# hugelist-8.1
test hugelist-8.2 \
  {events} \
  {
    catch {destroy .l}
    hugelist .l -height 5 -width 10 -bd 0 -highlightthickness 0
    .l insert 0 a b c "A string that is very very long" d e f g h i j k
    pack .l
    update
    place .l -width 100 -height 100
    update
    list [getXview .l] [getYview .l]
  } \
  {{0 100} {0 100}}
test hugelist-8.3 \
  {events} \
  {
    deleteWindows
    update
    hugelist .l1 -bg #543210
    rename .l1 .l2
    set x {}
    lappend x [winfo children .]
    lappend x [.l2 cget -bg]
    destroy .l1
    lappend x [info command .l*] [winfo children .]
  } \
  {.l1 #543210 {} {}}

# rename listvar

test hugelist-9.1 \
  {rename listvar} \
  {
    deleteWindows
    hugelist .l1
    rename .l1 {}
    list [info command .l*] [winfo children .]
  } \
  {{} {}}
# hugelist-9.2

# index

catch {destroy .l}
hugelist .l
pack .l
.l delete 0 end
.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
test hugelist-10.1 \
  {index} \
  {
    .l activate 3
    list [.l activate 3; .l index active] [.l activate 6; .l index active]
  } \
  {3 6}
test hugelist-10.2 \
{GetListboxIndex procedure} {
    .l selection anchor 2
    .l index anchor
  } \
  {2}
# hugelist-10.3
test hugelist-10.4 \
  {index} \
  {
    list [catch {.l index a} msg] $msg
  } \
  {1 {bad hugelist index "a": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.5 \
  {index} \
  {
    .l index end
  } \
  {12}
test hugelist-10.6 \
{GetListboxIndex procedure} {
    .l get end
  } \
  {el11}
test hugelist-10.7 \
  {index} \
  {
    .l delete 0 end
    .l index end
  } \
  {0}
.l delete 0 end
.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
update
test hugelist-10.8 \
  {index} \
  {
    list [catch {.l index @} msg] $msg
  } \
  {1 {bad hugelist index "@": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.9 \
  {index} \
  {
    list [catch {.l index @foo} msg] $msg
  } \
  {1 {bad hugelist index "@foo": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.10 \
  {index} \
  {
    list [catch {.l index @1x3} msg] $msg
  } \
  {1 {bad hugelist index "@1x3": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.11 \
  {index} \
  {
    list [catch {.l index @1,} msg] $msg
  } \
  {1 {bad hugelist index "@1,": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.12 \
  {index} \
  {
    list [catch {.l index @1,foo} msg] $msg
  } \
  {1 {bad hugelist index "@1,foo": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.13 \
{GetListboxIndex procedure} {
    list [catch {.l index @1,2x} msg] $msg
  } \
  {1 {bad hugelist index "@1,2x": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.14 \
  {index} \
  {
    list [.l index @5,57] [.l index @5,58]
  } \
  {3 3}
test hugelist-10.15 \
  {index} \
  {
    list [catch {.l index 1xy} msg] $msg
  } \
  {1 {bad hugelist index "1xy": must be active, anchor, end, @x,y, or a number}}
test hugelist-10.16 \
  {index} \
  {
    .l index 3
  } \
  {3}
test hugelist-10.17 \
  {index} \
  {
    .l index 20
  } \
  {20}
test hugelist-10.18 \
  {index} \
  {
    .l get 20
  } \
  {}
test hugelist-10.19 \
  {index} \
  {
    .l index -2
  } \
  {-2}
test hugelist-10.20 \
  {index} \
  {
    .l delete 0 end
    .l index 1
  } \
  {1}

# new indexes

test hugelist-10.21 \
  {index} \
  {
    .l insert end a b c d e f
    .l index end-0
  } \
  {5}
test hugelist-10.22 \
  {index} \
  {
    catch { .l index end+0 } errmsg
    set errmsg
  } \
  {bad hugelist index "end+0": must be active, anchor, end, @x,y, or a number}
test hugelist-10.23 \
  {index} \
  {
    .l index end-2
  } \
  {3}
test hugelist-10.24 \
  {index} \
  {
    .l index end-6
  } \
  {0}


# boundary conditions for index

test hugelist-11.1 \
  {boundary conditions for index} \
  {
    catch {destroy .l}
    hugelist .l -height 5
    pack .l
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    set x [.l index @0,0]
    .l yview -1
    update
    lappend x [.l index @0,0]
  } \
  {3 0}
test hugelist-11.2 \
  {boundary conditions for index} \
  {
    catch {destroy .l}
    hugelist .l -height 5
    pack .l
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    set x [.l index @0,0]
    .l yview 20
    update
    lappend x [.l index @0,0]
  } \
  {3 5}
  
# x/yview

test hugelist-11.3 \
  {yview} \
  {
    catch {destroy .l}
    hugelist .l -height 5 -yscrollcommand "record y"
    pack .l
    .l insert 0 a b c d e f g h i j
    update
    record -init x y
    .l yview 2
    update
    list [.l yview] [print y]
  }  \
  {{0.2 0.7} {{y 0.2 0.7}}}
test hugelist-11.4 \
  {yview} \
  {
    catch {destroy .l}
    hugelist .l -height 5 -yscrollcommand "record y"
    pack .l
    .l insert 0 a b c d e f g h i j
    update
    record -init x y
    .l yview 8
    update
    list [.l yview] [print y]
  }  \
  {{0.5 1} {{y 0.5 1}}}
test hugelist-11.5 \
  {yview} \
  {
    catch {destroy .l}
    hugelist .l -height 5 -yscrollcommand "record y"
    pack .l
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    record -init x y
    .l yview 3
    update
    list [.l yview] [print y]
  }  \
  {{0.3 0.8} {{}}}
# hugelist-11.6
catch {destroy .l}
hugelist .l -font $fixed -xscrollcommand "record x" -width 10
.l insert 0 0123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789
pack .l
update
test hugelist-12.1 \
  {xview} \
  {
    record -init x y
    .l xview 99
    update
    list [.l xview] [print x]
  } \
  {{0.9 1} {{x 0.9 1}}}
test hugelist-12.2 \
  {xview} \
  {
    record -init x y
    .l xview moveto -.25
    update
    list [.l xview] [print x]
  } \
  {{0 0.1} {{x 0 0.1}}}
test hugelist-12.3 \
  {xview} \
  {
    .l xview 10
    update
    record -init x y
    .l xview 10
    update
    list [.l xview] [print x]
  } \
  {{0.1 0.2} {{}}}

# scan 

catch {destroy .l}
hugelist .l -font $fixed -width 10 -height 5
pack .l
.l insert 0 a bb c d e f g h i j k l m n o p q r s
.l insert 0 0123456789a123456789b123456789c123456789d123456789
update
set width [expr [lindex [.l bbox 2] 2] - [lindex [.l bbox 1] 2]]
set height [expr [lindex [.l bbox 2] 1] - [lindex [.l bbox 1] 1]]
test listbox-13.1 \
  {ListboxScanTo procedure} \
  {
    .l yview 0
    .l xview 0
    .l scan mark 10 20
    .l scan dragto [expr 10-$width] [expr 20-$height]
    update
    list [.l xview] [.l yview]
  } \
  {{0.2 0.4} {0.5 0.75}}
test listbox-13.2 \
  {ListboxScanTo procedure} \
  {
    .l yview 5
    .l xview 10
    update
    .l scan mark 0 0
    .l scan dragto 100 100
    update
    set x [list [.l xview] [.l yview]]
    .l scan dragto [expr 100-$width] [expr 100-$height]
    update
    lappend x [.l xview] [.l yview]
  } \
  {{0 0.2} {0 0.25} {0.2 0.4} {0.5 0.75}}
test listbox-13.3 \
  {ListboxScanTo procedure} \
  {
    .l yview moveto 1.0
    .l xview moveto 1.0
    .l scan mark 10 20
    .l scan dragto 5 10
    update
    set x [list [.l xview] [.l yview]]
    .l scan dragto [expr 5+$width] [expr 10+$height]
    update
    lappend x [.l xview] [.l yview]
  } \
  {{0.8 1} {0.75 1} {0.6 0.8} {0.25 0.5}}

# nearest

# hugelist-14.1
catch {destroy .l}
hugelist .l -font $fixed -width 20 -height 10
.l insert 0 a b c d e f g h i j k l m n o p q r s t
.l yview 4
pack .l
update
test hugelist-14.2 \
  {nearest} \
  {
    .l index @50,0
  } \
  {4}
test hugelist-14.3 \
  {nearest} \
  {
    getSizes .l
    list [.l index @50,[expr {$::rowheight - 1}]] [.l index @50,$::rowheight]
  } \
  {4 5}
test hugelist-14.4 \
  {nearest} \
  {
    .l index @50,[expr {$::rowheight * 10}]
  } \
  {14}

# select

test hugelist-15.1 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j k l m n o p
    .l select set 2 4
    .l select set 7 12
    .l select clear 4 7
    .l curselection
  } \
  {2 3 8 9 10 11 12}
test hugelist-15.2 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j k l m n o p
    catch {destroy .e}
    entry .e
    .e insert 0 "This is some text"
    .e select from 0
    .e select to 7
    .l selection clear 2 4
    set x [selection own]
    .l selection set 3
    list $x [selection own] [selection get]
  } \
  {.e .l d}
test hugelist-15.3 \
  {select} \
  {
    .l delete 0 end
    .l selection clear 0 end
    .l select set 0 end
    .l curselection
  } \
  {}
test hugelist-15.4 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set -2 -1
    .l curselection
  } \
  {}
test hugelist-15.5 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set -1 3
    .l curselection
  } \
  {0 1 2 3}
test hugelist-15.6 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 2 4
    .l curselection
  } \
  {2 3 4}
test hugelist-15.7 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 4 end
    .l curselection
  } \
  {4 5}
test hugelist-15.8 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 4 30
    .l curselection
  } \
  {4 5}
test hugelist-15.9 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set end 30
    .l curselection
  } \
  {5}
test hugelist-15.10 \
  {select} \
  {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 20 25
    .l curselection
  } \
  {}

# x selection

test hugelist-16.1 \
  {x selection} \
  {
    .l delete 0 end
    .l insert 0 a b c "two words" e f g h i \\ k l m n o p
    .l selection set 2 4
    .l selection set 9
    .l selection set 11 12
    selection get
  } \
  "c\ntwo words\ne\n\\\nl\nm"
test hugelist-16.2 \
  {x selection} \
  {
    .l delete 0 end
    .l insert 0 a b c "two words" e f g h i \\ k l m n o p
    .l selection set 3
    selection get
  } \
  {two words}
test hugelist-16.3 \
  {x selection} \
  {
    set long "This is quite a long string\n"
    append long $long $long $long $long
    append long $long $long $long $long
    append long $long $long
    .l delete 0 end
    .l insert 0 1$long 2$long 3$long 4$long 5$long
    .l selection set 0 end
    set sel [selection get]
    string compare 1$long\n2$long\n3$long\n4$long\n5$long $sel
  } \
  {0}
catch {unset long sel}

# hugelist-17.1
# hugelist-17.2

# yscrollcommand

catch {destroy .l}
hugelist .l -font $fixed -width 10 -height 5
pack .l
update
test hugelist-18.1 \
  {yscrollcommand} \
  {
    .l configure -yscrollcommand "record y"
    set log {}
    record -init x y
    .l insert 0 a b c
    update
    lappend log [print y]
    .l insert end d e f g h
    update
    lappend log [print y]
    .l delete 0 end
    update
    lappend log [print y]
    return [eval concat $log]
  } \
  {{y 0 1} {y 0 0.625} {y 0 1}}
# hugelist-18.2
test hugelist-18.3 \
  {yscrollcommand} \
  {
    catch {
      .l configure -yscrollcommand gorp
      .l insert 0 foo
      update
    } errmsg
    set errmsg
  } \
  {.l -yscrollcommand: invalid command name "gorp"}

# xscrollcommand

catch {destroy .l}
hugelist .l -font $fixed -width 10 -height 5
pack .l
update
test hugelist-19.1 \
  {xscrollcommand} \
  {
    .l configure -list ::list -xscrollcommand "record x"
    set log {}
    record -init x y
    set ::list abc
    update
    lappend log [print x]
    lappend ::list 01234567890123456789012345678901234567890123456789
    update
    lappend log [print x]
    set ::list {}
    update
    lappend log [print x]
    return [eval concat $log]
  } \
  {{x 0 1} {x 0 0.2} {x 0 1}}
catch {destroy .l}
hugelist .l -font $fixed -width 10 -height 5
pack .l
update
test hugelist-19.2 \
  {xscrollcommand} \
  {
    set ::bgerror ""
    .l configure -xscrollcommand bogus
    .l insert 0 foo
    update
    set ::bgerror
  } \
  {.l -xscrollcommand: invalid command name "bogus"}

# hidden

set l [interp hidden]
deleteWindows

test hugelist-20.1 \
  {hidden} \
  {
    catch {destroy .l}
    hugelist .l
    interp hide {} .l
    destroy .l
    list [winfo children .] [interp hidden]
  } \
  [list {} $l]

# listvar
test hugelist-21.1 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x
    set x [list a b c d]
    .l get 0 end
  } \
  {a b c d}
test hugelist-21.2 \
  {listvar} {listvar_protection} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    unset x
    set x
  } \
  {a b c d}
test hugelist-21.3 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    .l configure -listvar {}
    unset x
    info exists x
  } \
  {0}
test hugelist-21.4 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    lappend x e f g
    .l size
  } \
  {7}
test hugelist-21.5 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d e f g]
    hugelist .l -listvar x
    .l selection set end
    set x [list a b c d]
    set x [list 0 1 2 3 4 5 6]
    .l curselection
  } \
  {}
test hugelist-21.6 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    .l selection set 3
    lappend x e f g
    .l curselection
  } \
  {3}
test hugelist-21.7 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    .l selection set 0
    set x [linsert $x 0 1 2 3 4]
    .l curselection
  } \
  {0}
test hugelist-21.8 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d]
    hugelist .l -listvar x
    .l selection set 2
    set x [list a b c]
    .l curselection
  } \
  {2}

test hugelist-21.9 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    set log {}
    record -init x y
    hugelist .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
    pack .l
    update
    lappend log [print x]
    lappend x "0000000000"
    update
    lappend log [print x]
    lappend x "00000000000000000000"
    update
    lappend log [print x]
    return [eval concat $log]
  } \
  {{x 0 1} {x 0 1} {x 0 0.5}}
# hugelist-21.10
test hugelist-21.11 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x
    set x [list a b c d]
    catch {set x "this is a \" bad list"} result
    set result
  } \
  {can't set "x": unmatched open quote in list}
test hugelist-21.12 \
  {listvar} \
  {
    catch {destroy .l}
    set x [list a b c d e f g]
    hugelist .l -listvar x
    .l config -fg black
    .l itemconfigure end -fg red
    set x [list a b c d]
    set x [list 0 1 2 3 4 5 6]
    .l itemcget end -fg
  } \
  {black}


test hugelist-21.13 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x
    .l insert end a b c
    .l itemconfigure 1 -fg red
    set x [list b c]
    .l itemcget 1 -fg
  } \
  {red}
test hugelist-21.14 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x
    .l insert end a b c
    .l itemconfigure 0 -fg red
    set x [list 1 2 3 4 a b c]
    .l itemcget 0 -fg
  } \
  {red}
test hugelist-21.15 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    set log {}
    record -init x y
    hugelist .l -listvar x -yscrollcommand "record y" -font fixed -height 3
    pack .l
    update
    lappend log [print y]
    lappend x a b c d e f
    update
    lappend log [print y]
    return [eval concat $log]
  } \
  {{y 0 1} {y 0 0.5}}
test hugelist-21.16 \
  {listvar} \
  {
    catch {destroy .l}
    catch {unset x}
    hugelist .l -listvar x -height 3
    pack .l
    update
    set x [list 0 1 2 3 4 5]
    .l yview scroll 3 units
    update
    set result {}
    lappend result [.l yview]
    set x [lreplace $x 3 3]
    set x [lreplace $x 3 3]
    set x [lreplace $x 3 3]
    update
    lappend result [.l yview]
    set result
  } \
  {{0.5 1} {0 1}}

# x scrollbar

test hugelist-22.1 \
  {x scrollbar} {
    catch {destroy .l}
    set log {}
    record -init x y
    hugelist .l -font $fixed -width 10 -xscrollcommand "record x"
    pack .l
    update
    lappend log [print x]
    .l insert end "0000000000"
    update
    lappend log [print x]
    .l insert end "00000000000000000000"
    update
    lappend log [print x]
    return [eval concat $log]
  } \
  {{x 0 1} {x 0 1} {x 0 0.5}}

# itemconfigure

test hugelist-23.1 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l
    catch {.l itemconfigure 0} result
    set result
  } \
  {item number "0" out of range}
test hugelist-23.2 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l -fg black -bg white -selectfg white -selectbg navy
    .l insert end a b c d
    .l itemconfigure 0
  } \
  {{-background background Background {} white} {-bg -background} {-fg -foreground} {-font font Font {} {}} {-foreground foreground Foreground {} black} {-img -image} {-image image Image {} {}} {-left left Left 0 0} {-selectbackground selectBackground Background {} navy} {-selectforeground selectForeground Foreground {} white} {-text text Text {} a}}
test hugelist-23.3 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l -bg white
    .l insert end a b c d
    .l itemco 0 -background
  } \
  {-background background Background {} white}
test hugelist-23.4 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a
    catch {.l itemco} result
    set result
  } \
  {wrong # args: should be ".l itemconfigure first ?last? ?option? ?value? ?option value ...?"}
test hugelist-23.5 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l
    set i 0
    foreach color {red orange yellow green blue white violet} \
    {
      .l insert end $color
      .l itemconfigure $i -bg $color
      incr i
    }
    pack .l
    update
    set l {}
    for {set i 0} {$i < 7} {incr i} { lappend l [.l itemcget $i -bg] }
    set l
  } \
  {red orange yellow green blue white violet}
test hugelist-23.6 \
  {itemconfigure} \
  {
    catch {destroy .l}
    hugelist .l -fg black
    .l insert end a b c d
    .l itemconf 1 2 -fg red
    pack .l
    update
    set l {}
    for {set i 0} {$i < 4} {incr i} { lappend l [.l itemcget $i -fg] }
    set l
  } \
  {black red red black}

# new v1.1 item options

test hugelist-23.7 \
  {new item options} \
  {
    .l itemconf 0 -img
  } \
  {-image image Image {} {}}
test hugelist-23.8 \
  {new item options} \
  {
    .l itemconf 0 -image
  } \
  {-image image Image {} {}}
test hugelist-23.9 \
  {new item options} \
  {
    catch { .l itemconf 0 -image _image_2 } errmsg
    set errmsg
  } \
  {image "_image_2" doesn't exist}
test hugelist-23.10 \
  {new item options} \
  {
    .l itemconf 0 -img _image_
    .l itemcget 0 -img
  } \
  {_image_}
test hugelist-23.11 \
  {new item options} \
  {
    .l itemconf 0 -image _image_
    .l itemcget 0 -image
  } \
  {_image_}
test hugelist-23.12 \
  {new item options} \
  {
    .l itemconf 0 -text
  } \
  {-text text Text {} a}
test hugelist-23.13 \
  {new item options} \
  {
    .l itemconf 0 -text text
    .l itemcget 0 -text
  } \
  {text}

# itemconfigure/itemcget

catch {destroy .l}
hugelist .l
.l insert end a b c d
set i 20
set tests \
{
  {-background #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
  {-fg #110022 #110022 bogus {unknown color name "bogus"}}
  {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
  {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
  {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
} 
foreach test $tests \
{
  set name [lindex $test 0]
  test hugelist-23.$i \
  {itemconfigure/itemcget} \
  {
    .l itemconfigure 0 $name [lindex $test 1]
    list [lindex [.l itemconfigure 0 $name] 4] [.l itemcget 0 $name]
  } \
  [list [lindex $test 2] [lindex $test 2]]
  incr i
  if {[lindex $test 3] != ""} \
  {
    test hugelist-23.$i \
    {itemconfigure/itemcget} \
    {
      list [catch {.l configure $name [lindex $test 3]} msg] $msg
    } \
    [list 1 [lindex $test 4]]
  }
  .l configure $name [lindex [.l configure $name] 3]
  incr i
}

# itemcget

test hugelist-24.1 \
  {itemcget} \
  {
    catch {destroy .l}
    hugelist .l -fg black
    .l insert end a b c d
    .l itemcget 0 -fg
  } \
  {black}
test hugelist-24.2 \
  {itemcget} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c d
    .l itemconfigure 0 -fg red
    .l itemcget 0 -fg
  } \
  {red}
test hugelist-24.3 \
  {itemcget} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c d
    catch {.l itemcget 0} result
    set result
  } \
  {wrong # args: should be ".l itemcget index option"}
test hugelist-24.3 \
  {itemcget} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c d
    catch {.l itemcg 0} result
    set result
  } \
  {wrong # args: should be ".l itemcget index option"}

# general

test hugelist-25.1 \
  {general} \
  {
    catch {destroy .l}
    hugelist .l -fg black
    .l insert end a
    .l itemconfigure 0 -fg red
    .l delete 0 end
    .l insert end a
    .l itemcget 0 -fg
  } \
  {black}
test hugelist-25.2 \
  {general} \
  {
    catch {destroy .l}
    hugelist .l -fg black
    .l insert end a b c
    .l itemconfigure 0 -fg red
    .l insert 0 1 2 3 4
    list [.l itemcget 0 -fg] [.l itemcget 4 -fg]
  } \
  {black red}
    
# state

test hugelist-26.1 \
  {state} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c
    .l configure -state disabled
    .l insert end d e f
    .l get 0 end
  } \
  {a b c}
test hugelist-26.2 \
  {state} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c
    .l configure -state disabled
    .l delete 0 end
    .l get 0 end
  } \
  {a b c}
test hugelist-26.3 \
  {state} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c
    .l selection set 0
    .l selection set 2
    .l configure -state disabled
    .l selection clear 0 end
    .l selection set 1
    .l curselection
  } \
  {0 2}
test hugelist-26.4 \
  {state} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c
    .l selection anchor 0
    .l configure -state disabled
    .l selection anchor 2
    .l index anchor
  } \
  {0}
test hugelist-26.5 \
  {state} \
  {
    catch {destroy .l}
    hugelist .l
    .l insert end a b c
    .l activate 0
    .l configure -state disabled
    .l activate 2
    .l index active
  } \
  {0}

# widget deletion while active

test hugelist-27.1 \
  {widget deletion while active} \
  {
    destroy .l
    pack [hugelist .l]
    update
    .l configure -cursor xterm -xscrollcommand { destroy .l }
    .l insert 0 a
    update
    winfo exists .l
  } \
  {0}

# activestyle

test hugelist-28.1 \
  {activestyle} \
  {
    catch {destroy .l}
    hugelist .l -activ non
    .l cget -activestyle
  } \
  {none}
test hugelist-28.2 \
  {activestyle} \
  {
    catch {destroy .l}
    hugelist .l
    .l cget -activestyle
  } \
  {underline}
test hugelist-28.3 \
  {activestyle} \
  {
    catch {destroy .l}
    hugelist .l -activestyle dot
    .l cget -activestyle
  } \
  {dotbox}

# --------------------
# new v1.2 hugelist operations
# --------------------

# hugelist option

test hugelist-30.0 \
  {hugelist option get/set} \
  {
    lindex [hugelist option get] 0
  } \
  {-activestyle activeStyle ActiveStyle {underline}}

test hugelist-30.1 \
  {hugelist option get/set} \
  {
    hugelist option get -state
  } \
  {normal}

test hugelist-30.2 \
  {hugelist option get/set} \
  {
    list [catch { hugelist option set -option } msg] $msg
  } \
  {1 {"-option" does not match a hugelist option}}

test hugelist-30.3 \
  {hugelist option get/set} \
  {
    hugelist option set -foreground red
    destroy .l
    hugelist .l
    .l cget -foreground
  } \
  {red}

test hugelist-30.4 \
  {hugelist option get/set} \
  {
    hugelist option set -foreground
  } \
  {-foreground foreground Foreground red}

test hugelist-30.5 \
  {hugelist option get/set} \
  {
    hugelist option set -bg red
    destroy .l
    hugelist .l
    .l cget -bg
  } \
  {red}

test hugelist-30.6 \
  {hugelist option get/set} \
  {
    hugelist option set -bg green -foreground red
    destroy .l
    hugelist .l
    list [.l cget -background] [.l cget -fg] 
  } \
  {green red}

set tests \
{
  {-background red red}
  {-bg blue blue}
  {-fg brown brown}
  {-foreground green green}
  {-img _image_ _image_}
  {-image _image_ _image_}
  {-left 15 15}
  {-selectbackground gold gold}
  {-selectforeground gray gray}
  {-text "any text" "any text"}
} 

set i 1
foreach test $tests \
{
  set name [lindex $test 0]
  set value [lindex $test 1]
  test hugelist-31.$i $name \
  {
    destroy .l
    hugelist option set $name $value
    hugelist .l -values {0 1 2 3 4 5 6 7 8 9 ""}      
    .l itemcget $i $name
  } $value
  incr i
}

# hugelist version

test hugelist-32.0 \
  {hugelist version} \
  {
    hugelist version
  } \
  {1.2.2}


# ---------------------
#
# end of tests
#
# ---------------------

option clear
tcltest::cleanupTests