# $Id$

set testfilename1 parse.rvt

::tcltest::test parse-1.1 {Parse command} {
    set page [ ::http::geturl "${urlbase}$testfilename1" ]
    string trimright [::http::data $page] "\n"
} {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Parse Test</title>
  </head>

  <body>
    <h1>Parse Test</h1>
    Hello, World

¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!


<p>日本語 (UTF-8 Japanese text)</p>

  </body>
</html>}

set testfilename2 parsestring.rvt

::tcltest::test parse-1.2 {Parse command} {
    set page [ ::http::geturl "${urlbase}$testfilename2" ]
    string trimright [::http::data $page] "\n"
} {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Parse String Test</title>
  </head>

  <body>
    <h1>Parse String Test</h1>
    Hello, World

¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!


<p>日本語 (UTF-8 Japanese text)</p>

  </body>
</html>}

::tcltest::test parse-1.3 {Parse command with explicit legacy encoding} \
    -setup {
        set legacyFile parse-iso8859-1.tmp
        set channel [open $legacyFile w]
        chan configure $channel -translation binary
        puts -nonewline $channel [encoding convertto iso8859-1 {
            <? puts -nonewline "Más" ?>
        }]
        close $channel
        unset channel
    } \
    -body {
        set page [::http::geturl "${urlbase}parseencoding.rvt"]
        set data [::http::data $page]
        regexp {Más} $data
    } \
    -cleanup {
        if {[info exists page]} {
            ::http::cleanup $page
        }
        if {[info exists channel]} {
            close $channel
        }
        if {[info exists legacyFile]} {
            file delete -force $legacyFile
        }
        unset -nocomplain page data channel legacyFile
    } \
    -result 1
