File: assign.t

package info (click to toggle)
libwant-perl 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 168 kB
  • ctags: 10
  • sloc: perl: 167; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (4)
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
BEGIN { $| = 1; print "1..10\n"; }

# Test that we can load the module
END {print "not ok 1\n" unless $loaded;}
use Want;
$loaded = 1;
print "ok 1\n";

# Test the ASSIGN context

sub t {
    my $t = shift();
    print (want(@_) ? "ok $t\n" : "not ok $t\n");
}

my $t;
sub tl :lvalue {
    $t = shift();
    print (want(@_) ? "ok $t\n" : "not ok $t\n");
    $t;
}

sub noop {}
sub idl :lvalue {@_[0..$#_]}

t (2, qw/RVALUE !ASSIGN/);
tl(3, qw/RVALUE !ASSIGN/);
noop(tl(4, qw/LVALUE !ASSIGN/));
tl(5, qw/LVALUE ASSIGN/) = ();
tl(6, 'ASSIGN') = ();

sub backstr :lvalue {
    if (want('LVALUE')) {
	carp("Not in ASSIGN context") unless want('ASSIGN');
	my $a = want('ASSIGN');
	$_[0] = reverse $a;
	lnoreturn;
    }
    else {
	rreturn scalar reverse $_[0];
    }
    die; return;
}

my $b = backstr("qwerty");
print ($b eq "ytrewq" ? "ok 7\n" : "not ok 7\t# $b\n");
backstr(my $foo) = "robin";
print ($foo eq 'nibor' ? "ok 8\n" : "not ok 8\n");

# Try with some stuff on the stack
for(1..3) {
  backstr($foo) = 23;
}

print ($foo eq 32 ? "ok 9\n" : "not ok 9\n");

idl(tl(10, 'LVALUE', '!ASSIGN')) = ();