| 1 |
@load "rwarray" |
| 2 |
|
| 3 |
BEGIN { |
| 4 |
while ((getline word) > 0) |
| 5 |
dict[word] = word word |
| 6 |
|
| 7 |
re_sub = "/typed-regex/" |
| 8 |
dict[re_sub] = @/search me/ |
| 9 |
|
| 10 |
strnum_sub = "strnum-sub" |
| 11 |
split("-2.4", f) |
| 12 |
dict[strnum_sub] = f[1] |
| 13 |
|
| 14 |
bool_sub = "bool-sub" |
| 15 |
dict[bool_sub] = mkbool(1) |
| 16 |
|
| 17 |
dict["x"] = "x" |
| 18 |
|
| 19 |
dict["42"] = 42 |
| 20 |
dict["42.42"] = 42.42 |
| 21 |
|
| 22 |
n = asorti(dict, dictindices) |
| 23 |
for (i = 1; i <= n; i++) |
| 24 |
printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "orig.out" |
| 25 |
close("orig.out"); |
| 26 |
|
| 27 |
ret = writea("orig.bin", dict) |
| 28 |
printf "writea() returned %d, expecting 1\n", ret |
| 29 |
|
| 30 |
ret = reada("orig.bin", dict) |
| 31 |
printf "reada() returned %d, expecting 1\n", ret |
| 32 |
|
| 33 |
n = asorti(dict, dictindices) |
| 34 |
for (i = 1; i <= n; i++) |
| 35 |
printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "new.out" |
| 36 |
close("new.out"); |
| 37 |
|
| 38 |
os = "" |
| 39 |
if (ENVIRON["AWKLIBPATH"] == "sys$disk:[-]") { |
| 40 |
os = "VMS" |
| 41 |
# return status from system() on VMS can not be used here |
| 42 |
} |
| 43 |
if (os != "VMS") { |
| 44 |
ret = system("cmp orig.out new.out") |
| 45 |
|
| 46 |
if (ret == 0) |
| 47 |
print "old and new are equal - GOOD" |
| 48 |
else |
| 49 |
print "old and new are not equal - BAD" |
| 50 |
|
| 51 |
if (ret == 0 && !("KEEPIT" in ENVIRON)) |
| 52 |
system("rm -f orig.bin orig.out new.out") |
| 53 |
} |
| 54 |
|
| 55 |
if (typeof(dict[re_sub]) != "regexp") |
| 56 |
printf("dict[\"%s\"] should be regexp, is %s\n", |
| 57 |
re_sub, typeof(dict[re_sub])); |
| 58 |
|
| 59 |
if (typeof(dict[strnum_sub]) != "strnum") |
| 60 |
printf("dict[\"%s\"] should be strnum, is %s\n", |
| 61 |
strnum_sub, typeof(dict[strnum_sub])); |
| 62 |
|
| 63 |
if (typeof(dict[bool_sub]) != "number|bool") |
| 64 |
printf("dict[\"%s\"] should be number|bool, is %s\n", |
| 65 |
bool_sub, typeof(dict[bool_sub])); |
| 66 |
|
| 67 |
if ((dict[bool_sub] "") != "1") |
| 68 |
printf("dict[\"%s\"] should be 1, is %s\n", |
| 69 |
bool_sub, dict[bool_sub]); |
| 70 |
} |