
# Test script for Tkhtml
proc sourcefile {file} {
  set fname [file join [file dirname [info script]] $file] 
  uplevel #0 [list source $fname]
}
sourcefile common.tcl

html .h
.h handler script style styleHandler 
proc styleHandler {data} {
  .h style $data
}

proc property {node prop} {
  array set properties [$node prop]
  return $properties($prop)
}

tcltest::test dynamic-1.0 {} -body {
  .h reset
  .h parse -final {
    <html>
    <body>
    <a>Some Text</a>
    <b>Some Text</b>
    </html>
  }

  set ::node_a [lindex [.h search a] 0]
  set ::node_b [lindex [.h search b] 0]

  $::node_a dynamic set
} -result {}

tcltest::test dynamic-1.1 {} -body {
  $::node_b dynamic set
} -result {}

tcltest::test dynamic-1.2 {} -body {
  $::node_a dynamic set hover
} -result {hover}

tcltest::test dynamic-1.3 {} -body {
  $::node_a dynamic set 
} -result {hover}

tcltest::test dynamic-2.0 {} -body {
  .h reset
  .h parse -final {
    <html>
    <style>
      :hover {color:white}
    </style>
    <body>
    <a>Some Text</a>
    </html>
  }

  set ::node [lindex [.h search a] 0]
  property $::node color
} -result {black}

tcltest::test dynamic-2.1 {} -body {
  $::node dynamic set hover
  $::node dynamic set
} -result {hover}

tcltest::test dynamic-2.2 {} -body {
  property $::node color
} -result {white}

tcltest::test dynamic-3.0 {} -body {
  .h reset
  .h parse -final {
    <html>
    <style>
      a:link    {color:white}
      a:visited {color:blue}
      a         {color:black}
    </style>
    <body>
    <a>Some Text</a>
    </html>
  }

  set ::node [lindex [.h search a] 0]
  property $::node color
} -result {black}

tcltest::test dynamic-3.1 {} -body {
  $::node dynamic set visited
  $::node dynamic set
} -result visited

tcltest::test dynamic-3.2 {} -body {
  property $::node color
} -result {blue}

tcltest::test dynamic-3.3 {} -body {
  $::node dynamic set link
  property $::node color
} -result {blue}
tcltest::test dynamic-3.4 {} -body {
  $::node dynamic clear visited
  property $::node color
} -result {white}
tcltest::test dynamic-3.5 {} -body {
  $::node dynamic clear link
  $::node dynamic set
} -result {}
tcltest::test dynamic-3.6 {} -body {
  property $::node color
} -result {black}

tcltest::test dynamic-4.0 {} -body {
  .h reset
  .h parse -final {
    <html>
    <style>
      body a:hover {color:red}
    </style>
    <body>
    <a>Some Text</a>
    </html>
  }
  set ::node [lindex [.h search a] 0]
  $::node dynamic conditions
} -result {:link {body a:hover}}

finish_test

