# -*- tcl -*-
# idx.test:  tests for the doctools::idx package.
#
# Copyright (c) 2009 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: export.test,v 1.2 2009/04/29 02:10:34 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 2

support {
    use fileutil/fileutil.tcl    fileutil      ;# tests/common

    use struct/list.tcl          struct::list
    use snit/snit.tcl            snit
    use log/logger.tcl           logger
    use pluginmgr/pluginmgr.tcl  pluginmgr

    use doctools2base/config.tcl          doctools::config
    useLocal structure.tcl   doctools::idx::structure
    use doctools2base/nroff_manmacros.tcl doctools::nroff::man_macros

    source [tcllibPath doctools2base/tests/common]
}
testing {
    useLocalKeep export.tcl doctools::idx::export
}

# -------------------------------------------------------------------------

setup_plugins

# -------------------------------------------------------------------------

test doctools-idx-export-1.0 {export object, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E export object
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::idx::export::Snit_hmethodexport_object type selfns win self obj ?format?"}

test doctools-idx-export-1.1 {export object, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E export object O F XXX
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::idx::export::Snit_hmethodexport_object type selfns win self obj ?format?"}

test doctools-idx-export-2.0 {export serial, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E export serial
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::idx::export::Snit_hmethodexport_serial type selfns win self serial ?format?"}

test doctools-idx-export-2.1 {export serial, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E export serial S F XXX
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::idx::export::Snit_hmethodexport_serial type selfns win self serial ?format?"}

test doctools-idx-export-5.0 {config names, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E config names X
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::config::Snit_methodnames type selfns win self"}

test doctools-idx-export-6.0 {config get, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E config get X
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::config::Snit_methodget type selfns win self"}

test doctools-idx-export-7.0 {config set, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E config set
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::config::Snit_methodset type selfns win self name ?value?"}

test doctools-idx-export-7.1 {config set, wrong#args} -setup {
    doctools::idx::export E
} -body {
    E config set N V X
} -cleanup {
    E destroy
} -returnCodes error -result {wrong # args: should be "::doctools::config::Snit_methodset type selfns win self name ?value?"}

# -------------------------------------------------------------------------

test doctools-idx-export-12.0 {config set, define single var} -setup {
    doctools::idx::export E
} -body {
    E config set N V
    E config get
} -cleanup {
    E destroy
} -result {N V}

test doctools-idx-export-12.1 {config set, define multiple vars} -setup {
    doctools::idx::export E
} -body {
    E config set N V
    E config set A B
    dictsort [E config get]
} -cleanup {
    E destroy
} -result {A B N V}

test doctools-idx-export-12.2 {config set, as query} -setup {
    doctools::idx::export E
    E config set N V
} -body {
    E config set N
} -cleanup {
    E destroy
} -result V

test doctools-idx-export-13.0 {config unset, all} -setup {
    doctools::idx::export E
    E config set N V
} -body {
    E config unset
    E config get
} -cleanup {
    E destroy
} -result {}

test doctools-idx-export-13.1 {config unset, by exact name} -setup {
    doctools::idx::export E
    E config set N V
    E config set A B
} -body {
    E config unset N
    E config get
} -cleanup {
    E destroy
} -result {A B}

test doctools-idx-export-13.2 {config unset, by glob pattern} -setup {
    doctools::idx::export E
    E config set N V
    E config set N' V'
    E config set A B
} -body {
    E config unset N*
    E config get
} -cleanup {
    E destroy
} -result {A B}

test doctools-idx-export-14.0 {config names, empty} -setup {
    doctools::idx::export E
} -body {
    E config names
} -cleanup {
    E destroy
} -result {}

test doctools-idx-export-14.1 {config names, with variables} -setup {
    doctools::idx::export E
    E config set N V
    E config set A B
} -body {
    lsort -dict [E config names]
} -cleanup {
    E destroy
} -result {A N}

test doctools-idx-export-15.0 {config get, empty} -setup {
    doctools::idx::export E
} -body {
    E config get
} -cleanup {
    E destroy
} -result {}

test doctools-idx-export-15.1 {config get, with variables} -setup {
    doctools::idx::export E
    E config set N V
    E config set A B
} -body {
    dictsort [E config get]
} -cleanup {
    E destroy
} -result {A B N V}

# idx_export tests, numbering starts at 20
# -------------------------------------------------------------------------

source [localPath tests/export]

# -------------------------------------------------------------------------
testsuiteCleanup
return
