# -- get.test
#
# testing ::rivet::var command for accessing urlencoded 
# variables

::tcltest::test getvariables-1.1 {GET variables} {
     set page [ ::http::geturl "${urlbase}get.rvt?foobar=goober" ]
     regexp -line {\[::rivet::var get foobar\] = goober$} [ ::http::data $page ] match
     set match
} {[::rivet::var get foobar] = goober}
 
::tcltest::test getvariables-1.2 {GET variables - exists} {
     set page [ ::http::geturl "${urlbase}get.rvt?xst=1" ]
     regexp -line {\[::rivet::var exists xst\]\[::rivet::var exists noxst\] = 1 0$} [ ::http::data $page ] match
     set match
} {[::rivet::var exists xst][::rivet::var exists noxst] = 1 0}
 
::tcltest::test getvariables-1.3 {GET variables - doesn't exist} {
     set page [ ::http::geturl "${urlbase}get.rvt" ]
     regexp -line {\[::rivet::var get xst\] = } [ ::http::data $page ] match
     set match
} {[::rivet::var get xst] = }
 
::tcltest::test getvariables-1.4 {GET variables - default value} {
     set page [::http::geturl "${urlbase}get.rvt?defaulttest=1"]
     regexp {^\[::rivet::var get xst foo\] = foo} [ ::http::data $page ] match
     set match
} {[::rivet::var get xst foo] = foo}
 
 ::tcltest::test getvariables-1.5 {GET variables - var_qs exists} {
     set page [::http::geturl "${urlbase}get.rvt?xst=1"]
     regexp -line {\[::rivet::var_qs exists xst\]\[::rivet::var_qs exists noxst\] = 1 0$} [ ::http::data $page ] match
     set match
} {[::rivet::var_qs exists xst][::rivet::var_qs exists noxst] = 1 0}
 
 ::tcltest::test getvariables-2.1 {GET variables + I18N} {
     set page [::http::geturl "${urlbase}get.rvt?Más=Tú"]
     regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test getvariables-2.2 {GET variables + I18N + encoding} {
     set page [::http::geturl [format "${urlbase}get.rvt?%s" [::http::formatQuery Más Tú]]]
     regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
} {[::rivet::var get Más] = Tú}
 
::tcltest::test getvariables-3.1 {GET multi-value variable} {
     set page [::http::geturl "${urlbase}get.rvt?lstvar1=a&lstvar1=b&lstvar1=c+d"]
     regexp -line {\[::rivet::var get lstvar1\] = a b c d$} [ ::http::data $page ] match
     set match
} {[::rivet::var get lstvar1] = a b c d}
 
::tcltest::test getvariables-3.2 {GET multi-value variable as list} {
     set page [::http::geturl "${urlbase}get.rvt?lstvar2=a&lstvar2=b&lstvar2=c+d"]
     regexp -line {\[::rivet::var list lstvar2\] = a b {c d}$} [ ::http::data $page ] match
     set match
} {[::rivet::var list lstvar2] = a b {c d}}
 
::tcltest::test getvariables-4.1 {var_qs} {
     set page [::http::geturl "${urlbase}get.rvt?foobar=goober"]
     regexp -line {\[::rivet::var_qs get foobar\] = goober$} [::http::data $page] match
     set match
} {[::rivet::var_qs get foobar] = goober}
 
::tcltest::test getvariables-5.1 {GET var_qs all} {
    set page [::http::geturl "${urlbase}getall.rvt?a=1&b=2&c=3&d=4"]
    set ptext [::http::data $page]
    regexp -line {^\[::rivet::var_qs all\]\s=\s.*$} $ptext match
    set match
} {[::rivet::var_qs all] = a|1|b|2|c|3|d|4}

::tcltest::test getvariables-5.2 {GET var_qs all <defaults>} {
    set page [::http::geturl "${urlbase}getall.rvt"]
    set ptext [::http::data $page]
    regexp -line {^\[::rivet::var_qs all\]\s=\s.*$} $ptext match
    set match
} {[::rivet::var_qs all] = a|1|b|2|c|3|d|4}

