diff options
Diffstat (limited to 'tcllib/modules/grammar_fa/tests/fa_symbol.test')
-rw-r--r-- | tcllib/modules/grammar_fa/tests/fa_symbol.test | 254 |
1 files changed, 254 insertions, 0 deletions
diff --git a/tcllib/modules/grammar_fa/tests/fa_symbol.test b/tcllib/modules/grammar_fa/tests/fa_symbol.test new file mode 100644 index 0000000..673baa5 --- /dev/null +++ b/tcllib/modules/grammar_fa/tests/fa_symbol.test @@ -0,0 +1,254 @@ +# -*- tcl -*- +# finite_automaton.test: tests for the grammar::fa container. +# +# Copyright (c) 2004-2007 by Andreas Kupries <andreas_kupries@users.sourceforge.net> +# +# RCS: @(#) $Id: fa_symbol.test,v 1.7 2009/10/27 21:17:23 andreas_kupries Exp $ + +# ------------------------------------------------------------------------- + +test fa-symbol-${setimpl}-1.0 {symbol, error} { + grammar::fa a + catch {a symbol} res + a destroy + set res +} {wrong number args: should be "::a symbol method args"} +# [tcltest::wrongNumArgs {::a symbol method} {sym args} 0] + + +test fa-symbol-${setimpl}-1.1 {symbol, error} { + grammar::fa a + catch {a symbol foo @} res + a destroy + set res +} {"::a symbol foo" is not defined} + + +test fa-symbol-${setimpl}-1.2 {symbol, error} { + grammar::fa a + catch {a symbol add} res + a destroy + set res +} [tcltest::wrongNumArgs ::grammar::fa::Snit_hmethodsymbol_add {type selfns win self sym args} 4] + + +test fa-symbol-${setimpl}-1.3 {symbol, error} { + grammar::fa a + a symbol add x + catch {a symbol add x} res + a destroy + set res +} {Symbol "x" is already known} + + +test fa-symbol-${setimpl}-1.4 {symbol, error} { + grammar::fa a + catch {a symbol add ""} res + a destroy + set res +} {Cannot add illegal empty symbol ""} + + +test fa-symbol-${setimpl}-1.5 {symbol, error} { + grammar::fa a + catch {a symbol delete} res + a destroy + set res +} [tcltest::wrongNumArgs ::grammar::fa::Snit_hmethodsymbol_delete {type selfns win self sym args} 4] + + +test fa-symbol-${setimpl}-1.6 {symbol, error} { + grammar::fa a + catch {a symbol delete @} res + a destroy + set res +} {Illegal symbol "@"} + + +test fa-symbol-${setimpl}-1.7 {symbol, error} { + grammar::fa a + catch {a symbol exists} res + a destroy + set res +} [tcltest::wrongNumArgs ::grammar::fa::Snit_hmethodsymbol_exists {type selfns win self sym} 4] + + +test fa-symbol-${setimpl}-1.8 {symbol, error} { + grammar::fa a + catch {a symbol exists a b} res + a destroy + set res +} [tcltest::tooManyArgs ::grammar::fa::Snit_hmethodsymbol_exists {type selfns win self sym}] + + +test fa-symbol-${setimpl}-1.9 {symbol, error} { + grammar::fa a + catch {a symbol rename} res + a destroy + set res +} [tcltest::wrongNumArgs ::grammar::fa::Snit_hmethodsymbol_rename {type selfns win self sym newsym} 4] + + +test fa-symbol-${setimpl}-1.10 {symbol, error} { + grammar::fa a + catch {a symbol rename foo} res + a destroy + set res +} [tcltest::wrongNumArgs ::grammar::fa::Snit_hmethodsymbol_rename {type selfns win self sym newsym} 5] + + +test fa-symbol-${setimpl}-1.11 {symbol, error} { + grammar::fa a + catch {a symbol rename foo bar snarf} res + a destroy + set res +} [tcltest::tooManyArgs ::grammar::fa::Snit_hmethodsymbol_rename {type selfns win self sym newsym}] + + +test fa-symbol-${setimpl}-1.12 {symbol, error} { + grammar::fa a + catch {a symbol rename x y} res + a destroy + set res +} {Illegal symbol "x"} + + +test fa-symbol-${setimpl}-1.13 {symbol, error} { + grammar::fa a + catch {a symbol rename "" y} res + a destroy + set res +} {Illegal symbol ""} + + +test fa-symbol-${setimpl}-1.14 {symbol, error} { + grammar::fa a + a symbol add x y + catch {a symbol rename x y} res + a destroy + set res +} {Symbol "y" is already known} + + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +test fa-symbol-${setimpl}-2.0 {symbol add} { + grammar::fa a + set res {} + lappend res [a symbol add x y] + lappend res [lsort [a symbols]] + a destroy + set res +} {{} {x y}} + + +test fa-symbol-${setimpl}-2.1 {symbol add} { + grammar::fa a + a symbol add x + set res [a symbols] + a destroy + set res +} x + + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +test fa-symbol-${setimpl}-3.0 {symbol delete} { + grammar::fa a + a symbol add x + set res [a symbols] + lappend res [a symbol exists x] + a symbol delete x + lappend res [a symbols] + lappend res [a symbol exists x] + a destroy + set res +} {x 1 {} 0} + + +test fa-symbol-${setimpl}-3.1 {symbol delete, transitions} { + grammar::fa a + a state add x y + a symbol add @ + a next x @ --> y + + set res [a symbols] + lappend res [a symbol exists @] + a symbol delete @ + lappend res [a symbols] + lappend res [a symbol exists @] + lappend res [validate_serial {grammar::fa {} {x {0 0 {}} y {0 0 {}}}} a] + a destroy + set res +} {@ 1 {} 0 ok} + + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +test fa-symbol-${setimpl}-4.0 {symbol exists} { + grammar::fa a + set res [a symbol exists x] + a destroy + set res +} 0 + + +test fa-symbol-${setimpl}-4.1 {symbol exists} { + grammar::fa a + a symbol add x + set res [a symbol exists x] + a destroy + set res +} 1 + + +test fa-symbol-${setimpl}-4.2 {symbol exists} { + grammar::fa a + a symbol add x + set res [a symbol exists x] + a symbol delete x + lappend res [a symbol exists x] + a destroy + set res +} {1 0} + + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +test fa-symbol-${setimpl}-5.0 {symbol rename} { + grammar::fa a + a symbol add x y + a symbol rename x z + set res [validate_serial {grammar::fa {y z} {}} a] + a destroy + set res +} ok + + +test fa-symbol-${setimpl}-5.1 {symbol rename} { + grammar::fa a + a symbol add x y + a symbol rename y z + set res [validate_serial {grammar::fa {x z} {}} a] + a destroy + set res +} ok + + +test fa-symbol-${setimpl}-5.2 {symbol rename} { + grammar::fa a + a state add x y + a symbol add @ + a next x @ --> y + a symbol rename @ = + set res [validate_serial {grammar::fa = {x {0 0 {= y}} y {0 0 {}}}} a] + a destroy + set res +} ok + + +# ------------------------------------------------------------------------- +::tcltest::cleanupTests |