Initial commit

master
Dmitry Baranovskiy 2013-07-05 17:23:52 +10:00
parent da0a61c54f
commit e9a164079f
11 changed files with 10346 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "eve"]
path = eve
url = git://github.com/adobe-webplatform/eve.git

91
demojs.html Normal file

File diff suppressed because one or more lines are too long

302
elemental.js Normal file
View File

@ -0,0 +1,302 @@
/*
* Elemental 0.2.1 - Simple JavaScript Tag Parser
*
* Copyright (c) 2010 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
(function () {
function parse(s) {
s = s || Object(s);
var pos = 1,
len = s.length + 1,
p, c, n = at(s, 0);
for (;pos < len; pos++) {
p = c;
c = n;
n = at(s, pos);
this.raw += c;
step.call(this, c, n, p);
}
this._beforeEnd = function () {
step.call(this, "", "", c);
};
return this;
}
function at(s, i) {
return s && (s.charAt ? s.charAt(i) : s[i]);
}
function on(name, f) {
this.events = this.events || {};
this.events[name] = this.events[name] || [];
this.events[name].push(f);
}
function event(name, data, extra) {
if (typeof eve == "function") {
eve("elemental." + name + "." + data, null, data, extra || "", this.raw);
}
var a = this.events && this.events[name],
i = a && a.length;
while (i--) try {
this.events[name][i](data, extra || "", this.raw);
} catch (e) {}
this.raw = "";
}
function end() {
step.call(this, "eof");
// this._beforeEnd && this._beforeEnd();
// this.raw && this.event("text", this.raw);
// this.mode = "text";
// this.textchunk = "";
// delete this._beforeEnd;
this.event("eof");
}
var whitespace = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]/,
fireAttrEvent = function () {
for (var key in this.attr) if (this.attr.hasOwnProperty(key)) {
this.event("attr", key, {
value: this.attr[key],
tagname: this.tagname,
attr: this.attr
});
}
},
act = {
text: function (c, n, p) {
switch (c) {
case "<":
case "eof":
this.nodename = "";
this.attr = {};
this.mode = "tag name start";
this.raw = this.raw.slice(0, -1);
this.textchunk && this.event("text", this.textchunk);
this.raw += c;
this.textchunk = "";
break;
default:
this.textchunk += c;
break;
}
},
special: function (c, n, p) {
if (p == "!" && c == "-" && n == "-") {
this.mode = "comment start";
return;
}
if (this.textchunk == "[CDATA" && c == "[") {
this.mode = "cdata";
this.textchunk = "";
return;
}
if (c == ">" || c == "eof") {
this.event("special", this.textchunk);
this.mode = "text";
this.textchunk = "";
return;
}
this.textchunk += c;
},
cdata: function (c, n, p) {
if (p == "]" && c == "]" && n == ">") {
this.mode = "cdata end";
this.textchunk = this.textchunk.slice(0, -1);
return;
}
if (c == "eof") {
act["cdata end"].call(this);
}
this.textchunk += c;
},
"cdata end": function (c, n, p) {
this.event("cdata", this.textchunk);
this.textchunk = "";
this.mode = "text";
},
"comment start": function (c, n, p) {
if (n == ">" || c == "eof") {
this.event("comment", "");
this.mode = "comment instant end";
} else {
this.mode = "comment";
}
},
"comment instant end": function (c, n, p) {
this.mode = "text";
},
comment: function (c, n, p) {
if (c == "-" && p == "-" && n == ">") {
this.mode = "comment end";
this.textchunk = this.textchunk.slice(0, -1);
} else if (c == "eof") {
this.event("comment", this.textchunk);
} else {
this.textchunk += c;
}
},
"comment end": function (c, n, p) {
this.event("comment", this.textchunk);
this.textchunk = "";
this.mode = "text";
},
declaration: function (c, n, p) {
if (c == "?" && n == ">") {
this.mode = "declaration end";
return;
}
if (c == "eof") {
this.event("comment", this.textchunk);
}
this.textchunk += c;
},
"declaration end": function (c, n, p) {
this.event("comment", this.textchunk);
this.textchunk = "";
this.mode = "text";
},
"tag name start": function (c, n, p) {
if (c == "eof") {
this.event("text", "<");
return;
}
if (!whitespace.test(c)) {
this.mode = "tag name";
if (c == "/") {
this.mode = "close tag name start";
return;
} else if (c == "!") {
this.mode = "special";
this.textchunk = "";
return;
} else if (c == "?") {
this.mode = "declaration";
return;
}
act[this.mode].call(this, c, n, p);
}
},
"close tag name start": function (c, n, p) {
if (!whitespace.test(c)) {
this.mode = "close tag name";
this.tagname = "";
this.nodename = "";
act[this.mode].call(this, c, n, p);
}
},
"close tag name": function (c, n, p) {
if (whitespace.test(c)) {
this.tagname = this.nodename;
} else switch (c) {
case ">":
this.event("/tag", (this.tagname || this.nodename));
this.mode = "text";
break;
default:
!this.tagname && (this.nodename += c);
break;
}
},
"tag name": function (c, n, p) {
if (whitespace.test(c)) {
this.tagname = this.nodename;
this.nodename = "";
this.mode = "attr start";
} else switch (c) {
case ">":
this.event("tag", this.nodename);
this.mode = "text";
break;
default:
this.nodename += c;
break;
}
},
"attr start": function (c, n, p) {
if (!whitespace.test(c)) {
this.mode = "attr";
this.nodename = "";
act[this.mode].call(this, c, n, p);
}
},
attr: function (c, n, p) {
if (whitespace.test(c) || c == "=") {
this.attr[this.nodename] = "";
this.mode = "attr value start";
} else switch (c) {
case ">":
if (this.nodename == "/") {
delete this.attr["/"];
this.event("tag", this.tagname, this.attr);
fireAttrEvent.call(this);
this.event("/tag", this.tagname, true);
} else {
this.nodename && (this.attr[this.nodename] = "");
this.event("tag", this.tagname, this.attr);
fireAttrEvent.call(this);
}
this.mode = "text";
break;
default:
this.nodename += c;
break;
}
},
"attr value start": function (c, n, p) {
if (!whitespace.test(c)) {
this.mode = "attr value";
this.quote = false;
if (c == "'" || c == '"') {
this.quote = c;
return;
}
act[this.mode].call(this, c, n, p);
}
},
"attr value": function (c, n, p) {
if (whitespace.test(c) && !this.quote) {
this.mode = "attr start";
} else if (c == ">" && !this.quote) {
this.event("tag", this.tagname, this.attr);
this.mode = "text";
} else switch (c) {
case '"':
case "'":
if (this.quote == c && p != "\\") {
this.mode = "attr start";
}
break;
default:
this.attr[this.nodename] += c;
break;
}
}
};
function step(c, n, p) {
c == "\n" && this.event("newline");
act[this.mode].call(this, c, n, p);
}
function elemental(type) {
var out = function (s) {
out.parse(s);
};
out.mode = "text";
out.type = String(type || "html").toLowerCase();
out.textchunk = "";
out.raw = "";
out.parse = parse;
out.on = on;
out.event = event;
out.end = end;
return out;
}
elemental.version = "0.2.1";
(typeof exports == "undefined" ? this : exports).elemental = elemental;
})();

176
mina.js Normal file
View File

@ -0,0 +1,176 @@
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
window.mina = (function () {
var animations = [],
requestAnimFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
setTimeout(callback, 16);
},
diff = function (a, b, A, B) {
var dif = (A - a) / (B - b);
return function (bb) {
return a + dif * (bb - b);
};
},
timer = function () {
return +new Date;
},
frame = function () {
for (var i = 0; i < animations.length; i++) {
var a = animations[i],
gen = a.b + (a.gen() - a.b) * a["*"] + a["+"],
value = a.dif(gen),
one = a.A - a.a;
value = a.a + a.easing((value - a.a) / one) * one;
try {
if (a.stopper(gen)) {
if (--a.iterations) {
a["+"] += a.b - a.B; // -dur
} else {
animations.splice(i--, 1);
a.framer(a.A);
a.callback && a.callback();
}
} else {
a.framer(value);
}
} catch (e) {
console.error(e);
// swallow
}
}
animations.length && requestAnimFrame(frame);
},
setSpeed = function (speed) {
this["*"] = Math.abs(speed);
this.speed = speed;
if (speed < 0) {
var t = this.a;
this.a = this.A;
this.A = t;
this.dif = diff(this.a, this.b, this.A, this.B);
// TODO remove?
this.stopper = stopperEnd(this.b, this.B);
}
},
stopme = function () {
for (var i = 0, ii = animations.length; i < ii; i++) {
if (animations[i] == this) {
animations.splice(i, 1);
return;
}
}
},
queue = function (a, A, b, B, framer, callback, gen, stopper) {
var anim = {
framer: framer,
callback: callback,
dif: diff(a, b, A, B),
easing: mina.linear,
"+": 0,
"*": 1,
gen: gen,
speed: 1,
iterations: 1,
stopper: stopper,
a: a,
b: b,
A: A,
B: B,
setSpeed: setSpeed,
stop: stopme
};
animations.push(anim);
animations.length == 1 && requestAnimFrame(frame);
return anim;
},
stopperEnd = function (a, A) {
return function (value) {
return a < A ? value >= A : value <= A;
};
},
stopperStart = function (a, A) {
return function (value) {
return a < A ? value <= a : value >= a;
};
},
mina = function (a, A, ms, frameHandler, callback) {
var b = timer(),
B = b + ms;
frameHandler(a);
return queue(a, A, b, B, frameHandler, callback, timer, stopperEnd(b, B));
};
mina.linear = function (n) {
return n;
};
mina.easeout = function (n) {
return Math.pow(n, 1.7);
};
mina.easein = function (n) {
return Math.pow(n, .48);
};
mina.easeinout = function (n) {
var q = .48 - n / 1.04,
Q = Math.sqrt(.1734 + q * q),
x = Q - q,
X = Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1),
y = -Q - q,
Y = Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1),
t = X + Y + .5;
return (1 - t) * 3 * t * t + t * t * t;
};
mina.backin = function (n) {
var s = 1.70158;
return n * n * ((s + 1) * n - s);
};
mina.backout = function (n) {
n = n - 1;
var s = 1.70158;
return n * n * ((s + 1) * n + s) + 1;
};
mina.elastic = function (n) {
if (n == !!n) {
return n;
}
return Math.pow(2, -10 * n) * Math.sin((n - .075) * (2 * Math.PI) / .3) + 1;
};
mina.bounce = function (n) {
var s = 7.5625,
p = 2.75,
l;
if (n < (1 / p)) {
l = s * n * n;
} else {
if (n < (2 / p)) {
n -= (1.5 / p);
l = s * n * n + .75;
} else {
if (n < (2.5 / p)) {
n -= (2.25 / p);
l = s * n * n + .9375;
} else {
n -= (2.625 / p);
l = s * n * n + .984375;
}
}
}
return l;
};
return mina;
})();

200
savage.set.js Normal file
View File

@ -0,0 +1,200 @@
(function () {
var mmax = Math.max,
mmin = Math.min,
g = eve("savage.globals")[0];
// Set
var Set = function (items) {
this.items = [];
this.length = 0;
this.type = "set";
if (items) {
for (var i = 0, ii = items.length; i < ii; i++) {
if (items[i]) {
this[this.items.length] = this.items[this.items.length] = items[i];
this.length++;
}
}
}
},
setproto = Set.prototype;
/*\
* Set.push
[ method ]
**
* Adds each argument to the current set.
= (object) original element
\*/
setproto.push = function () {
var item,
len;
for (var i = 0, ii = arguments.length; i < ii; i++) {
item = arguments[i];
if (item) {
len = this.items.length;
this[len] = this.items[len] = item;
this.length++;
}
}
return this;
};
/*\
* Set.pop
[ method ]
**
* Removes last element and returns it.
= (object) element
\*/
setproto.pop = function () {
this.length && delete this[this.length--];
return this.items.pop();
};
/*\
* Set.forEach
[ method ]
**
* Executes given function for each element in the set.
*
* If function returns `false` it will stop loop running.
**
> Parameters
**
- callback (function) function to run
- thisArg (object) context object for the callback
= (object) Set object
\*/
setproto.forEach = function (callback, thisArg) {
for (var i = 0, ii = this.items.length; i < ii; i++) {
if (callback.call(thisArg, this.items[i], i) === false) {
return this;
}
}
return this;
};
setproto.attr = function (name, value) {
for (var i = 0, ii = this.items.length; i < ii; i++) {
this.items[i].attr(name, value);
}
return this;
};
/*\
* Set.clear
[ method ]
**
* Removeds all elements from the set
\*/
setproto.clear = function () {
while (this.length) {
this.pop();
}
};
/*\
* Set.splice
[ method ]
**
* Removes given element from the set
**
> Parameters
**
- index (number) position of the deletion
- count (number) number of element to remove
- insertion (object) #optional elements to insert
= (object) set elements that were deleted
\*/
setproto.splice = function (index, count, insertion) {
index = index < 0 ? mmax(this.length + index, 0) : index;
count = mmax(0, mmin(this.length - index, count));
var tail = [],
todel = [],
args = [],
i;
for (i = 2; i < arguments.length; i++) {
args.push(arguments[i]);
}
for (i = 0; i < count; i++) {
todel.push(this[index + i]);
}
for (; i < this.length - index; i++) {
tail.push(this[index + i]);
}
var arglen = args.length;
for (i = 0; i < arglen + tail.length; i++) {
this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
}
i = this.items.length = this.length -= count - arglen;
while (this[i]) {
delete this[i++];
}
return new Set(todel);
};
/*\
* Set.exclude
[ method ]
**
* Removes given element from the set
**
> Parameters
**
- element (object) element to remove
= (boolean) `true` if object was found & removed from the set
\*/
setproto.exclude = function (el) {
for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
this.splice(i, 1);
return true;
}
};
setproto.insertAfter = function (el) {
var i = this.items.length;
while (i--) {
this.items[i].insertAfter(el);
}
return this;
};
setproto.getBBox = function () {
var x = [],
y = [],
x2 = [],
y2 = [];
for (var i = this.items.length; i--;) if (!this.items[i].removed) {
var box = this.items[i].getBBox();
x.push(box.x);
y.push(box.y);
x2.push(box.x + box.width);
y2.push(box.y + box.height);
}
x = mmin.apply(0, x);
y = mmin.apply(0, y);
x2 = mmax.apply(0, x2);
y2 = mmax.apply(0, y2);
return {
x: x,
y: y,
x2: x2,
y2: y2,
width: x2 - x,
height: y2 - y,
cx: x + (x2 - x) / 2,
cy: y + (y2 - y) / 2
};
};
setproto.clone = function (s) {
s = new Set;
for (var i = 0, ii = this.items.length; i < ii; i++) {
s.push(this.items[i].clone());
}
return s;
};
setproto.toString = function () {
return "Savage\u2018s set";
};
setproto.type = "set";
// export
g.savage.set = function () {
var set = new Set;
if (arguments.length) {
set.push.apply(set, Array.prototype.slice.call(arguments, 0));
}
return set;
};
})();

2439
svg.js Normal file

File diff suppressed because it is too large Load Diff

BIN
test/.DS_Store vendored Normal file

Binary file not shown.

1284
test/expect.js Normal file

File diff suppressed because it is too large Load Diff

251
test/mocha.css Normal file
View File

@ -0,0 +1,251 @@
@charset "utf-8";
body {
margin:0;
}
#mocha {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
#mocha .hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
overflow: hidden;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial, sans-serif;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test pre {
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: 0;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.3;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-error {
color: #c00;
font-size: 1.5em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
z-index: 1;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
#mocha-stats canvas {
width: 40px;
height: 40px;
}
#mocha code .comment { color: #ddd }
#mocha code .init { color: #2F6FAD }
#mocha code .string { color: #5890AD }
#mocha code .keyword { color: #8A6343 }
#mocha code .number { color: #2F6FAD }
@media screen and (max-device-width: 480px) {
#mocha {
margin: 60px 0px;
}
#mocha #stats {
position: absolute;
}
}

5428
test/mocha.js Normal file

File diff suppressed because it is too large Load Diff

172
test/test.html Normal file
View File

@ -0,0 +1,172 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Savage Tests</title>
<link rel="stylesheet" href="mocha.css" />
<script src="../mywork/eve/eve.js"></script>
<script src="mina.js"></script>
<script src="elemental.js"></script>
<script src="svg.js"></script>
<script src="savage.set.js"></script>
</head>
<body>
<div id="mocha"></div>
<script src="expect.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd');</script>
<script>
describe("System check", function () {
it("Savage exists", function () {
expect(Savage).to.be.a("function");
});
it("eve exists", function () {
expect(eve).to.be.a("function");
});
it("mina exists", function () {
expect(mina).to.be.a("function");
});
it("elemental exists", function () {
expect(elemental).to.be.a("function");
});
});
describe("Check for Paper Creation", function () {
it("creates simple paper 20 × 10", function () {
var s = Savage(20, 10);
var S = document.querySelector("svg");
expect(S).to.not.be(null);
expect(S.getAttribute("width")).to.be("20");
expect(S.getAttribute("height")).to.be("10");
s.remove();
});
it("removal of paper", function () {
var s = Savage(20, 10);
var S = document.querySelector("svg");
expect(S).to.not.be(null);
s.remove();
S = document.querySelector("svg");
expect(S).to.be(null);
});
it("creates simple paper 20% × 10em", function () {
var s = Savage("20%", "10em");
var S = document.querySelector("svg");
expect(S).to.not.be(null);
expect(S.getAttribute("width")).to.be("20%");
expect(S.getAttribute("height")).to.be("10em");
s.remove();
});
});
describe("Primitives creation", function () {
var s;
beforeEach(function () {
s = Savage(100, 100);
});
afterEach(function () {
s.remove();
});
it("creates a circle", function () {
var c = s.circle(10, 20, 30);
var C = document.querySelector("circle");
expect(C).to.not.be(null);
expect(C.getAttribute("cx")).to.be("10");
expect(C.getAttribute("cy")).to.be("20");
expect(C.getAttribute("r")).to.be("30");
});
it("creates a rect", function () {
var c = s.rect(10, 20, 30, 40, 5);
var C = document.querySelector("rect");
expect(C).to.not.be(null);
expect(C.getAttribute("x")).to.be("10");
expect(C.getAttribute("y")).to.be("20");
expect(C.getAttribute("width")).to.be("30");
expect(C.getAttribute("height")).to.be("40");
expect(C.getAttribute("rx")).to.be("5");
expect(C.getAttribute("ry")).to.be("5");
});
it("creates a rect with different rx & ry", function () {
var c = s.rect(10, 20, 30, 40, 5, 6);
var C = document.querySelector("rect");
expect(C).to.not.be(null);
expect(C.getAttribute("x")).to.be("10");
expect(C.getAttribute("y")).to.be("20");
expect(C.getAttribute("width")).to.be("30");
expect(C.getAttribute("height")).to.be("40");
expect(C.getAttribute("rx")).to.be("5");
expect(C.getAttribute("ry")).to.be("6");
});
it("creates a ellipse", function () {
var c = s.ellipse(10, 20, 30, 40);
var C = document.querySelector("ellipse");
expect(C).to.not.be(null);
expect(C.getAttribute("cx")).to.be("10");
expect(C.getAttribute("cy")).to.be("20");
expect(C.getAttribute("rx")).to.be("30");
expect(C.getAttribute("ry")).to.be("40");
});
it("creates a ellipse", function () {
var c = s.ellipse(10, 20, 30, 40);
var C = document.querySelector("ellipse");
expect(C).to.not.be(null);
expect(C.getAttribute("cx")).to.be("10");
expect(C.getAttribute("cy")).to.be("20");
expect(C.getAttribute("rx")).to.be("30");
expect(C.getAttribute("ry")).to.be("40");
});
it("creates a path", function () {
var c = s.path("M10,10,50,60");
var C = document.querySelector("path");
expect(C).to.not.be(null);
expect(C.getAttribute("d")).to.be("M10,10,50,60");
expect(C.getBBox().width).to.be(40);
});
it("creates a line", function () {
var c = s.line(10, 10, 50, 60);
var C = document.querySelector("line");
expect(C).to.not.be(null);
expect(C.getAttribute("x1")).to.be("10");
expect(C.getBBox().width).to.be(40);
});
it("creates a polyline", function () {
var c = s.polyline(10, 10, 50, 60, 70, 80);
var C = document.querySelector("polyline");
expect(C).to.not.be(null);
expect(C.getAttribute("points")).to.be("10,10,50,60,70,80");
});
it("creates a polygon", function () {
var c = s.polygon(10, 10, 50, 60, 70, 80);
var C = document.querySelector("polygon");
expect(C).to.not.be(null);
expect(C.getAttribute("points")).to.be("10,10,50,60,70,80");
});
it("creates a group", function () {
var c = s.group();
var C = document.querySelector("g");
expect(C).to.not.be(null);
});
it("creates and fills a group", function () {
var c = s.group(),
a = s.circle(10, 10, 10),
b = s.circle(20, 20, 10),
C = document.querySelector("g");
c.add(a, b);
expect(C).to.not.be(null);
expect(C.children.length).to.be(2);
});
it("creates a text", function () {
var c = s.text(10, 10, "test");
var C = document.querySelector("text");
expect(C).to.not.be(null);
expect(C.getAttribute("x")).to.be("10");
expect(C.textContent).to.be("test");
});
});
</script>
<script>
mocha.checkLeaks();
window.onload = function () {
mocha.run();
};
</script>
</body>
</html>