~vcs-imports/gawk/master

« back to all changes in this revision

Viewing changes to test/rwarray.awk

  • Committer: Arnold D. Robbins
  • Date: 2012-11-25 19:54:48 UTC
  • mfrom: (319.1.122)
  • Revision ID: git-v1:9a9ff61bbd952c1263b55f82a269da5b09289a6b
Merge branch 'master' into array-iface

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@load "rwarray"
 
2
 
 
3
BEGIN {
 
4
        while ((getline word) > 0)
 
5
                dict[word] = word word
 
6
 
 
7
        n = asorti(dict, dictindices)
 
8
        for (i = 1; i <= n; i++)
 
9
                printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "orig.out"
 
10
        close("orig.out");
 
11
 
 
12
        ret = writea("orig.bin", dict)
 
13
        printf "writea() returned %d, expecting 1\n", ret
 
14
 
 
15
 
 
16
        ret = reada("orig.bin", dict)
 
17
        printf "reada() returned %d, expecting 1\n", ret
 
18
 
 
19
        n = asorti(dict, dictindices)
 
20
        for (i = 1; i <= n; i++)
 
21
                printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "new.out"
 
22
        close("new.out");
 
23
 
 
24
        ret = system("cmp orig.out new.out")
 
25
 
 
26
        if (ret == 0)
 
27
                print "old and new are equal - GOOD"
 
28
        else
 
29
                print "old and new are not equal - BAD"
 
30
 
 
31
        if (ret == 0 && !("KEEPIT" in ENVIRON))
 
32
                system("rm -f orig.bin orig.out new.out")
 
33
}