summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/grammar_fa/tests/da_cons.test
blob: 42cdb6a0832e89b15792062d0631aec0d28510c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- tcl -*-
# finite_automaton.test:  tests for the grammar::fa::dacceptor engine
#
# Copyright (c) 2004-2007 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# RCS: @(#) $Id: da_cons.test,v 1.8 2007/04/12 03:43:14 andreas_kupries Exp $

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

if {![::tcltest::testConstraint runtotal]} {
    ::tcltest::cleanupTests
    return
}

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

test da-cons-${setimpl}-1.0 {construction error} {
    catch {grammar::fa::dacceptor a} msg
    set msg
} {Error in constructor: wrong # args: should be "::grammar::fa::dacceptor::Snit_constructor type selfns win self fa args"}


test da-cons-${setimpl}-1.1 {construction error} {
    catch {grammar::fa::dacceptor a foo fie far} msg
    set msg
} {Error in constructor: unknown option "fie"}


test da-cons-${setimpl}-1.2 {construction error} {
    catch {grammar::fa::dacceptor 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 da-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::dacceptor da a} msg]
		a destroy
		catch {da destroy}

		expr {($nfa && $fail) || (!$nfa && !$fail)}
	    } 1
	}
    }
}

test da-cons-${setimpl}-1.4 {construction error} {
    grammar::fa a
    gen xyz+-=_
    a start add x
    catch {grammar::fa::dacceptor da a -any *} msg
    a destroy
    set msg
} {Error in constructor: Chosen any symbol "*" does not exist}

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


test da-cons-${setimpl}-2.0 {construction} {
    grammar::fa a
    gen xyz+-=_
    a start add x
    grammar::fa::dacceptor da a
    a destroy
    da destroy
} {}


test da-cons-${setimpl}-2.1 {construction} {
    set res {}
    grammar::fa a
    gen xyz+-=_
    a start add x
    lappend res [info commands ::da]
    grammar::fa::dacceptor da a
    a destroy
    lappend res [info commands ::da]
    da destroy
    lappend res [info commands ::da]
    set res
} {{} ::da {}}


test da-cons-${setimpl}-2.2 {construction} {
    grammar::fa a
    gen xyz+-=_
    a start add x
    grammar::fa::dacceptor da a -any @
    a destroy
    da destroy
} {}

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