# -*- tcl -*-
# General set of error cases regarding the number of arguments.

test pt-peg-import-parse:${parseimpl}-rde:${rdeimpl}-stack:${stackimpl}-1.0 {import, wrong#args} -body {
    import
} -returnCodes error -result {wrong # args: should be "import text"}

test pt-peg-import-parse:${parseimpl}-rde:${rdeimpl}-stack:${stackimpl}-1.1 {import, wrong#args} -body {
    import S XXX
} -returnCodes error -result {wrong # args: should be "import text"}

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

# Testing the processing of various forms of peg input.

foreach {k section} {
    0 {}
    1 -fused
    2 -templated
    3 -templated-fused
} {
    TestFilesProcess $mytestdir ok peg_peg$section peg_serial-canonical -> n label input data expected {
	# The PEG parser flattens the expression it comes across, as
	# part of the conversion from AST to grammar. The grammars we
	# have around are not flattened, so we have to this now for
	# proper comparison.

	pt::peg::container G deserialize $expected
	G start [pt::pe::op flatten [G start]]
	foreach s [G nonterminals] {
	    G rule $s [pt::pe::op flatten [G rule $s]]
	}
	set expected [G serialize]
	G destroy

	test pt-peg-import-parse:${parseimpl}-rde:${rdeimpl}-stack:${stackimpl}-2.$k.$n "pt::peg::import::peg, $label$section, ok :- $input" -body {
	    import $data
	} -result $expected
    }
}

# TODO :: Should test handling of failures as well, for various forms
# of malformed peg input (essentially bad serializations).

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