# -*- tcl -*-
# fa_operations.test:  tests for the FA operations.
#
# Copyright (c) 2004-2007 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# RCS: @(#) $Id: faop_complete.test,v 1.4 2007/04/12 03:43:15 andreas_kupries Exp $

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

test faop-complete-${setimpl}-1.0 {complete, error} {
    catch {grammar::fa::op::complete} res
    set res
} {wrong # args: should be "grammar::fa::op::complete fa ?sink?"}


test faop-complete-${setimpl}-1.1 {complete, error} {
    catch {grammar::fa::op::complete a b c} res
    set res
} {wrong # args: should be "grammar::fa::op::complete fa ?sink?"}


test faop-complete-${setimpl}-1.2 {complete, error} {
    catch {grammar::fa::op::complete a} res
    set res
} {invalid command name "a"}


test faop-complete-${setimpl}-1.3 {complete, error} {
    grammar::fa a
    a state add sink x
    a symbol add @
    catch {grammar::fa::op::complete a sink} res
    a destroy
    set res
} {The chosen sink state exists already}


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


foreach {n code result} {
    00 x       {grammar::fa {} {x {0 0 {}}}}
    01 x-      {grammar::fa @  {x {0 0 {@ x}}}}
    02 xe      {grammar::fa {} {x {0 0 {{} x}}}}
    03 xy      {grammar::fa {} {x {0 0 {}} y {0 0 {}}}}
    04 xy-     {grammar::fa @  {x {0 0 {@  y}} y {0 0 {@ sink}} sink {0 0 {@ sink}}}}
    05 xye     {grammar::fa {} {x {0 0 {{} y}} y {0 0 {}}}}
    06 xyee    {grammar::fa {} {x {0 0 {{} y}} y {0 0 {{} x}}}}
    07 xyz/ee  {grammar::fa {}    {x {0 0 {{} {y z}}} y {0 0 {}} z {0 0 {}}}}
    08 xyz/-=  {grammar::fa {@ =} {x {0 0 {@ y = z}} y {0 0 {@ sink = sink}} z {0 0 {@ sink = sink}} sink {0 0 {@ sink = sink}}}}
    09 xyz|ee  {grammar::fa {} {x {0 0 {{} z}} y {0 0 {{} z}} z {0 0 {}}}}
    10 xyz|-=  {grammar::fa {@ =} {x {0 0 {@ z = sink}} y {0 0 {@ sink = z}} z {0 0 {@ sink = sink}} sink {0 0 {@ sink = sink}}}}
    11 xyz+eee {grammar::fa {}      {x {0 0 {{} y}} y {0 0 {{} z}} z {0 0 {{} x}}}}
    12 xyz+-=_ {grammar::fa {@ % =} {x {0 0 {@ y % sink = sink}} y {0 0 {@ sink % sink = z}} z {0 0 {@ sink = sink % x}} sink {0 0 {@ sink = sink % sink}}}}
    13 xyz&eee {grammar::fa {} {x {0 0 {{} {y z}}} y {0 0 {{} z}} z {0 0 {}}}}
    14 xyz&-=_ {grammar::fa {@ % =} {x {0 0 {@ y % sink = z}} y {0 0 {@ sink = sink % z}} z {0 0 {@ sink = sink % sink}} sink {0 0 {@ sink = sink % sink}}}}
    15 xyz!ee  {grammar::fa {} {x {0 0 {{} y}} y {0 0 {{} z}} z {0 0 {}}}}
    16 xyz!-=  {grammar::fa {@ % =} {x {0 0 {@ y % sink = sink}} y {0 0 {@ sink % sink = z}} z {0 0 {@ sink = sink % sink}} sink {0 0 {@ sink = sink % sink}}}}
} {
    set key ${n}.${code}

    test faop-complete-${setimpl}-2.$key {complete} {
	grammar::fa a
	gen $code
	grammar::fa::op::complete a sink
	set     res [a is complete]
	lappend res [validate_serial $result a]
	a destroy
	set res
    } {1 ok}

    test faop-complete-${setimpl}-3.$key {second complete is a null operation} {
	grammar::fa a
	gen $code
	grammar::fa::op::complete a
	set res [a serialize]
	grammar::fa::op::complete a
	set res [validate_serial $res a]
	a destroy
	set res
    } ok

    test faop-complete-${setimpl}-4.$key {complete, as method} {
	grammar::fa a
	gen $code
	a complete sink
	set     res [a is complete]
	lappend res [validate_serial $result a]
	a destroy
	set res
    } {1 ok}

    test faop-complete-${setimpl}-5.$key {as method, second complete is a null operation} {
	grammar::fa a
	gen $code
	a complete
	set res [a serialize]
	a complete
	set res [validate_serial $res a]
	a destroy
	set res
    } ok
}


# -------------------------------------------------------------------------
::tcltest::cleanupTests
