7017
|
1 ## Copyright (C) 2004, 2006, 2007 Paul Kienzle |
5837
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
7016
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 ## |
|
19 ## Original version by Paul Kienzle distributed as free software in the |
|
20 ## public domain. |
5837
|
21 |
|
22 ## -*- texinfo -*- |
|
23 ## @deftypefn {Function File} {} inputname (@var{n}) |
5838
|
24 ## Return the text defining @var{n}-th input to the function. |
5837
|
25 ## @end deftypefn |
|
26 |
|
27 function s = inputname (n) |
7125
|
28 |
|
29 if (nargin != 1) |
|
30 print_usage (); |
|
31 endif |
|
32 |
5838
|
33 s = evalin ("caller", sprintf ("deblank (argn(%d,:));", n)); |
7125
|
34 |
5837
|
35 endfunction |
|
36 |
|
37 ## Warning: heap big magic in the following tests!!! |
|
38 ## The test function builds a private context for each |
|
39 ## test, with only the specified values shared between |
|
40 ## them. It does this using the following template: |
|
41 ## |
|
42 ## function [<shared>] = testfn(<shared>) |
|
43 ## <test> |
|
44 ## |
|
45 ## To test inputname, I need a function context invoked |
|
46 ## with known parameter names. So define a couple of |
|
47 ## shared parameters, et voila!, the test is trivial. |
|
48 %!shared hello,worldly |
|
49 %!assert(inputname(1),'hello'); |
|
50 %!assert(inputname(2),'worldly'); |