# -*- tcl -*-
# toc_import_doctoc.testsuite:  tests for the doctoc import plugin.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: import_doctoc,v 1.1 2009/04/18 21:14:21 andreas_kupries Exp $

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

source [tcllibPath doctools2base/tests/common]
set mytestdir      data
set mytestconfig   {fox dog lazy jump}
set mytestincludes [TestFilesGlob $mytestdir]

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

# We are checking that the various forms of doctoc markup, as can be
# generated by doctools::toc(::export(::doctoc)) are valid input to
# the doctoc parser.
#
# section {} holds the non-canonical input we have to accept and make
# canonical to higher layers.

foreach {k section} {
    0 {}
    1 -ultracompact
    2 -compact
    3 -indented
    4 -aligned
    5 -indalign
} {
    TestFilesProcess $mytestdir ok doctoc$section serial-print -> n label input data expected {
	test doctools-toc-import-doctoc-${stkimpl}-${setimpl}-${impl}-2.$k.$n "doctools::toc::import::doctoc, $label$section, ok" -setup {
	    doctools::toc::parse include set $mytestincludes
	} -body {
	    doctools::toc::structure print [import $data $mytestconfig]
	} -cleanup {
	    doctools::toc::parse include clear
	} -result $expected
    }
}

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

# We test the error messages and codes thrown by the parser for a
# variety of failure possibilities.

TestFilesProcess $mytestdir fail doctoc emsg -> n label input data expected {
    test doctools-toc-import-doctoc-${stkimpl}-${setimpl}-${impl}-3.$n "doctools::toc::import::doctoc, $label, error message" -setup {
	doctools::toc::parse include set $mytestincludes
    } -body {
	import $data $mytestconfig
    } -cleanup {
	doctools::toc::parse include clear
    } -returnCodes error -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-import-doctoc-${stkimpl}-${setimpl}-${impl}-4.$n "doctools::toc::import::doctoc, $label, error code" -setup {
	doctools::toc::parse include set $mytestincludes
    } -body {
	# Catch and rethrow using the error code as new message.
	catch {	import $data $mytestconfig }
	set ::errorCode
    } -cleanup {
	doctools::toc::parse include clear
    } -result $expected
}

# -------------------------------------------------------------------------
unset mytestdir n label input data expected
return