# -*- tcl -*- # finite_automaton.test: tests for the grammar::fa::dexec engine # # Copyright (c) 2004-2007 by Andreas Kupries # # RCS: @(#) $Id: de_cons.test,v 1.8 2007/04/12 03:43:14 andreas_kupries Exp $ # ------------------------------------------------------------------------- if {![::tcltest::testConstraint runtotal]} { ::tcltest::cleanupTests return } # ------------------------------------------------------------------------- global events # ------------------------------------------------------------------------- test de-cons-${setimpl}-1.0 {construction error} { catch {grammar::fa::dexec a} msg set msg } {Error in constructor: wrong # args: should be "::grammar::fa::dexec::Snit_constructor type selfns win self fa args"} test de-cons-${setimpl}-1.1 {construction error} { catch {grammar::fa::dexec a foo fie far} msg set msg } {Error in constructor: unknown option "fie"} test de-cons-${setimpl}-1.2 {construction error} { catch {grammar::fa::dexec a b} msg set msg } {Error in constructor: invalid command name "b"} foreach {n code setup_result} { 00 x {{} 0 x 1} 01 x- {{} 0 x 1} 02 xe {{} 0 x 0} 03 xy {{} 0 x 1 y 1 {x y} 0} 04 xy- {{} 0 x 1 y 1 {x y} 0} 05 xye {{} 0 x 0 y 0 {x y} 0} 06 xyee {{} 0 x 0 y 0 {x y} 0} 07 xye- {{} 0 x 0 y 0 {x y} 0} 08 xy-- {{} 0 x 1 y 1 {x y} 0} 09 xy-= {{} 0 x 1 y 1 {x y} 0} 10 xyz/ee {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 11 xyz/e- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 12 xyz/-- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 13 xyz/-= {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 14 xyz|ee {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 15 xyz|e- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 16 xyz|-- {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 17 xyz|-= {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 18 xyz+eee {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 19 xyz+ee- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 20 xyz+e-- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 21 xyz+e-= {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 22 xyz+--- {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 23 xyz+--= {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 24 xyz+-=_ {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 25 xyz&eee {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 26 xyz&ee- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 27 xyz&e-- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 28 xyz&e-= {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 29 xyz&--- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 30 xyz&--= {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 31 xyz&-=_ {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 32 xyz!ee {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 33 xyz!e- {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 34 xyz!-- {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 35 xyz!-= {{} 0 x 1 y 1 z 1 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} 36 xyz!-e {{} 0 x 0 y 0 z 0 {x y} 0 {x z} 0 {y z} 0 {x y z} 0} } { foreach {stset expected} $setup_result { foreach {fset __} $setup_result { set key ${n}.${code}.([join $stset {}]).([join $fset {}]) test de-cons-${setimpl}-1.3.$key {construction error} { grammar::fa a gen $code a start set $stset a final set $fset set nfa [expr {![a is deterministic]}] set fail [catch {grammar::fa::dexec de a -command {lappend events}} msg] a destroy catch {de destroy} set res [expr {($nfa && $fail) || (!$nfa && !$fail)}] if {!$res} {set res $msg} set res } 1 } } } test de-cons-${setimpl}-1.4 {construction error} { grammar::fa a gen xyz+-=_ a start add x catch {grammar::fa::dexec de a -any *} msg a destroy set msg } {Error in constructor: Chosen any symbol "*" does not exist} test de-cons-${setimpl}-1.5 {construction error} { grammar::fa a gen xyz+-=_ a start add x catch {grammar::fa::dexec de a -any @} msg a destroy set msg } {Error in constructor: Command callback missing} # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test de-cons-${setimpl}-2.0 {construction} { grammar::fa a gen xyz+-=_ a start add x grammar::fa::dexec de a -command {lappend events} a destroy de destroy } {} test de-cons-${setimpl}-2.1 {construction} { set res {} grammar::fa a gen xyz+-=_ a start add x lappend res [info commands ::de] grammar::fa::dexec de a -command {lappend events} a destroy lappend res [info commands ::de] de destroy lappend res [info commands ::de] set res } {{} ::de {}} test de-cons-${setimpl}-2.2 {construction} { grammar::fa a gen xyz+-=_ a start add x grammar::fa::dexec de a -any @ -command {lappend events} a destroy de destroy } {} # ------------------------------------------------------------------------- unset events ::tcltest::cleanupTests