# -*- tcl -*-
# -- toc_import.test:
# -- Tests for package "doctools::toc::import": Management of import plugins.
#
# Copyright (c) 2009-2019 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.

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

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

testsNeedTcl     8.5
testsNeedTcltest 2

support {
    use struct/list.tcl         struct::list
    use snit/snit.tcl           snit
    use fileutil/fileutil.tcl   fileutil
    use fileutil/paths.tcl      fileutil::paths
    use log/logger.tcl          logger
    use pluginmgr/pluginmgr.tcl pluginmgr
    use struct/map.tcl          struct::map

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

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

setup_plugins

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

test doctools-toc-import-1.0 {import text, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import text
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_text type selfns win self text ?format?"}

test doctools-toc-import-1.1 {import text, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import text T F XX
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_text type selfns win self text ?format?"}

test doctools-toc-import-2.0 {import file, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import file
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_file type selfns win self path ?format?"}

test doctools-toc-import-2.1 {import file, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import file P F XXX
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_file type selfns win self path ?format?"}

test doctools-toc-import-3.0 {import object text, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object text
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_text type selfns win self obj text ?format?"}

test doctools-toc-import-3.1 {import object text, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object text O
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_text type selfns win self obj text ?format?"}

test doctools-toc-import-3.2 {import object text, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object text O T F XXX
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_text type selfns win self obj text ?format?"}

test doctools-toc-import-4.0 {import object file, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object file
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_file type selfns win self obj path ?format?"}

test doctools-toc-import-4.1 {import object file, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object file O
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_file type selfns win self obj path ?format?"}

test doctools-toc-import-4.2 {import object file, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I import object file O P F XXX
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::doctools::toc::import::Snit_hmethodimport_object_file type selfns win self obj path ?format?"}

test doctools-toc-import-5.0 {config names, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I config names X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::struct::map::I::Snit_methodnames type selfns win self"}

test doctools-toc-import-6.0 {config get, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I config get X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::struct::map::I::Snit_methodget type selfns win self"}

test doctools-toc-import-7.0 {config set, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I config set
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::struct::map::I::Snit_methodset type selfns win self name ?value?"}

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

# config unset - accepts any number of arguments.

# -------------------------------------------------------------------------
## `include paths` component, provided via fileutil::paths, search path for includes

test doctools-toc-import-8.0 {include paths, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include paths X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodpaths type selfns win self"}

test doctools-toc-import-9.0 {include clear, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include clear X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodclear type selfns win self"}

test doctools-toc-import-10.0 {include add, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include add
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodadd type selfns win self path"}

test doctools-toc-import-10.1 {include add, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include add P X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodadd type selfns win self path"}

test doctools-toc-import-11.0 {include remove, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include remove
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodremove type selfns win self path"}

test doctools-toc-import-11.1 {include remove, wrong#args} -setup {
    doctools::toc::import I
} -body {
    I include remove P X
} -cleanup {
    I destroy
} -returnCodes error -result {wrong # args: should be "::fileutil::paths::Snit_methodremove type selfns win self path"}

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

test doctools-toc-import-12.0 {config set, define single var} -setup {
    doctools::toc::import I
} -body {
    I config set N V
    I config get
} -cleanup {
    I destroy
} -result {N V}

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

test doctools-toc-import-12.2 {config set, as query} -setup {
    doctools::toc::import I
    I config set N V
} -body {
    I config set N
} -cleanup {
    I destroy
} -result V

test doctools-toc-import-13.0 {config unset, all} -setup {
    doctools::toc::import I
    I config set N V
} -body {
    I config unset
    I config get
} -cleanup {
    I destroy
} -result {}

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

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

test doctools-toc-import-14.0 {config names, empty} -setup {
    doctools::toc::import I
} -body {
    I config names
} -cleanup {
    I destroy
} -result {}

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

test doctools-toc-import-15.0 {config get, empty} -setup {
    doctools::toc::import I
} -body {
    I config get
} -cleanup {
    I destroy
} -result {}

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

test doctools-toc-import-16.0 {include paths, empty} -setup {
    doctools::toc::import I
} -body {
    I include paths
} -cleanup {
    I destroy
} -result {}

test doctools-toc-import-16.1 {include paths, several paths, order} -setup {
    doctools::toc::import I
    I include add first
    I include add second
} -body {
    I include paths
} -cleanup {
    I destroy
} -result {first second}

test doctools-toc-import-17.0 {include add, unknown} -setup {
    doctools::toc::import I
} -body {
    I include add A
    I include paths
} -cleanup {
    I destroy
} -result A

test doctools-toc-import-17.1 {include add, already known} -setup {
    doctools::toc::import I
} -body {
    I include add A
    I include add A
    I include paths
} -cleanup {
    I destroy
} -result A

test doctools-toc-import-18.0 {include remove, unknown} -setup {
    doctools::toc::import I
} -body {
    I include add A
    I include remove B
    I include paths
} -cleanup {
    I destroy
} -result A

test doctools-toc-import-18.1 {include remove, known} -setup {
    doctools::toc::import I
} -body {
    I include add A
    I include remove A
    I include paths
} -cleanup {
    I destroy
} -result {}

test doctools-toc-import-19.0 {include clear} -setup {
    doctools::toc::import I
} -body {
    I include add A
    I include add B
    I include clear
    I include paths
} -cleanup {
    I destroy
} -result {}

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

source [localPath tests/import]

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