Ticket #5: testrecu.py

File testrecu.py, 1.2 KB (added by Peter Murphy (pkmurphy at postmaster dot co dot uk), 8 years ago)

Small test file

Line 
1# This is the testrecu module. It contains code that tests the output and input of
2# YAML with recursive structures.
3
4import yaml;
5
6# We start with sequences.
7
8RecSeq1 = [];
9RecSeq1.append(RecSeq1);
10print RecSeq1;
11
12RecSeq2 = [];
13RecSeq2.append(u"a");
14RecSeq2.append(RecSeq2);
15RecSeq2.append(u"b");
16print RecSeq2;
17
18RecSeq3 = [];
19RecSeq3a = [];
20RecSeq3.append(RecSeq3a);
21RecSeq3a.append(RecSeq3);
22print RecSeq3;
23
24RecSeq4 = [];
25RecSeq4a = [];
26RecSeq4.append(RecSeq4a);
27RecSeq4a.append(u"a");
28RecSeq4a.append(RecSeq4);
29RecSeq4a.append(u"b");
30print RecSeq4;
31
32RecMap1 = {};
33RecMap1["a"]= RecMap1;
34print RecMap1;
35
36RecMap2 = {};
37RecMap2["a"] = u"d";
38RecMap2["b"] = RecMap1;
39RecMap2["c"] = u"e";
40print RecSeq2;
41
42RecMap3 = {};
43RecMap3a = {};
44RecMap3["a"] = RecMap3a;
45RecMap3a["b"] = RecMap3;
46print RecSeq3;
47
48RecMap4 = {};
49RecMap4a = {};
50RecMap4["a"] = RecMap4a;
51RecMap4a["b"] = u"c";
52RecMap4a["d"] = RecMap4;
53RecMap4a["e"] = u"f";
54print RecSeq4;
55
56
57
58
59
60print "YAML" 
61print yaml.dump(RecSeq1);
62print yaml.dump(RecSeq2);
63print yaml.dump(RecSeq3);
64print yaml.dump(RecSeq4);
65
66print yaml.dump(RecMap1);
67print yaml.dump(RecMap2);
68print yaml.dump(RecMap3);
69print yaml.dump(RecMap4);