Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5c6988
commit 7650f70
Showing
5 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var contains_same_elements = { | ||
index_of: function (element, list) { | ||
var i; | ||
for(i = 0; i < list.length; i++) { | ||
if(element instanceof Array) { | ||
if((list[i] instanceof Array) && this.list_equal(list[i], element)) { | ||
return i; | ||
} | ||
} | ||
else if(Screw.Matchers.equal.match(element, list[i])) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}, | ||
remove: function (list, index) { | ||
list[index] = list[list.length - 1]; | ||
list.pop(); | ||
}, | ||
list_equal: function (list1, list2) { | ||
var copy_list2 = list2.slice(0, list2.length); | ||
var i; | ||
for(i = 0; i < list1.length; i++) { | ||
var list1_item = list1[i]; | ||
var index_on_list2 = this.index_of(list1_item, copy_list2) | ||
if(index_on_list2 == -1) { | ||
return false; | ||
} | ||
this.remove(copy_list2, index_on_list2); | ||
} | ||
return copy_list2.length == 0; | ||
}, | ||
match: | ||
function(expected, actual) { | ||
if(expected.length != actual.length) { | ||
return false; | ||
} | ||
return this.list_equal(expected, actual); | ||
}, | ||
failure_message: | ||
function (expected, actual, not) { | ||
return "expected " + $.print(actual) + (not ? ' to not contain ' : ' to contain ') + $.print(expected);; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
Screw.Unit(function() { | ||
describe("Collection Matcher", function() { | ||
it("should match empty collections", function() { | ||
expect([]).to(contains_same_elements, []); | ||
}); | ||
it("should match collections of primitives in any order", function() { | ||
expect([1,2,3,"hi","pokemon"]).to(contains_same_elements, ["pokemon", 3, 1, 2, "hi"]); | ||
}); | ||
it("should not match collections of different size", function() { | ||
expect([1,2,3,4,5,6]).to_not(contains_same_elements, [1,2,3]); | ||
expect([1,2,3]).to_not(contains_same_elements, [1,2,3,4,5,6]); | ||
}); | ||
it("should match collections with repetitions", function() { | ||
expect([1,2,3,3,3,3]).to(contains_same_elements, [3,1,3,2,3,3]); | ||
expect([1,2,3,3,3,3]).to_not(contains_same_elements, [3,1,3,2]); | ||
expect([1,2,3,3,3,3]).to_not(contains_same_elements, [3,1,1,1,2,1]); | ||
}); | ||
it("should match collections in any order of collections in any order", function() { | ||
expect([[1,2],3,4,[5]]).to(contains_same_elements, [[5], 4, 3, [2,1]]); | ||
expect([[1,2],3,4,[5]]).to_not(contains_same_elements, [5,4,3,2,1]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<script src="../lib/jquery-1.2.6.js"></script> | ||
<script src="../lib/jquery.fn.js"></script> | ||
<script src="../lib/jquery.print.js"></script> | ||
<script src="../lib/screw.builder.js"></script> | ||
<script src="../lib/screw.matchers.js"></script> | ||
<script src="../lib/screw.events.js"></script> | ||
<script src="../lib/screw.behaviors.js"></script> | ||
<script src="../lib/smoke.core.js"></script> | ||
<script src="../lib/smoke.mock.js"></script> | ||
<script src="../lib/smoke.stub.js"></script> | ||
|
||
<script src="matchers.js"></script> | ||
<script src="matchersSpec.js"></script> | ||
|
||
<link rel="stylesheet" href="../lib/screw.css"> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |