-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathcomparison.islike.js
More file actions
82 lines (64 loc) · 2.24 KB
/
comparison.islike.js
File metadata and controls
82 lines (64 loc) · 2.24 KB
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
$(document).ready(function() {
module("underscore.comparison.islike");
test("string islike string", function() {
ok(_.islike("hello, world", ""));
});
test("number islike number", function() {
ok(_.islike(32.4, 0));
});
test("boolean islike boolean", function() {
ok(_.islike(true, true));
});
test("string is not like number", function() {
equal(_.islike("hello", 0), false);
});
test("boolean is not like number", function() {
equal(_.islike(false, 0), false);
});
test("array is like array", function() {
ok(_.islike([1,2,3], []));
});
test("number array is typed like array", function() {
ok(_.islike([1,2,3], [0]));
});
test("string array is typed like array", function() {
ok(_.islike(["hello", "world"], [""]));
});
test("string array is not typed like number array", function() {
equal(_.islike(["hello", "world"], [0]), false);
});
test("object is like object", function() {
ok(_.islike(
{name: "James", age: 10, hobbies: ["football", "computer games", "baking"]},
{name: "", age: 0, hobbies: [""]}
));
});
test("object is not like object", function() {
equal(_.islike(
{name: "James", age: 10, hobbies: ["football", "computer games", "baking"]},
{name: "", age: 0, hometown: "", hobbies: [""]}
), false);
});
test("object is like type", function() {
var Type = function(){};
ok(_.islike(new Type, Type));
});
test("function is like Function", function() {
ok(_.islike(function(){}, Function));
});
test("function is not like function", function() {
equal(_.islike(function(){}, function(){}), false);
});
test("object with functions is like object", function() {
ok(_.islike(
{name: "James", age: 10, hobbies: ["football", "computer games", "baking"], done: function() { console.log("done");} },
{name: "", age: 0, hobbies: [""], done: Function}
));
});
test("object with functions is not like object", function() {
equal(_.islike(
{name: "James", age: 10, hobbies: ["football", "computer games", "baking"], done: true},
{name: "", age: 0, hobbies: [""], done: Function}
), false);
});
});