# -*- tcl -*-
# idx_import_docidx.testsuite:  tests for the docidx import plugin.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: import_docidx,v 1.1 2009/04/01 04:28:37 andreas_kupries Exp $

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

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

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

# We are checking that the various forms of docidx markup, as can be
# generated by doctools::idx(::export(::docidx)) are valid input to
# the docidx 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 docidx$section serial-print -> n label input data expected {
	test doctools-idx-import-docidx-${stkimpl}-${setimpl}-${impl}-2.$k.$n "doctools::idx::import::docidx, $label$section, ok" -setup {
	    doctools::idx::parse include set $mytestincludes
	} -body {
	    doctools::idx::structure print [import $data $mytestconfig]
	} -cleanup {
	    doctools::idx::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 docidx emsg -> n label input data expected {
    test doctools-idx-import-docidx-${stkimpl}-${setimpl}-${impl}-3.$n "doctools::idx::import::docidx, $label, error message" -setup {
	doctools::idx::parse include set $mytestincludes
    } -body {
	import $data $mytestconfig
    } -cleanup {
	doctools::idx::parse include clear
    } -returnCodes error -result $expected
}

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

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