File: enum.test

package info (click to toggle)
critcl 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,680 kB
  • sloc: ansic: 41,058; tcl: 12,090; sh: 7,230; pascal: 3,456; asm: 3,058; ada: 1,681; cpp: 1,001; cs: 879; makefile: 333; perl: 104; xml: 95; f90: 10
file content (99 lines) | stat: -rw-r--r-- 2,668 bytes parent folder | download
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
# -*- tcl -*-
# -------------------------------------------------------------------------
# enum.test
# -------------------------------------------------------------------------

source [file join [file dirname [info script]] support testutilities.tcl]

testsNeedTcl     8.6 9
testsNeedTcltest 2

support {
    useLocal lib/stubs_container/container.tcl stubs::container
    useLocal lib/stubs_reader/reader.tcl       stubs::reader
    useLocal lib/stubs_genframe/genframe.tcl   stubs::gen

    useLocal lib/critcl/critcl.tcl             critcl
    useLocal lib/critcl-iassoc/iassoc.tcl      critcl::iassoc
    useLocal lib/critcl-literals/literals.tcl  critcl::literals

    localcache-setup
}
testing {
    useLocal lib/critcl-enum/enum.tcl critcl::enum
}

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

test enum-mode-tcl+list-1.0 {critcl-enum, mode: +list} -setup {
    make-demo TL {
        critcl::enum::def demo {
            E_global global
            E_exact  exact
            E_filler filler
        } +list

        critcl::cproc decode {Tcl_Interp* ip int args} object {
            Tcl_Obj* res = demo_ToObjList (ip, args.c, args.v);
            Tcl_IncrRefCount (res);
            return res;
        }
    }
} -body {
    decode 1 0 2
} -result {exact global filler}

test enum-mode-tcl-1.0 {critcl-enum, mode: tcl} -setup {
    make-demo TL {
        critcl::enum::def demo {
            E_global global
            E_exact  exact
            E_filler filler
        }

        critcl::cproc encode {Tcl_Interp* ip Tcl_Obj* str} int {
            int val;
            demo_GetFromObj (ip, str, 0, &val);
            return val;
        }

        critcl::cproc decode {Tcl_Interp* ip int val} object {
            Tcl_Obj* res = demo_ToObj (ip, val);
            Tcl_IncrRefCount (res);
            return res;
        }

        # Encode hidden in the argtype.
        critcl::cproc xencode {Tcl_Interp* ip demo str} int {
            return str;
        }

        # Encode hidden in the argtype.
        critcl::cproc xencode-p {Tcl_Interp* ip demo-prefix str} int {
            return str;
        }

        # Decode hidden in the resultype
        critcl::cproc xdecode {Tcl_Interp* ip int val} demo {
            return val;
        }
    }
} -body {
    res!
    res+ [encode    exact]
    res+ [xencode   filler]
    res+ [xencode-p glob]
    res+ [xencode   glob]
    res+ [decode  2]
    res+ [xdecode 0]
    res?
} -result {1 2 0 0 filler global}

# -------------------------------------------------------------------------
testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End: