summaryrefslogtreecommitdiff
path: root/itcl/itcl/tests/mkindex.itcl
blob: bef0fb5358e09e94b364c802af28b75830c348b4 (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
# Test file for:
#   auto_mkindex
#
# This file provides example cases for testing the Tcl autoloading
# facility.  Things are much more complicated with namespaces and classes.
# The "auto_mkindex" facility can no longer be built on top of a simple
# regular expression parser.  It must recognize constructs like this:
#
#   namespace eval foo {
#       class Internal { ... }
#       body Internal::func {x y} { ... }
#       namespace eval bar {
#           class Another { ... }
#       }
#   }
#
# Note that class definitions can be nested inside of namespaces.
#
# Copyright (c) 1993-1998  Lucent Technologies, Inc.

#
# Should be able to handle simple class definitions, even if
# they are prefaced with white space.
#
namespace import itcl::*
namespace import blt::*

class Simple1 {
    variable x 0
    public method bump {} {incr x}
}
  itcl::class Simple2 {
    variable x 0
    public variable by 1
    public method bump {}
  }

itcl_class OldStyle {
  public x 0
  method foo {args} {return $args}
}

itcl::ensemble ens {
    part one {x} {}
    part two {x y} {}
    part three {x y z} {}
}

#
# Should be able to handle "body" and "configbody" declarations.
#
body Simple2::bump {} {incr x $by}
configbody Simple2::by {if {$by <= 0} {error "bad increment"}}

#
# Should be able to handle class declarations within namespaces,
# even if they have explicit namespace paths.
#
namespace eval buried {
    class inside {
        variable x 0
        public variable by 1
        public method bump {}
        method skip {x y z} {}
        proc find {args} {}
    }
    body inside::bump {} {incr x $by}
    configbody inside::by {if {$by <= 0} {error "bad increment"}}

    class ::top {
        method skip {x y z} {}
        method ignore {} {}
        public proc find {args} {}
        protected proc notice {args} {}
    }

    ensemble ens {
        part one {x} {}
        part two {x y} {}
        part three {x y z} {}
    }

    namespace eval under {
        itcl::class neath { }
    }
    namespace eval deep {
        ::itcl::class within { }
    }
}