2014-12-13 18:24:54 +03:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Mocha Tests</title>
|
|
|
|
<link rel="stylesheet" href="lib/mocha.css" />
|
|
|
|
<script type="text/javascript" src="../../src/color.js"></script>
|
|
|
|
<script src="lib/expect.js"></script>
|
|
|
|
<script src="lib/mocha.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="mocha"></div>
|
|
|
|
<script>mocha.setup('bdd')</script>
|
|
|
|
<script>
|
|
|
|
describe("Colors", function() {
|
|
|
|
describe("named colors", function() {
|
|
|
|
it("bisque", function () {
|
|
|
|
var c = new Color("bisque");
|
|
|
|
assertColor(c, 255, 228, 196, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("BLUE", function () {
|
|
|
|
var c = new Color("BLUE");
|
|
|
|
assertColor(c, 0, 0, 255, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("rgb()", function() {
|
|
|
|
it("rgb(1,3,5)", function () {
|
|
|
|
var c = new Color("rgb(1,3,5)");
|
|
|
|
assertColor(c, 1, 3, 5, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("rgb(222, 111, 50)", function () {
|
|
|
|
var c = new Color("rgb(222, 111, 50)");
|
|
|
|
assertColor(c, 222, 111, 50, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("rgb( 222, 111 , 50)", function () {
|
|
|
|
var c = new Color("rgb(222 , 111 , 50)");
|
|
|
|
assertColor(c, 222, 111, 50, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("rgba()", function() {
|
2014-12-13 19:10:41 +03:00
|
|
|
it("rgba(200,3,5,1)", function () {
|
|
|
|
var c = new Color("rgba(200,3,5,1)");
|
|
|
|
assertColor(c, 200, 3, 5, 1);
|
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("rgba(222, 111, 50, 0.22)", function () {
|
|
|
|
var c = new Color("rgba(222, 111, 50, 0.22)");
|
|
|
|
assertColor(c, 222, 111, 50, 0.22);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("rgba( 222, 111 , 50, 0.123 )", function () {
|
|
|
|
var c = new Color("rgba(222 , 111 , 50, 0.123)");
|
|
|
|
assertColor(c, 222, 111, 50, 0.123);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("hex", function() {
|
|
|
|
it("#7FFFD4", function () {
|
|
|
|
var c = new Color("#7FFFD4");
|
|
|
|
assertColor(c, 127, 255, 212, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("#f0ffff", function () {
|
|
|
|
var c = new Color("#f0ffff");
|
|
|
|
assertColor(c, 240, 255, 255, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("#fff", function () {
|
|
|
|
var c = new Color("#fff");
|
|
|
|
assertColor(c, 255, 255, 255, null);
|
2014-12-13 19:10:41 +03:00
|
|
|
expect(c.isTransparent()).to.equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-13 19:30:52 +03:00
|
|
|
describe("from array", function() {
|
|
|
|
it("[1,2,3]", function () {
|
|
|
|
var c = new Color([1,2,3]);
|
|
|
|
assertColor(c, 1, 2, 3, null);
|
|
|
|
expect(c.isTransparent()).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("[5,6,7,1]", function () {
|
|
|
|
var c = new Color([5,6,7, 1]);
|
|
|
|
assertColor(c, 5, 6, 7, 1);
|
|
|
|
expect(c.isTransparent()).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("[5,6,7,0]", function () {
|
|
|
|
var c = new Color([5,6,7, 0]);
|
|
|
|
assertColor(c, 5, 6, 7, 0);
|
|
|
|
expect(c.isTransparent()).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-13 19:10:41 +03:00
|
|
|
describe("transparency", function() {
|
|
|
|
it("transparent", function () {
|
|
|
|
var c = new Color("transparent");
|
|
|
|
assertColor(c, 0, 0, 0, 0);
|
|
|
|
expect(c.isTransparent()).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rgba(255,255,255,0)", function () {
|
|
|
|
var c = new Color("rgba(255,255,255,0)");
|
|
|
|
assertColor(c, 255, 255, 255, 0);
|
|
|
|
expect(c.isTransparent()).to.equal(true);
|
2014-12-13 18:24:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function assertColor(c, r, g, b, a) {
|
|
|
|
expect(c.r).to.equal(r);
|
|
|
|
expect(c.g).to.equal(g);
|
|
|
|
expect(c.b).to.equal(b);
|
|
|
|
expect(c.a).to.equal(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
mocha.checkLeaks();
|
|
|
|
mocha.globals(['jQuery']);
|
|
|
|
if (window.mochaPhantomJS) {
|
|
|
|
mochaPhantomJS.run();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mocha.run();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|