summaryrefslogtreecommitdiff
path: root/includes/js/dojox/collections/tests/_base.js
blob: f58a82c9c42ab5ea3f255766cc1a8cc9b0fec0be (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
if(!dojo._hasResource["dojox.collections.tests._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.collections.tests._base"] = true;
dojo.provide("dojox.collections.tests._base");
dojo.require("dojox.collections");

tests.register("dojox.collections.tests._base", [
	function testDictionaryEntry(t){
		var d=new dojox.collections.DictionaryEntry("foo","bar");
		t.assertEqual("bar", d.valueOf());
		t.assertEqual("bar", d.toString());
	},

	function testIterator(t){
		var itr=new dojox.collections.Iterator(["foo","bar","baz","zoo"]);
		t.assertEqual("foo", itr.element);	//	test initialization
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo", itr.get());	//	make sure the first get doesn't advance.
		t.assertEqual("bar", itr.get());
		t.assertEqual("baz", itr.get());
		t.assertEqual("zoo", itr.get());
		t.assertTrue(itr.atEnd());
		t.assertEqual(null, itr.get());

		itr.reset();
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo", itr.element);

		//	test map
		var a=itr.map(function(elm){
			return elm+"-mapped";
		});
		itr=new dojox.collections.Iterator(a);
		t.assertEqual("foo-mapped", itr.element);	//	test initialization
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo-mapped", itr.get());	//	make sure the first get doesn't advance.
		t.assertEqual("bar-mapped", itr.get());
		t.assertEqual("baz-mapped", itr.get());
		t.assertEqual("zoo-mapped", itr.get());
		t.assertTrue(itr.atEnd());
		t.assertEqual(null, itr.get());
	},

	function testDictionaryIterator(t){
		/*
			in the context of any of the Dictionary-based collections, the
			element would normally return a DictionaryEntry.  However, since
			the DictionaryIterator is really an iterator of pure objects,
			we will just test with an object here.  This means all property
			names are lost in the translation, but...that's why there's a
			DictionaryEntry object :)
		*/
		var itr=new dojox.collections.DictionaryIterator({
			first:"foo", second:"bar", third:"baz", fourth:"zoo"
		});
		t.assertEqual("foo", itr.element);	//	test initialization
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo", itr.get());	//	make sure the first get doesn't advance.
		t.assertEqual("bar", itr.get());
		t.assertEqual("baz", itr.get());
		t.assertEqual("zoo", itr.get());
		t.assertTrue(itr.atEnd());
		t.assertEqual(null, itr.get());

		itr.reset();
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo", itr.element);

		//	test map
		var a=itr.map(function(elm){
			return elm+"-mapped";
		});
		itr=new dojox.collections.Iterator(a);
		t.assertEqual("foo-mapped", itr.element);	//	test initialization
		t.assertTrue(!itr.atEnd());
		t.assertEqual("foo-mapped", itr.get());	//	make sure the first get doesn't advance.
		t.assertEqual("bar-mapped", itr.get());
		t.assertEqual("baz-mapped", itr.get());
		t.assertEqual("zoo-mapped", itr.get());
		t.assertTrue(itr.atEnd());
		t.assertEqual(null, itr.get());
	}
]);

}