# -*- tcl -*-
# pt_peg_import_plugins.tests: Tests for the management of peg import plugins.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: pt_peg_import_plugins.tests,v 1.1 2010/03/26 05:07:24 andreas_kupries Exp $

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

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

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

if 0 {
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# doctoc markup

# We are checking that the various forms of doctoc markup, as can be
# generated by pt::peg(::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 pt-peg-import-plugin-doctoc-20.$k.$n "pt::peg::import text /doctoc, $label$section, ok :- $input" -setup {
	    pt::peg::import I
	    foreach {n v} $mytestconfig { I config set $n $v }
	    foreach p $mytestincludes   { I include add $p }
	} -body {
	    pt::peg::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 pt-peg-import-plugin-doctoc-21.$k.$n "pt::peg::import file /doctoc, $label$section, ok :- $input" -setup {
	    pt::peg::import I
	    foreach {n v} $mytestconfig { I config set $n $v }
	    foreach p $mytestincludes   { I include add $p }
	} -body {
	    pt::peg::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 pt-peg-import-plugin-doctoc-22.$n "pt::peg::import text /doctoc, $label, error message :- $input" -setup {
	pt::peg::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 pt-peg-import-plugin-doctoc-23.$n "pt::peg::import text /doctoc, $label, error code :- $input" -setup {
	pt::peg::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 pt-peg-import-plugin-doctoc-24.$n "pt::peg::import file /doctoc, $label, error message :- $input" -setup {
	pt::peg::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 pt-peg-import-plugin-doctoc-25.$n "pt::peg::import file /doctoc, $label, error code :- $input" -setup {
	pt::peg::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 pt::peg(::export(::json)) are valid input to the json
# parser.

foreach {k section} {
    0 -ultracompact
    1 -indented
    2 -indalign
} {
    TestFilesProcess $mytestdir ok peg_json$section peg_serial-canonical -> n label input data expected {
	test pt-peg-import-plugin-json-26.$k.$n "pt::peg::import text /json, $label$section, ok :- $input" -setup {
	    pt::peg::import I
	} -body {
	    I import text $data json
	} -cleanup {
	    I destroy
	} -result $expected
    }

    TestFilesProcess $mytestdir ok peg_json$section peg_serial-canonical -> n label input data expected {
	test pt-peg-import-plugin-json-27.$k.$n "pt::peg::import file /json, $label$section, ok :- $input" -setup {
	    pt::peg::import I
	} -body {
	    I import file $input json
	} -cleanup {
	    I destroy
	} -result $expected
    }
}

# -------------------------------------------------------------------------
if 0 {
# 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 pt-peg-import-plugin-json-28.$n "pt::peg::import text /json, $label, error message :- $input" -setup {
	pt::peg::import I
    } -body {
	I import text $data json
    } -cleanup {
	I destroy
    } -returnCodes error -result $expected
}
}
# -------------------------------------------------------------------------
unset mytestdir n label input data expected
return
