OSDN Git Service

2756358d8cb5e5697e0ca6d7d8d568b27b6e4893
[pf3gnuchains/sourceware.git] / tcl / tests / autoMkindex.tcl
1 # Test file for:
2 #   auto_mkindex
3 #
4 # This file provides example cases for testing the Tcl autoloading
5 # facility.  Things are much more complicated with namespaces and classes.
6 # The "auto_mkindex" facility can no longer be built on top of a simple
7 # regular expression parser.  It must recognize constructs like this:
8 #
9 #   namespace eval foo {
10 #       proc test {x y} { ... }
11 #       namespace eval bar {
12 #           proc another {args} { ... }
13 #       }
14 #   }
15 #
16 # Note that procedures and itcl class definitions can be nested inside
17 # of namespaces.
18 #
19 # Copyright (c) 1993-1998  Lucent Technologies, Inc.
20
21 # This shouldn't cause any problems
22 namespace import -force blt::*
23
24 # Should be able to handle "proc" definitions, even if they are
25 # preceded by white space.
26
27 proc normal {x y} {return [expr $x+$y]}
28   proc indented {x y} {return [expr $x+$y]}
29
30 #
31 # Should be able to handle proc declarations within namespaces,
32 # even if they have explicit namespace paths.
33 #
34 namespace eval buried {
35     proc inside {args} {return "inside: $args"}
36
37     namespace export pub_*
38     proc pub_one {args} {return "one: $args"}
39     proc pub_two {args} {return "two: $args"}
40 }
41 proc buried::within {args} {return "within: $args"}
42
43 namespace eval buried {
44     namespace eval under {
45         proc neath {args} {return "neath: $args"}
46     }
47     namespace eval ::buried {
48         proc relative {args} {return "relative: $args"}
49         proc ::top {args} {return "top: $args"}
50         proc ::buried::explicit {args} {return "explicit: $args"}
51     }
52 }
53
54 # With proper hooks, we should be able to support other commands
55 # that create procedures
56
57 proc buried::myproc {name body args} {
58     ::proc $name $body $args
59 }
60 namespace eval ::buried {
61     proc mycmd1 args {return "mycmd"}
62     myproc mycmd2 args {return "mycmd"}
63 }
64 ::buried::myproc mycmd3 args {return "another"}
65
66 proc {buried::my proc} {name body args} {
67     ::proc $name $body $args
68 }
69 namespace eval ::buried {
70     proc mycmd4 args {return "mycmd"}
71     {my proc} mycmd5 args {return "mycmd"}
72 }
73 {::buried::my proc} mycmd6 args {return "another"}