summaryrefslogtreecommitdiff
path: root/os2/OS2/REXX/t/rx_tievar.t
blob: 77f90c2f59f34aff8d5e2b174490cc3a70f4bac9 (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
BEGIN {
    chdir 't' if -d 't/lib';
    @INC = '../lib' if -d 'lib';
    require Config; import Config;
    if (-d 'lib' and $Config{'extensions'} !~ /\bOS2(::|\/)REXX\b/) {
	print "1..0\n";
	exit 0;
    }
}

use OS2::REXX;

#
# DLL
#
load OS2::REXX "ydbautil" or die "1..0\n# load\n";

print "1..19\n";

REXX_call {
  print "ok 1\n";

  #
  # scalar
  #
  tie $s, OS2::REXX, "TEST";
  print "ok 2\n";
  $s = 1;
  print "ok 3\n" if $s eq 1;
  print "not ok 3\n# `$s'\n" unless $s eq 1;
  untie $s;

  #
  # hash
  #

  tie %all, OS2::REXX, "";	# all REXX vars
  print "ok 4\n";

  sub show {
	# show all REXX vars
	print "--@_--\n";
	foreach (keys %all) {
		$v = $all{$_};
		print "$_ => $v\n";
	}
  }

  sub check {
	# check all REXX vars
	my ($test, @arr) = @_;
	my @rx;
	foreach $key (sort keys %all) { push @rx, $key, $all{$key} }
	if ("@rx" eq "@arr") {print "ok $test\n"}
	else { print "not ok $test\n# expect `@arr', got `@rx'\n" }
  }


  tie %h, OS2::REXX, "TEST.";
  print "ok 5\n";
  check(6);

  $h{"one"} = 1;
  check(7, "TEST.one", 1);

  $h{"two"} = 2;
  check(8, "TEST.one", 1, "TEST.two", 2);

  $h{"one"} = "";
  check(9, "TEST.one", "", "TEST.two", 2);
  print "ok 10\n" if exists $h{"one"};
  print "ok 11\n" if exists $h{"two"};

  delete $h{"one"};
  check(12, "TEST.two", 2);
  print "ok 13\n" if not exists $h{"one"};
  print "ok 14\n" if exists $h{"two"};

  OS2::REXX::dropall("TEST.");
  print "ok 15\n";
  check(16);
  print "ok 17\n" if not exists $h{"one"};
  print "ok 18\n" if not exists $h{"two"};

  untie %h;
  print "ok 19";

};