-
Notifications
You must be signed in to change notification settings - Fork 535
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
cfb41d5
commit f09221d
Showing
4 changed files
with
141 additions
and
1 deletion.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
<meta charset="UTF-8" /> | |||
<title>Aloha Editor Lang Utils Test Suite</title> | |||
|
|||
<!-- include qunit --> | |||
<link rel="stylesheet" href="../vendor/qunit.css" type="text/css"/> | |||
<script type="text/javascript" src="../vendor/qunit.js"></script> | |||
<script src="../vendor/jquery-1.6.1.js" ></script> | |||
|
|||
<script> | |||
var Aloha = { jQuery: $ }; | |||
</script> | |||
<script src="../../lib/aloha.js"></script> | |||
|
|||
<!-- include testswarm inject script --> | |||
<script> | |||
var url = window.location.search; | |||
url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); | |||
if ( url && url.indexOf("http") === 0 ) { | |||
require(["http://testswarm.aloha-editor.org/js/inject.js?" + (new Date).getTime()], function() {}); | |||
} | |||
</script> | |||
|
|||
</head> | |||
<body> | |||
<!-- include the tests --> | |||
<script> | |||
require( ['lang-tests'] ); | |||
</script> | |||
<h1 id="qunit-header">Aloha Editor Lang Utils Test Suite</h1> | |||
<h2 id="qunit-banner"></h2> | |||
<div id="qunit-testrunner-toolbar"></div> | |||
<h2 id="qunit-userAgent"></h2> | |||
<ol id="qunit-tests"></ol> | |||
<div id="qunit-fixture"> | |||
<div id="test-editable"></div> | |||
</div> | |||
</body> | |||
</html> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
/*! | |||
* This file is part of Aloha Editor | |||
* Author & Copyright (c) 2010 Gentics Software GmbH, aloha@gentics.com | |||
* Licensed unter the terms of http://www.aloha-editor.com/license.html | |||
*/ | |||
|
|||
define( | |||
[], | |||
function( ) { | |||
"use strict"; | |||
|
|||
Aloha.ready( function() { | |||
var Lang = Aloha.require( "util/lang" ); | |||
var $ = Aloha.require( "aloha/jquery" ); | |||
|
|||
module('sortUnique'); | |||
|
|||
test('loose compare', function() { | |||
var unique = Lang.sortUnique( [ 6, 3, 6, 3, "6", 3, "9", 9, 3, 2, 1 ] ); | |||
// Either numeric or string values for "6" and "9" may be chosen | |||
for ( var i = 0; i < unique.length; i++ ) { | |||
unique[ i ] = parseInt( unique[ i ] ); | |||
} | |||
deepEqual( unique, [ 1, 2, 3, 6, 9 ] ); | |||
}); | |||
|
|||
test('strict comparison', function() { | |||
var unique = Lang.sortUnique( [ 6, 3, "6", 3, 6, 3, "9", 9, 3, 2, 1 ], function(a,b){ | |||
return typeof a < typeof b ? -1 | |||
: ( typeof a > typeof b ? 1 | |||
: ( a < b ? -1 : ( a > b ? 1 : 0 ))); | |||
}); | |||
deepEqual( unique, [ 1, 2, 3, 6, 9, "6", "9" ] ); | |||
}); | |||
|
|||
test('comparator', function() { | |||
var unique = Lang.sortUnique( [ 7, 6, 9, 6, 9, 8 ], function( a, b ) { | |||
// Pretend 6 and 9 is equal | |||
if ( a === 9 ) { | |||
a = 6; | |||
} | |||
if ( b === 9 ) { | |||
b = 6; | |||
} | |||
return a < b ? -1 : ( a === b ? 0 : +1 ); | |||
}); | |||
deepEqual( unique, [ 6, 7, 8 ] ); | |||
}); | |||
}); | |||
}); |