web/test/jstests/utils.js
author Julien Cristau <julien.cristau@logilab.fr>
Sun, 22 Mar 2015 19:10:13 +0100
changeset 10447 d309c020d9fb
parent 8879 982a49239420
permissions -rw-r--r--
[schema] neuter check method for constraints we implement in sql Closes #5154406.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
function datetuple(d) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
    return [d.getFullYear(), d.getMonth()+1, d.getDate(),
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
	    d.getHours(), d.getMinutes()];
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
function pprint(obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
    print('{');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    for(k in obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
	print('  ' + k + ' = ' + obj[k]);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    print('}');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
function arrayrepr(array) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    return '[' + array.join(', ') + ']';
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
function assertArrayEquals(array1, array2) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
    if (array1.length != array2.length) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
	throw new crosscheck.AssertionFailure(array1.join(', ') + ' != ' + array2.join(', '));
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
    for (var i=0; i<array1.length; i++) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
	if (array1[i] != array2[i]) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
	    throw new crosscheck.AssertionFailure(arrayrepr(array1) + ' and ' + arrayrepr(array2)
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
						 + ' differs at index ' + i);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
	}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
}