Class: TestXampl

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/xamplr/test-support/test.rb,
lib/xamplr/test-support/test-misc.rb,
lib/xamplr/test-support/test-cache.rb,
lib/xamplr/test-support/test-names.rb,
lib/xamplr/test-support/test-elements.rb,
lib/xamplr/test-support/test-indexed-array.rb

Overview

generator.report_elements

Instance Method Summary collapse

Instance Method Details

#check_parents(xampl, parent = nil) ⇒ Object



1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
# File 'lib/xamplr/test-support/test.rb', line 1487

def check_parents(xampl, parent=nil)
  if (nil != parent) then
    found = false
    xampl.parents.each{ | p |
      found = true if (parent == p)
    }
    assert(found)
  else
    if (xampl.kind_of? XamplObject)
      assert((nil == xampl.parents) || (0 == xampl.parents.size))
    end
  end
  xampl.children.each{ | child |
    check_parents(child, xampl) if (child.kind_of? XamplObject)
  }
end

#choose_name_test_helper(name, expected_class_name, expected_attribute_name) ⇒ Object



1007
1008
1009
1010
1011
1012
1013
# File 'lib/xamplr/test-support/test.rb', line 1007

def choose_name_test_helper(name, expected_class_name, expected_attribute_name)
  original_name = name.dup
  class_name, attribute_name = Generator.choose_names(name, "", "")
  assert_equal(original_name, name, "changed the original name")
  assert_equal(expected_class_name, class_name, "CLASS name wrong")
  assert_equal(expected_attribute_name, attribute_name, "ATTRIBUTE name wrong")
end

#setupObject



51
52
53
54
# File 'lib/xamplr/test-support/test.rb', line 51

def setup
  Xampl.disable_all_persisters
  #FromXML.reset_registry
end

#test_bug_indexed_child_same_pid_added_twiceObject

TODO – test no namespace



1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
# File 'lib/xamplr/test-support/test.rb', line 1237

def test_bug_indexed_child_same_pid_added_twice
  element = Element.new
  attr0 = element.new_attribute("repeated")

  assert_equal(1, element.attribute_child.size)
  assert_equal(1, element.attribute_child.size)
  assert_equal(1, element.children.size)
  assert_equal(attr0, element.children[0])

  ce1 = element.new_child_element("something")

  assert_equal(1, element.attribute_child.size)
  assert_equal(1, element.attribute_child.size)
  assert_equal(2, element.children.size)
  assert_equal(attr0, element.children[0])
  assert_equal(ce1, element.children[1])

  attr2 = element.new_attribute("repeated")

  assert_equal(1, element.attribute_child.size)
  assert_equal(1, element.attribute_child.size)
  assert_equal(2, element.children.size)
  assert_equal(ce1, element.children[0])
  assert_equal(attr2, element.children[1])
end

#test_choose_namesObject



1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
# File 'lib/xamplr/test-support/test.rb', line 1205

def test_choose_names
  choose_name_test_helper("abcd", "Abcd", "abcd")
  choose_name_test_helper("Abcd", "Abcd", "abcd")
  choose_name_test_helper("abCd", "AbCd", "ab_cd")
  choose_name_test_helper("AbCd", "AbCd", "ab_cd")
  choose_name_test_helper("ABcd", "ABcd", "abcd")

  choose_name_test_helper("ABcdefABCdef", "ABcdefABCdef", "abcdef_abcdef")

  choose_name_test_helper("ab-cd", "AbCd", "ab_cd")
  choose_name_test_helper("Ab-Cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab--cd", "AbCd", "ab_cd")
  choose_name_test_helper("Ab--Cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab_-cd", "AbCd", "ab_cd")
  choose_name_test_helper("Ab_-Cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab__cd", "AbCd", "ab_cd")
  choose_name_test_helper("Ab__Cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab:cd", "AbCd", "ab_cd")
  choose_name_test_helper("Ab:Cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab.cd", "AbCd", "ab_cd")

  choose_name_test_helper("ab9cd", "AbCd", "ab_cd")
  choose_name_test_helper("ab9Cd", "AbCd", "ab_cd")
end

#test_cycles_and_bushy2_localsObject



1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File 'lib/xamplr/test-support/test.rb', line 1291

def test_cycles_and_bushy2_locals
  pname = "test_cycles_and_bushy" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  #Xampl.enable_persister(pname, :filesystem)
  Xampl.enable_persister(pname, :in_memory)
  Xampl.auto_persistence

  root = Thing.new("root")

  root.new_thing("branch1").new_thing("leaf")
  root.new_thing("branch2").new_thing("leaf")
  root.new_thing("branch3").new_thing("leaf")

  cycle0 = root.new_thing("cycle0")
  cycle0.new_thing("cycle1").new_thing("cycle2").new_thing("cycle0")

  assert_equal(Thing.lookup("cycle2").thing["cycle0"],
               Thing.lookup("root").thing["cycle0"])

  Xampl.sync

  assert_equal(8, CountingVisitor.new.start(root).count)

  #puts root.pp_xml
end

#test_cycles_and_bushy_lookupObject



1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
# File 'lib/xamplr/test-support/test.rb', line 1263

def test_cycles_and_bushy_lookup
  pname = "test_cycles_and_bushy" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  #Xampl.enable_persister(pname, :filesystem)
  Xampl.enable_persister(pname, :in_memory)
  Xampl.auto_persistence

  root = Thing.new("root")
  root.info = "one"

  root.new_thing("branch1").new_thing("leaf").info = "two"
  root.new_thing("branch2").new_thing("leaf").info = "three"
  root.new_thing("branch3").new_thing("leaf").info = "four"

  root.new_thing("cycle0").info = "five"
  Thing.lookup("cycle0").new_thing("cycle1").new_thing("cycle2").info = "six"
  Thing.lookup("cycle2").new_thing("cycle0")

  assert(Thing.lookup("cycle2").thing["cycle0"] == Thing.lookup("cycle0"))
  assert(Thing.lookup("root").thing["cycle0"] == Thing.lookup("cycle0"))

  Xampl.sync

  assert_equal(8, CountingVisitor.new.start(root).count)

  pp_xml = root.pp_xml
  #puts root.pp_xml
end

#test_data_xamplObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/xamplr/test-support/test.rb', line 150

def test_data_xampl
  emph_content_1 = "there"
  emph_content_2 = "are"
  big_thing = Xampl.make(Thing){ | big_thing |
    big_thing.pid = "big_thing"
    big_thing.new_thing("thing"){ | thing |
      thing.new_stuff.kind = "stuff1"

      thing.new_description{ | desc |
        desc.kind = "desc1"

        desc.add_content("hello ")
        desc.new_emph.content = emph_content_1
        desc.add_content("! How ")
        desc.new_emph.content = emph_content_2
        desc.add_content(" you?")
      }
    }
  }

  ###    desc1 = Description.new
  ###    desc1.kind = "desc1"
  ###
  ###    desc1.add_content("hello ")
  ###    emph_content_1 = "there"
  ###    desc1.new_emph.content = emph_content_1
  ###    desc1.add_content("! How ")
  ###    emph_content_2 = "are"
  ###    desc1.new_emph.content = emph_content_2
  ###    desc1.add_content(" you?")
  ###
  ###    thing = Thing.new
  ###    thing.pid = "thing"
  ###    assert(thing.is_changed)
  ###    thing.new_stuff.kind = "stuff1"
  ###    assert_not_nil(thing.is_changed)
  ###    thing.is_changed = nil
  ###    thing.add_description(desc1)
  ###    assert_not_nil(thing.is_changed)
  ###
  ###    big_thing = Thing.new
  ###    big_thing.add_thing(thing)
  assert_equal("<ex:thing pid='big_thing' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'><ex:thing pid='thing'><ex:stuff kind='stuff1'/><ex:description kind='desc1'>hello <ex:emph>there</ex:emph>! How <ex:emph>are</ex:emph> you?</ex:description></ex:thing></ex:thing>",
               big_thing.test_to_xml)

  assert_equal(1, big_thing.children.length)
  assert_equal(2, big_thing.thing_child[0].children.length)
  assert_equal(big_thing.thing_child[0].description_child[0].emph_child.length, 2)
  assert_equal(emph_content_1, big_thing.thing_child[0].description_child[0].emph_child[0].content, emph_content_1)
  assert_equal(emph_content_2, big_thing.thing_child[0].description_child[0].emph_child[1].content, emph_content_2)

  check_parents(big_thing)
end

#test_data_xampl_using_appendObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/xamplr/test-support/test.rb', line 226

def test_data_xampl_using_append
  emph_content_1 = "there"
  emph1 = Emph.new
  emph1 << emph_content_1

  emph_content_2 = "are"
  emph2 = Emph.new
  emph2.content = emph_content_2

  desc1 = Description.new
  desc1.kind = "desc1"

  desc1.is_changed = nil
  desc1 << "hello " << emph1 << "! How " << emph2 << " you?"
  assert_not_nil(desc1.is_changed)

  thing = Thing.new
  thing.pid = "thing"
  thing.new_stuff.kind = "stuff1"
  thing << desc1

  big_thing = Thing.new
  big_thing << thing

  assert_equal("<ex:thing xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'><ex:thing pid='thing'><ex:stuff kind='stuff1'/><ex:description kind='desc1'>hello <ex:emph>there</ex:emph>! How <ex:emph>are</ex:emph> you?</ex:description></ex:thing></ex:thing>",
               big_thing.test_to_xml)

  assert_equal(2, big_thing.thing_child[0].description_child[0].emph_child.length)
  assert_equal(emph_content_1, big_thing.thing_child[0].description_child[0].emph_child[0].content)
  assert_equal(emph_content_2, big_thing.thing_child[0].description_child[0].emph_child[1].content)

  check_parents(big_thing)
end

#test_empty_xamplObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/xamplr/test-support/test.rb', line 91

def test_empty_xampl
  stuff1 = Stuff.new
  assert_not_nil(stuff1.is_changed)
  stuff1.kind = 'test'
  assert_not_nil(stuff1.is_changed)

  stuff2 = Stuff.new
  assert_not_nil(stuff2.is_changed)

  stuff3 = Stuff.new
  assert_not_nil(stuff3.is_changed)
  stuff3.kind = 'test'
  assert_not_nil(stuff3.is_changed)
  stuff3.special = 'test'
  assert_not_nil(stuff3.is_changed)

  assert_equal("<ex:stuff kind='test' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)
  assert_equal("<ex:stuff xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff2.test_to_xml)
  assert_equal("<ex:stuff kind='test' exs:special='test' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff3.test_to_xml)

  fakeRules = XMLPrinter.new("fake...")
  stuff1.test_to_xml_internal(fakeRules)
  r = fakeRules.done
  assert_equal("fake... xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'<ex:stuff kind='test'/>", r)

  check_parents(stuff1)
  check_parents(stuff2)
  check_parents(stuff3)
end

#test_ensureObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/xamplr/test-support/test.rb', line 204

def test_ensure
  big_thing = Xampl.make(Thing){ | big_thing |
    big_thing.pid = "big_thing"
    big_thing.ensure_thing("thing"){ | thing |
      thing.info = "first";
    }
    big_thing.ensure_thing("thing"){ | thing |
      flunk "What are you doing in here?"
      thing.info = "second";
    }
  }

  assert_equal(1, big_thing.thing.length)
  assert_equal("first", big_thing.thing[0].info)

  desc = Description.new
  desc.ensure_emph
  assert_equal(1, desc.emph.length)
  #NOTE -- ensure_emph used to be aliased to new_emph, now it just makes
  #        sure that there is at least one emph
end

#test_escapingObject



997
998
999
1000
1001
1002
1003
1004
1005
# File 'lib/xamplr/test-support/test.rb', line 997

def test_escaping
  description = Description.new
  description.kind = "<>&'\""
  description << "<>&'\""

  expect = "<ex:description kind='&lt;&gt;&amp;&apos;&quot;' xmlns:ex='http://xampl.com/example'>&lt;>&amp;'\"</ex:description>"

  assert_equal(expect, description.test_to_xml)
end

#test_filesystem_persistence_automaticObject



794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# File 'lib/xamplr/test-support/test.rb', line 794

def test_filesystem_persistence_automatic
  stuff = Stuff.new
  thing = Thing.new
  thing << stuff

  thing.pid = "thing"

  pname = "test_filesystem_persistence_automatic_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :filesystem)
  Xampl.auto_persistence

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  assert_equal(thing, Xampl.lookup(Thing, "thing"))

  assert(thing.persister)
  assert(thing.is_changed)
  assert_equal(1, Xampl.count_changed)

  assert_equal(thing, Xampl.lookup(Thing, "thing"), "cannot lookup new stuff")

  writes = Xampl.sync

  assert_equal(1, writes)
  assert_equal(0, Xampl.count_changed)

  assert(Xampl.lookup(Thing, "thing"))
  assert_equal(thing, Xampl.lookup(Thing, "thing"), "cannot lookup cached stuff")
  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup cached stuff")

  Xampl.clear_cache

  found = Xampl.lookup(Thing, "thing")
  assert_not_equal(thing, found)
  assert_not_same(thing, found)

  root = Thing.new
  root.pid = "root"
  found2 = root.new_thing("thing")

  assert_equal(found, found2, "in automatic persistence mode, supposed to look stuff up")

  #Xampl.print_stats
end

#test_filesystem_persistence_basicsObject



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/xamplr/test-support/test.rb', line 617

def test_filesystem_persistence_basics
  stuff = Stuff.new
  thing = Thing.new
  thing << stuff

  thing.pid = "thing"

  assert_xampl_exception(:name_required){
    Xampl.enable_persister(nil, :filesystem)
  }

  pname = "test_filesystem_persistence_basics_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :filesystem)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  assert_nil(Xampl.lookup(Thing, "thing"))

  assert(nil == thing.persister)
  assert(thing.is_changed)
  assert_equal(0, Xampl.count_changed)

  Xampl.introduce_to_persister(thing)

  assert(thing.persister)
  assert_equal(1, Xampl.count_changed)
  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup new stuff")

  #Xampl.print_stats

  assert_equal(1, Xampl.count_changed)
  writes = Xampl.sync
  assert_equal(1, writes)
  assert_equal(0, Xampl.count_changed)
  assert(Xampl.lookup(Thing, "thing"))

  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup cached stuff")

  Xampl.clear_cache

  found = Xampl.lookup(Thing, "thing")
  assert_not_same(thing, found)
  assert(thing === found)

  Xampl.clear_cache

  # now, changing thing will affect the DB -- VERY SUBTLE POSSIBLIITY OF BUG!
  thing.new_stuff
  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  writes = Xampl.sync

  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  found2 = Xampl.lookup(Thing, "thing")

  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)
  assert_equal(2, found2.stuff.size)

  assert(!(found === found2))
  assert(thing === found2)

  assert_not_equal(found, found2)

  #Xampl.print_stats
end

#test_filesystem_persistence_over_write_on_parseObject



717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
# File 'lib/xamplr/test-support/test.rb', line 717

def test_filesystem_persistence_over_write_on_parse
  name = "test_filesystem_persistence_over_write_on_parse_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  holder = nil
  Xampl.transaction(name, :filesystem, automatic=true) do
    holder = Thing.new("root")
  end

  Xampl.transaction(name, :filesystem, automatic=true) do
    1.upto(10) do |i|
      cname = "child#{i}"
      child = holder.new_thing(cname)
      child.new_key_value('index').value = cname
    end
  end

  Xampl.transaction(name, :filesystem, automatic=true) do
    Xampl.print_stats
  end

  xml = holder.pp_xml

  Xampl.transaction(name, :filesystem, automatic=true) do
    1.upto(11) do |i|
      cname = "child#{i}"
      child = holder.ensure_thing(cname)
      child.ensure_key_value('index').value = "changed#{i}"
    end
    holder.remove_thing("child1")
  end

  assert_equal(10, holder.thing.size)
  assert_equal(holder.children.size, holder.thing.size)

  parsed_holder = nil
  Xampl.transaction(name, :filesystem, automatic=true) do
    parsed_holder = XamplObject.from_xml_string(xml)
  end

  assert_equal(10, holder.thing.size)
  assert_equal(holder.children.size, holder.thing.size)

  assert_equal(parsed_holder, holder)

  Xampl.transaction(name, :filesystem, automatic=true) do
    holder.thing.each{ | child |
      found = Xampl.lookup(Thing, child.pid)
      assert_equal(child, found)
      assert_equal(child, parsed_holder.thing[child.pid])
    }
    Xampl.print_stats
  end
end

#test_filesystem_persistence_rollbackObject



842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'lib/xamplr/test-support/test.rb', line 842

def test_filesystem_persistence_rollback
  pname = "test_filesystem_persistence_rollback_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  original_persister = Xampl.enable_persister(pname, :filesystem)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)

  Xampl.rollback

  current_persister = Xampl.persister

  assert_equal(original_persister, current_persister)
  #assert_not_equal(original_persister, current_persister)

  # no sync after thing's creation, so thing should NOT exist after rollback
  found = Xampl.lookup(Thing, "thing")
  assert_nil(found)

  assert_equal(original_persister, thing.persister)

  #assert_xampl_exception(:live_across_rollback){
  #  thing.new_stuff
  #}
  thing.stuff.size

  writes = Xampl.sync

  assert_equal(0, writes)
end

#test_filesystem_persistence_rollback_survivalObject



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# File 'lib/xamplr/test-support/test.rb', line 876

def test_filesystem_persistence_rollback_survival
  pname = "test_filesystem_persistence_rollback_survival_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  original_persister = Xampl.enable_persister(pname, :filesystem)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)

  assert_equal(1, thing.stuff.size)
  Xampl.sync
  assert_equal(1, thing.stuff.size)

  thing.new_stuff
  thing.info = "something"

  assert_equal(2, thing.stuff.size)

  Xampl.rollback

  assert(thing.load_needed)
  assert_nil(thing.info, "attributes not cleared by the rollback")
  assert(!thing.load_needed)
  assert_equal(1, thing.stuff.size)

  current_persister = Xampl.persister

  assert_equal(original_persister, current_persister)

  # a sync done BEFORE the second 'stuff' was added to thing
  found = Xampl.lookup(Thing, "thing")
  assert_equal(found.object_id, thing.object_id)

  assert_equal(original_persister, current_persister)
  assert_equal(current_persister, thing.persister)
  assert_equal(current_persister, found.persister)

  assert(!thing.load_needed)
  assert(!thing.is_changed)

  thing.stuff.size

  assert(!thing.load_needed)
  assert(!thing.is_changed)

  assert_equal(found.object_id, thing.object_id)
  assert_equal(1, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  #assert_xampl_exception(:live_across_rollback){
  #  thing.new_stuff
  #}

  assert(!thing.is_changed)
  writes = Xampl.sync

  assert_equal(0, writes)

  new_thing = found.new_thing("new_thing")
  new_thing.new_stuff

  writes = Xampl.sync

  assert_equal(2, writes)

  new_thing.new_stuff
  writes = Xampl.sync
  assert_equal(1, writes)

  Xampl.rollback

  assert_equal(0, Xampl.persister.read_count)

  thing = Thing.lookup("thing")
  assert_not_nil(thing)
  assert_equal(0, Xampl.persister.read_count, "not in the cache")

  new_thing = thing.thing["new_thing"]
  assert_not_nil(new_thing)
  assert_equal(0, Xampl.persister.read_count, "not in the cache")

  keep_new_thing = new_thing

  # these (to xml, ruby) will NOT suck the child thing into memory
  xml = thing.test_to_xml

  ruby = thing.to_ruby
  ruby_thing = XamplObject.from_ruby(ruby)

  assert_equal(0, Xampl.persister.read_count, "not in the cache")

  # this will trigger the lazy load of new_thing
  size = new_thing.stuff.size

  assert_equal(0, Xampl.persister.read_count, "not in the cache")
  assert_equal(keep_new_thing, new_thing)
  assert_equal(new_thing, thing.thing["new_thing"])

  Xampl.rollback

  # another way to get stuff into memory
  # ACTUALLY, this is not legal, there is a cache conflict problem
  illegal_lazy_thing = Thing.new
  illegal_lazy_thing.pid = "thing"
  illegal_lazy_thing.load_needed = true
  #assert_xampl_exception(:cache_conflict){
  #  assert(thing === illegal_lazy_thing)
  #}
  #assert_raise(XamplIsInvalid){
  #  # due to a change in xampl this is OK (it isn't invalid yet)
  #illegal_lazy_thing.info = "oops"
  #}

  okay_thing = Thing.lookup("thing")
  assert(okay_thing)
  okay_thing.info = "okay"
end

#test_filesystem_persistence_rubyObject



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/xamplr/test-support/test.rb', line 770

def test_filesystem_persistence_ruby
  pname = "test_filesystem_persistence_ruby" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :filesystem, :ruby_format)
  persister2 = Xampl.persister

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)
  Xampl.sync

  thing.info = "force emptying"

  Xampl.rollback

  assert(thing.load_needed)

  found = Xampl.lookup(Thing, "thing")

  assert_equal(thing.object_id, found.object_id)
end

#test_filesystem_persistence_very_manyObject



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/xamplr/test-support/test.rb', line 690

def test_filesystem_persistence_very_many
  name = "test_filesystem_persistence_very_many_ut" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  holder = nil

  Xampl.transaction(name, :filesystem, automatic=true) do
    holder = Thing.new("root")
  end

  1.upto(200) do |i|
    Xampl.transaction(name, :filesystem, automatic=true) do
      child = holder.new_thing("child#{i}")
    end
  end

  #Xampl.transaction(name, :filesystem, automatic=true) do
  #Xampl.print_stats
  #end

  Xampl.transaction(name, :filesystem, automatic=true) do
    holder.thing.each{ | child |
      found = Xampl.lookup(Thing, child.pid)
      assert_equal(child, found)
    }
    #Xampl.print_stats
  end
end

#test_from_xmlObject



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/xamplr/test-support/test.rb', line 260

def test_from_xml
  emph_content_1 = "there"
  emph1 = Emph.new
  emph1 << emph_content_1

  emph_content_2 = "are"
  emph2 = Emph.new
  emph2.content = emph_content_2

  desc1 = Description.new
  desc1.kind = "desc1"

  desc1.is_changed = nil
  desc1 << "hello " << emph1 << "! How " << emph2 << " you?"

  thing = Thing.new
  thing.pid = "thing"
  thing.new_stuff.kind = "stuff1"
  thing << desc1

  big_thing = Thing.new
  big_thing << "leading content" << thing << "trailing content"

  #puts big_thing.test_to_xml
  #pp = FromXML.new
  #pp.setup_parse_string(big_thing.test_to_xml)
  #while not pp.endDocument?
  #event = pp.next_interesting_event
  #puts event
  #if (event == Xampl_PP::TEXT) then
  #puts "TEXT [[[" << pp.text << "]]]"
  #end
  #end

  pp = FromXML.new
  pp.setup_parse_string(big_thing.test_to_xml)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)

  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::START_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::TEXT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_ELEMENT)
  assert_equal(pp.next_interesting_event, Xampl_PP::END_DOCUMENT)
  assert(pp.endDocument?)

  pp = FromXML.new
  #another_big_thing = pp.parse_string(big_thing.test_to_xml)
  another_big_thing = pp.parse_string(big_thing.pp_xml)

  #assert_equal(big_thing.test_to_xml, another_big_thing.test_to_xml)
  assert_equal(big_thing.pp_xml.gsub(/\s/, ''), another_big_thing.pp_xml.gsub(/\s/, ''))
  assert_not_same(big_thing, another_big_thing)
end

#test_generator_with_no_namespaceObject



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/xamplr/test-support/test.rb', line 1015

def test_generator_with_no_namespace
  generator = Generator.new
  generator.comprehend_from_strings([
          %Q{
<things xmlns:xampl='http://xampl.com/example/special'>
<thing pid=''>
  <description kind=''>blah <emph>blah</emph> blah</description>
  <keyValue id='' value=''/>
  <stuff kind='' xampl:special=''/>
  <thing pid=''/>
  <things/>
</thing>
</things>
}
  ])

  ns = ""
  #ns = nil
  emap = generator.elements_map
  assert_equal(1, emap.size)
  elements = emap[ns]
  assert_not_nil(elements)
  assert_equal(6, elements.element_child.size)

  ename = "emph"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(!element.empty)
  assert(element.has_content)

  ename = "description"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(!element.empty)
  assert(element.has_content)

  assert_equal(1, element.attribute_child.size)
  assert_not_nil(element.attribute_child["kind"])
  assert_nil(element.attribute_child["kind"].namespace)

  assert_equal(1, element.child_element_child.size)
  cname = "{#{ns}}emph"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("emph", element.child_element_child[cname].element_name)

  ename = "stuff"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(element.empty)
  assert(!element.has_content)

  assert_equal(2, element.attribute_child.size)
  assert_not_nil(element.attribute_child["kind"])
  assert_nil(element.attribute_child["kind"].namespace)
  assert_not_nil(element.attribute_child["special"])
  assert_equal('http://xampl.com/example/special', element.attribute_child["special"].namespace)

  assert_equal(0, element.child_element_child.size)

  ename = "keyValue"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(element.empty)
  assert(!element.has_content)

  assert_equal(2, element.attribute_child.size)
  assert_not_nil(element.attribute_child["id"])
  assert_nil(element.attribute_child["id"].namespace)
  assert_not_nil(element.attribute_child["value"])
  assert_nil(element.attribute_child["value"].namespace)

  assert_equal(0, element.child_element_child.size)

  ename = "thing"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(element.empty)
  assert(!element.has_content)

  assert_equal(1, element.attribute_child.size)
  assert_equal(1, element.attribute_child.size)
  assert_not_nil(element.attribute_child["pid"])
  assert_nil(element.attribute_child["pid"].namespace)

  assert_equal(5, element.child_element_child.size)

  cname = "{#{ns}}description"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("description", element.child_element_child[cname].element_name)

  cname = "{#{ns}}keyValue"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("keyValue", element.child_element_child[cname].element_name)

  cname = "{#{ns}}stuff"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("stuff", element.child_element_child[cname].element_name)

  cname = "{#{ns}}thing"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("thing", element.child_element_child[cname].element_name)

  cname = "{#{ns}}things"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("things", element.child_element_child[cname].element_name)

  ename = "things"
  element = elements.element_child[ename]
  assert_not_nil(element)
  assert_equal(ns, element.namespace)
  assert_equal("{#{ns}}#{ename}", element.nstag)
  assert(element.empty)
  assert(!element.has_content)

  assert_equal(0, element.attribute_child.size)
  assert_equal(1, element.child_element_child.size)

  cname = "{#{ns}}thing"
  assert_not_nil(element.child_element_child[cname])
  assert_equal(ns, element.child_element_child[cname].namespace)
  assert_equal("thing", element.child_element_child[cname].element_name)

  #generator.print_stats
  generator.analyse

  ename = "emph"
  element = elements.element_child[ename]
  assert_equal("simple", element.kind, "emph is wrong kind")
  assert_nil(element.indexed_by_attr)
  assert_nil(element.persisted)
  assert_equal("XamplAdHoc", element.package)
  assert_equal("Emph", element.class_name)
  assert_equal("emph", element.attribute_name)

  ename = "description"
  element = elements.element_child[ename]
  assert_equal("mixed", element.kind, "description is wrong kind")
  assert_nil(element.indexed_by_attr)
  assert_nil(element.persisted)
  assert_equal("XamplAdHoc", element.package)
  assert_equal("Description", element.class_name)
  assert_equal("description", element.attribute_name)

  ename = "stuff"
  element = elements.element_child[ename]
  assert_equal("empty", element.kind, "stuff is wrong kind")
  assert_nil(element.indexed_by_attr)
  assert_nil(element.persisted)
  assert_equal("XamplAdHoc", element.package)
  assert_equal("Stuff", element.class_name)
  assert_equal("stuff", element.attribute_name)

  ename = "keyValue"
  element = elements.element_child[ename]
  assert_equal("empty", element.kind, "keyValue is wrong kind")
  assert_equal("id", element.indexed_by_attr)
  assert_nil(element.persisted)
  assert_equal("XamplAdHoc", element.package)
  assert_equal("KeyValue", element.class_name)
  assert_equal("key_value", element.attribute_name)

  ename = "thing"
  element = elements.element_child[ename]
  assert_equal("data", element.kind, "thing is wrong kind")
  assert_equal("pid", element.indexed_by_attr)
  assert_not_nil(element.persisted)
  assert_equal("XamplAdHoc", element.package)
  assert_equal("Thing", element.class_name)
  assert_equal("thing", element.attribute_name)

  #generator.generate_to_directory(nil)
end

#test_in_memory_persistence_basicsObject



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/xamplr/test-support/test.rb', line 427

def test_in_memory_persistence_basics
  stuff = Stuff.new
  thing = Thing.new
  thing << stuff

  assert(!stuff.persist_required)
  assert(thing.persist_required)
  assert(nil == thing.persister)

  persister = InMemoryPersister.new

  assert_xampl_exception(:no_index_so_no_persist){
    persister.write(thing)
  }

  thing.pid = "thing"

  assert(persister.write(thing))

  saved_thing = persister.read(Thing, "thing")
  assert(saved_thing)

  assert_equal(thing.test_to_xml, saved_thing.test_to_xml)
  assert_not_same(thing, saved_thing)

  pname = "first" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :in_memory)
  persister1 = Xampl.persister

  #check that the naming and kind checking is working
  assert_raise(IncompatiblePersisterRequest){
    Xampl.enable_persister(pname, :filesystem)
  }
  #okay, carry on

  Xampl.enable_persister(pname, :in_memory)
  persister2 = Xampl.persister

  assert_equal(persister1, persister2)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  assert_nil(Xampl.lookup(Thing, "thing"))

  assert(nil == thing.persister)
  assert(thing.is_changed)
  assert(0 == Xampl.count_changed)
  Xampl.introduce_to_persister(thing)
  assert(thing.persister)
  assert_equal(1, Xampl.count_changed)
  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup new stuff")
  assert_same(thing, Thing.lookup("thing"), "cannot lookup new stuff")
  assert_same(thing, Thing["thing"], "cannot lookup new stuff")

  #Xampl.print_stats

  assert_equal(1, Xampl.count_changed)
  writes = Xampl.sync
  assert_equal(1, writes)
  assert_equal(0, Xampl.count_changed)
  assert(Xampl.lookup(Thing, "thing"))

  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup cached stuff")

  Xampl.clear_cache

  found = Xampl.lookup(Thing, "thing")
  assert_not_equal(thing, found)
  assert(thing === found)

  #Xampl.print_stats
end

#test_in_memory_persistence_rollbackObject



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/xamplr/test-support/test.rb', line 522

def test_in_memory_persistence_rollback
  pname = "first" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  original_persister = Xampl.enable_persister(pname, :in_memory)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)

  Xampl.rollback

  current_persister = Xampl.persister

  #assert_not_equal(original_persister, current_persister)
  assert_equal(original_persister, current_persister)

  # no sync after thing's creation, so thing should NOT exist after rollback
  found = Xampl.lookup(Thing, "thing")
  assert_nil(found)

  assert_equal(original_persister, thing.persister)

  #assert_xampl_exception(:live_across_rollback){
  #  thing.new_stuff
  #}
  assert_raise(XamplIsInvalid){
    thing.new_stuff
  }

  writes = Xampl.sync

  assert_equal(0, writes)
end

#test_in_memory_persistence_rollback_survivalObject



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/xamplr/test-support/test.rb', line 558

def test_in_memory_persistence_rollback_survival
  pname = "first" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  original_persister = Xampl.enable_persister(pname, :in_memory)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)

  Xampl.sync

  thing.new_stuff
  thing.info = "something"

  Xampl.rollback

  assert(thing.load_needed)
  assert(!thing.is_changed)

  assert_nil(thing.info, "attributes not cleared by the rollback")

  current_persister = Xampl.persister

  #assert_not_equal(original_persister, current_persister)
  assert_equal(original_persister, current_persister) # stomp

  # a sync done BEFORE the second 'stuff' was added to thing
  found = Xampl.lookup(Thing, "thing")
  assert_equal(thing, found)

  assert_equal(original_persister, current_persister)
  assert_equal(original_persister, thing.persister)
  assert_equal(current_persister, found.persister)

  assert_equal(1, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  #    assert_xampl_exception(:live_across_rollback){
  #      thing.new_stuff
  #    }

  writes = Xampl.sync

  assert_equal(0, writes)

  new_thing = found.new_thing("new_thing")
  new_thing.new_stuff

  writes = Xampl.sync

  assert_equal(2, writes)

  new_thing.new_stuff
  writes = Xampl.sync
  assert_equal(1, writes)
end

#test_in_memory_persistence_rubyObject



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/xamplr/test-support/test.rb', line 503

def test_in_memory_persistence_ruby
  pname = "test_in_memory_persistence_ruby" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :in_memory, :ruby_format)
  persister2 = Xampl.persister

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  Xampl.introduce_to_persister(thing)
  Xampl.sync
  Xampl.clear_cache
  found = Xampl.lookup(Thing, "thing")

  assert_not_equal(thing, found)
  assert(thing === found)
end

#test_indexObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/xamplr/test-support/test.rb', line 327

def test_index
  thing = Thing.new
  thing.new_key_value("one").value = "1"
  thing.new_key_value("two").value = "2"

  assert_same(thing.key_value_child[0], thing.key_value_child["one"])
  assert_same(thing.key_value_child[1], thing.key_value_child["two"])

  thing.new_key_value("one").value = "1a"

  assert_same(thing.key_value_child[0], thing.key_value_child["two"])
  assert_same(thing.key_value_child[1], thing.key_value_child["one"])

  check_parents(thing)
end

#test_indexed_removeObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/xamplr/test-support/test.rb', line 343

def test_indexed_remove
  thing = Thing.new
  thing.new_key_value("one").value = "1"
  thing.remove_key_value(thing.key_value["one"])

  assert_equal(0, thing.children.size)
  assert_equal(0, thing.key_value_child.size)

  thing = Thing.new
  thing.new_key_value("one").value = "1"
  thing.new_key_value("two").value = "2"
  thing.remove_key_value(thing.key_value["one"])

  assert_equal(1, thing.children.size)
  assert_equal(1, thing.key_value_child.size)
  assert_not_nil(thing.key_value["two"])
  assert_equal("2", thing.key_value["two"].value)

end

#test_internal_cycles_and_bushyObject



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File 'lib/xamplr/test-support/test.rb', line 1316

def test_internal_cycles_and_bushy
  pname = "test_internal_cycles_and_bushy" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  #Xampl.enable_persister(pname, :filesystem)
  Xampl.enable_persister(pname, :in_memory)
  Xampl.auto_persistence

  root = Thing.new("root")
  root.info = "root"

  (branch1 = Branch.new).info='one'
  (branch2 = Branch.new).info='two'
  (branch3 = Branch.new).info='three'
  (branch4 = Branch.new).info='four'
  (branch5 = Branch.new).info='five'

  #puts branch1.pp_xml

  #
  #                1
  #             2     3
  #                4
  #                1
  #        and 5 is a child of 1, 2, 3, and 4

  root << branch1

  branch1 << branch2
  branch1 << branch3

  branch2 << branch4
  branch3 << branch4

  branch4 << branch1

  branch1 << branch5
  branch2 << branch5
  branch3 << branch5
  branch4 << branch5

  #assert_xampl_exception(:cycle_detected_in_xampl_cluster){
  assert_xampl_exception(:cycle_detected_in_xampl_cluster){
    xml = PersistXML.new("").start(root).done
  }

  assert_xampl_exception(:cycle_detected_in_xampl_cluster){
    Xampl.sync
  }

  #there is one thing and 5 branches, so 6 different things
  assert_equal(6, CountingVisitor.new.start(root).count)

  pp_xml = root.pp_xml
end

#test_lose_the_firstObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xamplr/test-support/test-cache.rb', line 12

def test_lose_the_first
  cache = Xampl::XamplCache.new(10)
  assert(cache)

  cache['first'] = 'first'
  assert(cache['first'])

  10.times { | i |
    id = "id.#{i}"
    cache[id] = id
  }
  assert_nil(cache['first'])
end

#test_lose_the_first_XamplCacheObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/xamplr/test-support/test-cache.rb', line 44

def test_lose_the_first_XamplCache
  cache = Xampl::XamplCache.new(10)
  assert(cache)

  assert_nil(cache['dummy'])

  cache['dummy'] = 'dummy'
  assert_equal(1, cache.size)
  cache.delete('dummy')
  assert_equal(0, cache.size)
  assert_nil(cache['dummy'])

  cache['first'] = 'first-value'
  assert(cache['first'])

  10.times { | i |
    key = "thing.#{i}"
    value = "value.#{i}"
    cache[key] = value
  }
  assert_nil(cache['first'])
end

#test_lose_the_first_XamplCacheLFUObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/xamplr/test-support/test-cache.rb', line 94

def test_lose_the_first_XamplCacheLFU
  cache = Xampl::XamplCacheLFU.new(10)
  assert(cache)

  assert_nil(cache['dummy'])

  cache['dummy'] = 'dummy'
  assert_equal(1, cache.size)
  cache.delete('dummy')
  assert_equal(0, cache.size)
  assert_nil(cache['dummy'])

  cache['first'] = 'first-value'
  assert(cache['first'])
  cache.delete('first')
  assert_nil(cache['first'])
  cache['first'] = 'first-value'

  10.times { | i |
    key = "thing.#{i}"
    value = "value.#{i}"
    cache[key] = value
    thing = cache[key]
  }
  assert_nil(cache['first'])
end

#test_lose_the_secondObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xamplr/test-support/test-cache.rb', line 26

def test_lose_the_second
  cache = Xampl::XamplCache.new(10)
  assert(cache)

  cache['first'] = 'first'
  cache['second'] = 'second'
  assert(cache['first'])
  assert(cache['second'])

  10.times { | i |
    id = "id.#{i}"
    cache[id] = id
    use_first = cache['first']
  }
  assert(cache['first'])
  assert_nil(cache['second'])
end

#test_lose_the_second_XamplCacheObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/xamplr/test-support/test-cache.rb', line 67

def test_lose_the_second_XamplCache
  cache = Xampl::XamplCache.new(10)
  assert(cache)

  # fill the cache
  10.times { | i |
    id = "id.#{i}"
    cache[id] = id
    use_first = cache['first']
  }

  cache['first'] = 'first'
  cache['second'] = 'second'
  assert(cache['first'])
  assert(cache['second'])

  10.times { | i |
    use_first = cache['first']

    id = "id.#{10 + i}"
    cache[id] = id
  }

  assert(cache['first'])
  assert_nil(cache['second'])
end

#test_lose_the_second_XamplCacheLFUObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/xamplr/test-support/test-cache.rb', line 121

def test_lose_the_second_XamplCacheLFU
  cache = Xampl::XamplCacheLFU.new(10)
  assert(cache)

  # fill the cache
  10.times { | i |
    id = "id.#{i}"
    cache[id] = id
    use_first = cache['first']
  }

  cache['first'] = 'first'
  cache['second'] = 'second'
  assert(cache['first'])
  assert(cache['second'])

  10.times { | i |
    use_first = cache['first']

    id = "id.#{10 + i}"
    cache[id] = id
  }

  assert(cache['first'])
  assert_nil(cache['second'])
end

#test_mixed_xamplObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/xamplr/test-support/test.rb', line 124

def test_mixed_xampl
  desc1 = Description.new
  assert_not_nil(desc1.is_changed)
  desc1.kind = "desc1"
  assert_not_nil(desc1.is_changed)
  assert_equal("<ex:description kind='desc1' xmlns:ex='http://xampl.com/example'/>",
               desc1.test_to_xml)

  desc1.add_content("hello ")
  emph_content_1 = "there"
  desc1.new_emph.content = emph_content_1
  desc1.add_content("! How ")
  emph_content_2 = "are"
  desc1.new_emph.content = emph_content_2
  desc1.add_content(" you?")

  assert_not_nil(desc1.is_changed)
  assert_equal("<ex:description kind='desc1' xmlns:ex='http://xampl.com/example'>hello <ex:emph>there</ex:emph>! How <ex:emph>are</ex:emph> you?</ex:description>",
               desc1.test_to_xml)
  assert_equal(desc1.emph_child.length, 2)
  assert_equal(emph_content_1, desc1.emph_child[0].content, emph_content_1)
  assert_equal(emph_content_2, desc1.emph_child[1].content, emph_content_2)

  check_parents(desc1)
end

#test_non_string_attributesObject



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/xamplr/test-support/test.rb', line 381

def test_non_string_attributes
  stuff1 = Stuff.new

  stuff1.kind = 123.456
  assert_equal("<ex:stuff kind='123.456' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)

  stuff1.kind = nil
  assert_equal("<ex:stuff xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)

  stuff1.kind = [1, 2, 3]
  assert_equal("<ex:stuff kind='123' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)

  stuff2 = Stuff.new
  stuff2.kind = 123
  stuff1.kind = stuff2
  assert_equal("<ex:stuff kind='&lt;ex:stuff kind=&apos;123&apos; xmlns:ex=&apos;http://xampl.com/example&apos; xmlns:exs=&apos;http://xampl.com/example/special&apos;/&gt;' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)

  thing = Thing.new
  thing.pid = "thing"
  thing << stuff2
  stuff1.kind = thing
  assert_equal("<ex:stuff kind='&lt;ex:thing pid=&apos;thing&apos; xmlns:ex=&apos;http://xampl.com/example&apos; xmlns:exs=&apos;http://xampl.com/example/special&apos;&gt;&lt;ex:stuff kind=&apos;123&apos;/&gt;&lt;/ex:thing&gt;' xmlns:ex='http://xampl.com/example' xmlns:exs='http://xampl.com/example/special'/>",
               stuff1.test_to_xml)

  check_parents(stuff1)
end

#test_parentsObject



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/xamplr/test-support/test.rb', line 363

def test_parents
  thing = Thing.new
  (kv1 = thing.new_key_value("one")).value = "1"
  (kv2 = thing.new_key_value("two")).value = "2"

  assert_same(thing, thing.key_value_child[0].parents[0])
  assert_same(thing, thing.key_value_child[1].parents[0])

  another_thing = Thing.new
  another_thing << kv1 << kv2

  assert_equal(2, kv1.parents.size)
  assert_equal(2, kv2.parents.size)

  check_parents(thing)
  check_parents(another_thing)
end

#test_predefined_element_info_1Object



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
# File 'lib/xamplr/test-support/test-elements.rb', line 21

def test_predefined_element_info_1
  options = Xampl.make(Options) { | options |
    options.new_index_attribute("name")
    options.new_index_attribute("id")
    options.new_index_attribute("pid").persisted = true

    options.new_resolve{ | resolver |
      resolver.pkg = "XamplExample2"
      resolver.namespace="http://xampl.com/example"
    }
    options.new_resolve{ | resolver |
      resolver.pkg = "XamplExamplePlay2"
      resolver.namespace="http://xampl.com/example/play"
    }
  }

  elements = Xampl.make(Elements) { | elements |
    elements.pid = "http://xampl.com/example"
    elements.new_element("thing"){ | element |
      element.kind = 'mixed'
      element.indexed_by_attr = 'info'
      element.persisted = true
      element.class_name = "MyKindOfThing"
    }
  }

  generator = Generator.new(options, elements)

  generator.comprehend_from_files(["./xml/example.xml"])
  generator.generate_to_directory("./tmp/")

  require "tmp/XamplExample2"

  thing = XamplExample2::MyKindOfThing.new
  assert(thing.persist_required)
  assert(thing.has_mixed_content)
  assert_equal(:info, thing.indexed_by)

  thing2 = thing.new_thing("two")
  assert(thing2)
end

#test_predefined_element_info_2Object



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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/xamplr/test-support/test-elements.rb', line 63

def test_predefined_element_info_2
  options = Xampl.make(Options) { | options |
    options.new_index_attribute("name")
    options.new_index_attribute("id")
    options.new_index_attribute("pid").persisted = true

    options.new_resolve{ | resolver |
      resolver.pkg = "XamplExample2"
      resolver.namespace="http://xampl.com/example"
    }
    options.new_resolve{ | resolver |
      resolver.pkg = "XamplExamplePlay2"
      resolver.namespace="http://xampl.com/example/play"
    }
  }

  elements = Xampl.make(Elements) { | elements |
    elements.pid = "http://xampl.com/example"
    elements.new_element("thing"){ | element |
      element.kind = 'mixed'
      element.indexed_by_attr = 'info'
      element.persisted = true
      element.class_name = "MyKindOfThing"
      element.attribute_name = "my_thing"
    }
  }

  generator = Generator.new(options, elements)

  generator.comprehend_from_files(["./xml/example.xml"])
  generator.generate_to_directory("./tmp2/")

  require "tmp2/XamplExample2"
  #include XamplExample2

  thing = XamplExample2::MyKindOfThing.new
  assert(thing.persist_required)
  assert(thing.has_mixed_content)
  assert_equal(:info, thing.indexed_by)

  thing2 = thing.new_my_thing("two")
  assert(thing2)
end

#test_registryObject



412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/xamplr/test-support/test.rb', line 412

def test_registry
  assert_equal([ Emph ], FromXML::registered(Emph::ns_tag))
  assert_equal([ Emph ], FromXML::registered(Emph::tag))
  assert_equal([ Stuff ], FromXML::registered(Stuff::ns_tag))
  assert_equal([ Stuff ], FromXML::registered(Stuff::tag))

  FromXML::register(Emph::tag, Emph::ns_tag, Emph)
  assert_equal([ Emph ], FromXML::registered(Emph::ns_tag))
  assert_equal([ Emph ], FromXML::registered(Emph::tag))

  FromXML::register(Emph::tag, Thing::ns_tag, Thing)
  assert_equal([ Emph ], FromXML::registered(Emph::ns_tag))
  assert_equal([ Emph, Thing ], FromXML::registered(Emph::tag))
end

#test_removeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/xamplr/test-support/test-indexed-array.rb', line 39

def test_remove
  ia = IndexedArray.new

  ia["one"] = 1
  ia["two"] = 2
  ia["three"] = 3

  assert_equal(1, ia["one"])
  assert_equal(2, ia["two"])
  assert_equal(3, ia["three"])

  ia.delete_at("one")

  assert_equal(2, ia["two"])
  assert_equal(3, ia["three"])

  assert_equal(2, ia.size)
  assert_equal(2, ia[0])
  assert_equal(3, ia[1])
end

#test_same_namesObject



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
# File 'lib/xamplr/test-support/test-names.rb', line 15

def test_same_names
  options = Xampl.make(Options) { | options |
    options.new_index_attribute("name")
    options.new_resolve{ | resolver |
      resolver.pkg = "XamplExampleNames"
      resolver.namespace="http://xampl.com/example"
    }
  }
  generator = Generator.new(options)
  xml = %Q{
<conflict name="hansel" xmlns='http://xampl.com/example'>
<xname name='blah'>
 <conflict name='nested'/>
	</xname>
<name name='blah'>
 <conflict name='nested'/>
	</name>
</conflict>
}
  generator.comprehend_from_strings([ xml ])
  generator.generate_and_eval() { | module_definition, name |
    eval(module_definition, nil, name, 1)
  }

  parser = FromXML.new
  conflict = parser.parse_string(xml)

  assert(conflict)
  assert_equal("hansel", conflict.name)
  assert_equal("hansel"[0], conflict.name[0])
  assert_equal("blah", conflict.xname_child[0].name)
  assert_equal("blah", conflict.name_child[0].name)
  assert_nil(conflict.name['blah'])
end

#test_simple_extension_persistence_basicsObject

def test_fsdb_extension_persistence_basics

  require 'persister/fsdb'
  stuff = Stuff.new
  thing = Thing.new
  thing << stuff

  thing.pid = "thing"

  assert_xampl_exception(:name_required){
    Xampl.enable_persister(nil, :fsdb)
  }

  pname = "test_fsdb_extension_persistence_basics" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.enable_persister(pname, :fsdb)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  assert_nil(Xampl.lookup(Thing, "thing"))

  assert(nil == thing.persister)
  assert(thing.is_changed)
  assert_equal(0, Xampl.count_changed)

  Xampl.introduce_to_persister(thing)

  assert(thing.persister)
  assert_equal(1, Xampl.count_changed)
  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup new stuff")

  #Xampl.print_stats

  assert_equal(1, Xampl.count_changed)
  writes = Xampl.sync
  assert_equal(1, writes)
  assert_equal(0, Xampl.count_changed)
  assert(Xampl.lookup(Thing, "thing"))

  thing2 = Xampl.lookup(Thing, "thing")
  assert_same(thing, thing2, "cannot lookup cached stuff")

  Xampl.clear_cache

  found = Xampl.lookup(Thing, "thing")
  assert_not_same(thing, found)
  assert(thing === found)

  Xampl.clear_cache

  # now, changing thing will affect the DB -- VERY SUBTLE POSSIBLIITY OF BUG!
  thing.new_stuff
  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  writes = Xampl.sync

  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)

  found2 = Xampl.lookup(Thing, "thing")

  assert_equal(2, thing.stuff.size)
  assert_equal(1, found.stuff.size)
  assert_equal(2, found2.stuff.size)

  assert(!(found === found2))
  assert(thing === found2)

  assert_not_equal(found, found2)

  #Xampl.print_stats
end


1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
# File 'lib/xamplr/test-support/test.rb', line 1445

def test_simple_extension_persistence_basics
  stuff = Stuff.new
  thing = Thing.new
  thing << stuff

  thing.pid = "thing"

  Xampl.enable_persister(nil, :simple)

  stuff = Stuff.new
  thing = Thing.new
  thing.pid = "thing"
  thing << stuff

  assert_nil(Xampl.lookup(Thing, "thing"))

  assert(nil == thing.persister)
  assert(thing.is_changed)
  assert_equal(0, Xampl.count_changed)

  Xampl.introduce_to_persister(thing)

  assert(thing.persister)
  assert_equal(0, Xampl.count_changed)
  assert_same(thing, Xampl.lookup(Thing, "thing"), "cannot lookup new stuff")

  #Xampl.print_stats

  assert_equal(0, Xampl.count_changed)
  writes = Xampl.sync
  assert_equal(0, Xampl.count_changed)
  assert(Xampl.lookup(Thing, "thing"))

  thing2 = Xampl.lookup(Thing, "thing")
  assert_same(thing, thing2, "cannot lookup cached stuff")

  found = Xampl.lookup(Thing, "thing")
  assert_equal(thing.object_id, found.object_id)

  #Xampl.print_stats
end

#test_simple_xamplObject



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
89
# File 'lib/xamplr/test-support/test.rb', line 56

def test_simple_xampl
  emph1 = Emph.new
  assert_not_nil(emph1.is_changed)
  emph2 = Emph.new
  assert_not_nil(emph2.is_changed)
  emph3 = Emph.new
  assert_not_nil(emph3.is_changed)

  emph1.content = "emph 1"
  assert_not_nil(emph1.is_changed)
  emph2.content = "emph 2"
  assert_not_nil(emph2.is_changed)

  assert_equal("emph 1", emph1.content)
  assert_equal("emph 2", emph2.content)

  assert_equal("<ex:emph xmlns:ex='http://xampl.com/example'>emph 1</ex:emph>", emph1.test_to_xml)
  assert_equal("<ex:emph xmlns:ex='http://xampl.com/example'>emph 2</ex:emph>", emph2.test_to_xml)
  assert_equal("<ex:emph xmlns:ex='http://xampl.com/example'/>", emph3.test_to_xml)

  fakeRules = XMLPrinter.new("fake...")
  emph1.test_to_xml_internal(fakeRules)
  r = fakeRules.done

  assert_equal("fake... xmlns:ex='http://xampl.com/example'<ex:emph>emph 1</ex:emph>", r)

  assert_not_nil(emph1.is_changed)
  assert_not_nil(emph2.is_changed)
  assert_not_nil(emph3.is_changed)

  check_parents(emph1)
  check_parents(emph2)
  check_parents(emph3)
end

#test_tokeniseObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xamplr/test-support/test-misc.rb', line 17

def test_tokenise
  assert_equal(nil, FromXML.tokenise_string(nil))
  assert_equal("", FromXML.tokenise_string(""))
  assert_equal("abc", FromXML.tokenise_string("abc"))
  assert_equal("abc def ghi", FromXML.tokenise_string("abc def ghi"))
  assert_equal("a b c", FromXML.tokenise_string("a b c"))
  assert_equal("a b c", FromXML.tokenise_string(" a b c"))
  assert_equal("a b c", FromXML.tokenise_string("a b c "))
  assert_equal("a b c", FromXML.tokenise_string(" a b c "))
  assert_equal("a b c", FromXML.tokenise_string("a    b    c"))
  assert_equal("a b c", FromXML.tokenise_string("a\nb\tc"))
  assert_equal("a b c", FromXML.tokenise_string("a\n\t\n\tb\t\n\t\nc"))
  assert_equal("a b c", FromXML.tokenise_string("\n\n\t\ta\n\t\n\tb\t\n\t\nc\n\n"))
  assert_equal("abc", FromXML.tokenise_string("\n abc"))

  str = "\n\n\t\ta\n\t\n\tb\t\n\t\nc\n\n"
  FromXML.tokenise_string str
  assert_equal("a b c", str)

  #assert_equal(" a b c", FromXML.tokenise_string(" a b c", false))
  #assert_equal(" a b c", FromXML.tokenise_string("    a b c", false))
  #assert_equal(" a b c", FromXML.tokenise_string("\n\n\t    a b c", false))
end

#test_twoObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/xamplr/test-support/test-indexed-array.rb', line 82

def test_two
  a = IndexedArray.new
  b = IndexedArray.new

  a["one"] = 1
  a["two"] = 2
  a["three"] = 3

  #		a.each_pair { | k, v |
  #		  puts "a:: k: #{k}, v: #{v}"
  #		}
  #		a.dump("a")
  #		b.each_pair { | k, v |
  #		  puts "b:: k: #{k}, v: #{v}"
  #		}
  #		b.dump("b")


  b["three"] = 300
  b["two"] = 200
  b["one"] = 100

  assert_equal(1, a["one"])
  assert_equal(2, a["two"])
  assert_equal(3, a["three"])

  assert_equal(1, a[0])
  assert_equal(2, a[1])
  assert_equal(3, a[2])

  assert_equal(300, b["three"])
  assert_equal(200, b["two"])
  assert_equal(100, b["one"])
  assert_equal(300, b[0]) ### returns 100 here
  assert_equal(200, b[1])
  assert_equal(100, b[2])

  #		a.dump("a")
  #		b.dump("b")

end

#test_xml_textObject



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
# File 'lib/xamplr/test-support/test-misc.rb', line 41

def test_xml_text
  xml=%Q{
<unknown a='1'
       b='2'
       xmlns='dummy.ns'
       xmlns:ns='another-dummy.ns'
       xmlns:ns1='never-used.ns'
       xmlns:ns2='used-only-by-attr.ns'>
hello <ns:strong ns2:c='3'
                 ns3:d='4'
                 xmlns:ns3='also-used-only-by-attr.ns'>there</ns:strong>
hello <strong ns2:c='3'
              ns3:d='4'
              xmlns='another-dummy.ns'
              xmlns:ns3='also-used-only-by-attr.ns'>there</strong>
</unknown>
}
  xml_expected=%Q{<unknown a='1' b='2' xmlns:ns='another-dummy.ns' xmlns:ns2='used-only-by-attr.ns' xmlns:ns3='also-used-only-by-attr.ns' xmlns='dummy.ns'>
hello <ns:strong ns2:c='3' ns3:d='4' xmlns='another-dummy.ns'>there</ns:strong>
hello <strong ns2:c='3' ns3:d='4' xmlns='another-dummy.ns'>there</strong>
</unknown>}
  pp = FromXML.new
  pp.setup_parse_string(xml)
  while !pp.startElement?
    pp.nextEvent
  end
  xml_text = XMLText.new
  xml_text.build(pp)

  assert_equal(xml_expected, xml_text.text)
end

#xtest_dummy_fieldarrayObject



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
# File 'lib/xamplr/test-support/test-indexed-array.rb', line 11

def xtest_dummy_fieldarray
  ia = []
  ia.fields = []

  ia << 0 << 1 << 2

  ia["three"] = 3
  ia["four"] = 4
  ia["five"] = 5

  assert_equal(0, ia[0])
  assert_equal(1, ia[1])
  assert_equal(2, ia[2])
  assert_equal(3, ia[3])
  assert_equal(4, ia[4])
  assert_equal(5, ia[5])

  assert_equal(3, ia["three"])
  assert_equal(4, ia["four"])
  assert_equal(5, ia["five"])

  ia["four"] = 44

  assert_equal(44, ia["four"])
  assert_equal(44, ia[4])

end

#xtest_remove_fieldarrayObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/xamplr/test-support/test-indexed-array.rb', line 60

def xtest_remove_fieldarray
  ia = []
  ia.fields = []

  ia["one"] = 1
  ia["two"] = 2
  ia["three"] = 3

  assert_equal(1, ia["one"])
  assert_equal(2, ia["two"])
  assert_equal(3, ia["three"])

  ia.delete_at("one")

  assert_equal(2, ia["two"])
  assert_equal(3, ia["three"])

  assert_equal(2, ia.size)
  assert_equal(2, ia[0])
  assert_equal(3, ia[1])
end

#xtest_two_fieldarrayObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/xamplr/test-support/test-indexed-array.rb', line 124

def xtest_two_fieldarray
  a = []
  a.fields = []

  b = []
  b.fields = []

  a["one"] = 1
  a["two"] = 2
  a["three"] = 3

  #		a.each_pair { | k, v |
  #		  puts "a:: k: #{k}, v: #{v}"
  #		}
  #		a.dump("a")
  #		b.each_pair { | k, v |
  #		  puts "b:: k: #{k}, v: #{v}"
  #		}
  #		b.dump("b")


  b["three"] = 300
  b["two"] = 200
  b["one"] = 100

  assert_equal(1, a["one"])
  assert_equal(2, a["two"])
  assert_equal(3, a["three"])

  assert_equal(1, a[0])
  assert_equal(2, a[1])
  assert_equal(3, a[2])

  assert_equal(300, b["three"])
  assert_equal(200, b["two"])
  assert_equal(100, b["one"])
  assert_equal(300, b[0]) ### returns 100 here
  assert_equal(200, b[1])
  assert_equal(100, b[2])

  #		a.dump("a")
  #		b.dump("b")

end