summaryrefslogtreecommitdiffstats
path: root/kjsembed/tests/test_arrays.js
blob: 4f505d8a048572142a80fc2ed1f034c0d2f60685 (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
#!/usr/bin/env kjscmd

var empty = [];
var map1 = [];

var array = ["Test A", "Test B", "Test C", "Test D"];
var map2 = {"Test 1":"Test Map A", "Test 2":"Test Map B","Test 3":"Test Map C","Test 4":"Test Map D"};

map1["Test 1"] = "Test Map A";
map1["Test 2"] = "Test Map B";
map2.length = 1;
empty.length = 3;

list = ["Test A"];
list[3] = "Test B";
list[5] = "Test C";
list[7] = "Test D";

println( "Sparse value 2:" + list[2] );
try {
	println( "Array: " + array.length );
	println( "Array max value: " + array[array.length - 1] );
} catch(x) { println( "Error: " + x); }

try {
	println( "Map1: " + map1.length );
	println( "Map1 max value: " + map1[map1.length - 1] );
} catch(x) { println( "Error: " + x); }

try {
	println( "Map2: " + map2.length );
	println( "Map2 max value: " + map2[map2.length - 1] );
} catch(x) { println( "Error: " + x); }

try {
	println( "List: " + list.length );
	println( "List max value: " + list[list.length - 1] );
} catch(x) { println( "Error: " + x); }

try {
	println( "Empty: " + empty.length );
	println( "Empty max value: " + empty[empty.length - 1] );
} catch(x) { println( "Error: " + x); }

System.KJSConfig.writeListEntry("Test Array", array );
System.KJSConfig.writeListEntry("Test Map1", map1 );
System.KJSConfig.writeListEntry("Test Map2", map2 );
System.KJSConfig.writeListEntry("Test List", list );
System.KJSConfig.writeListEntry("Test Empty", empty );