head	1.2;
access;
symbols
	tcllib-1-13:1.2
	tcllib-1-12:1.2;
locks; strict;
comment	@# @;


1.2
date	2009.11.15.05.50.03;	author andreas_kupries;	state Exp;
branches;
next	1.1;

1.1
date	2009.04.18.21.14.21;	author andreas_kupries;	state Exp;
branches;
next	;


desc
@@


1.2
log
@
	* container.test: Fixed up typos in comments refering to keyword
	* export.tcl: indices, while the packages are all about tables of
	* export_doctoc.tcl: contents. Unchanged functionality, version
	* export_doctoc.test: left unchanged.
	* export_html.tcl:
	* export_html.test:
	* export_json.tcl:
	* export_json.test:
	* export_nroff.tcl:
	* export_nroff.test:
	* export_text.tcl:
	* export_text.test:
	* export_wiki.tcl:
	* export_wiki.test:
	* import.tcl:
	* import_doctoc.tcl:
	* import_json.tcl:
	* include/export/config/doctoc.inc:
	* include/export/config/html.inc:
	* include/export/config/nroff.inc:
	* include/export/plugin.inc:
	* include/import/plugin.inc:
	* parse.tcl:
	* tests/container:
	* tests/export:
	* tests/import:
@
text
@# -*- tcl -*-
# toc_import.testsuite: Tests for the management of toc import plugins.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@@users.sourceforge.net>
# All rights reserved.
#
# RCS: @@(#) $Id: import,v 1.1 2009/04/18 21:14:21 andreas_kupries Exp $

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

# Tests are run for all formats we have an import plugin for.

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

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

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# doctoc markup

# We are checking that the various forms of doctoc markup, as can be
# generated by doctools::toc(::format::doctoc) are valid input to the
# doctoc parser.

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-plugin-doctoc-20.$k.$n "doctools::toc::import text /doctoc, $label$section, ok" -setup {
	    doctools::toc::import I
	    foreach {n v} $mytestconfig { I config set $n $v }
	    foreach p $mytestincludes   { I include add $p }
	} -body {
	    doctools::toc::structure print [I import text $data doctoc]
	} -cleanup {
	    I destroy
	} -result $expected
    }

    TestFilesProcess $mytestdir ok doctoc$section serial-print -> n label input data expected {
	test doctools-toc-import-plugin-doctoc-21.$k.$n "doctools::toc::import file /doctoc, $label$section, ok" -setup {
	    doctools::toc::import I
	    foreach {n v} $mytestconfig { I config set $n $v }
	    foreach p $mytestincludes   { I include add $p }
	} -body {
	    doctools::toc::structure print [I import file $input doctoc]
	} -cleanup {
	    I destroy
	} -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-plugin-doctoc-22.$n "doctools::toc::import text /doctoc, $label, error message" -setup {
	doctools::toc::import I
	foreach {n v} $mytestconfig { I config set $n $v }
	foreach p $mytestincludes   { I include add $p }
    } -body {
	I import text $data doctoc
    } -cleanup {
	I destroy
    } -returnCodes error -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-import-plugin-doctoc-23.$n "doctools::toc::import text /doctoc, $label, error code" -setup {
	doctools::toc::import I
	foreach {n v} $mytestconfig { I config set $n $v }
	foreach p $mytestincludes   { I include add $p }
    } -body {
	# Catch and rethrow using the error code as new message.
	catch {	I import text $data doctoc }
	set ::errorCode
    } -cleanup {
	I destroy
    } -result $expected
}

TestFilesProcess $mytestdir fail doctoc emsg -> n label input data expected {
    test doctools-toc-import-plugin-doctoc-24.$n "doctools::toc::import file /doctoc, $label, error message" -setup {
	doctools::toc::import I
	foreach {n v} $mytestconfig { I config set $n $v }
	foreach p $mytestincludes   { I include add $p }
    } -body {
	I import file $input doctoc
    } -cleanup {
	I destroy
    } -returnCodes error -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-import-plugin-doctoc-25.$n "doctools::toc::import file /doctoc, $label, error code" -setup {
	doctools::toc::import I
	foreach {n v} $mytestconfig { I config set $n $v }
	foreach p $mytestincludes   { I include add $p }
    } -body {
	# Catch and rethrow using the error code as new message.
	catch {	I import file $input doctoc }
	set ::errorCode
    } -cleanup {
	I destroy
    } -result $expected
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# text markup - This is not an importable format.

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# json - Java Script Object Notation

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

foreach {k section} {
    0 {}
    1 -ultracompact
    2 -indented
    3 -indalign
} {
    TestFilesProcess $mytestdir ok json$section serial-print -> n label input data expected {
	test doctools-toc-import-plugin-json-26.$k.$n "doctools::toc::import text /json, $label$section, ok" -setup {
	    doctools::toc::import I
	} -body {
	    doctools::toc::structure print [I import text $data json]
	} -cleanup {
	I destroy
    } -result $expected
    }

    TestFilesProcess $mytestdir ok json$section serial-print -> n label input data expected {
	test doctools-toc-import-plugin-json-27.$k.$n "doctools::toc::import file /json, $label$section, ok" -setup {
	    doctools::toc::import I
	} -body {
	    doctools::toc::structure print [I import file $input json]
	} -cleanup {
	I destroy
    } -result $expected
    }
}

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

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

TestFilesProcess $mytestdir fail json json-emsg -> n label input data expected {
    test doctools-toc-import-plugin-json-28.$n "doctools::toc::import text /json, $label, error message" -setup {
	doctools::toc::import I
    } -body {
	I import text $data json
    } -cleanup {
	I destroy
    } -returnCodes error -result $expected
}

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


1.1
log
@
	* Doctools version 2, processing tables of contents.
@
text
@d2 1
a2 1
# toc_import.testsuite: Tests for the managed of index import plugins.
d7 1
a7 1
# RCS: @@(#) $Id: import,v 1.1 2009/04/01 04:28:37 andreas_kupries Exp $
@

