summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-07-02 14:36:09 +0100
committerwout <wout@impinc.co.uk>2013-07-02 14:36:09 +0100
commitc30c718d904dc35bd99595ab37d5bb8cac796570 (patch)
tree58774563c7cc8393e21774fae98dc730115efca2 /spec
parentf492d5d57790e4f3606a3370b1e676a38a9fd7a9 (diff)
downloadsvg.js-c30c718d904dc35bd99595ab37d5bb8cac796570.tar.gz
svg.js-c30c718d904dc35bd99595ab37d5bb8cac796570.zip
Added memory module
Diffstat (limited to 'spec')
-rw-r--r--spec/index.html1
-rw-r--r--spec/spec/memory.js52
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/index.html b/spec/index.html
index f8332be..7411d9c 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -31,6 +31,7 @@
<script type="text/javascript" src="spec/svg.js"></script>
<script type="text/javascript" src="spec/container.js"></script>
<script type="text/javascript" src="spec/element.js"></script>
+<script type="text/javascript" src="spec/memory.js"></script>
<script type="text/javascript" src="spec/arrange.js"></script>
<script type="text/javascript" src="spec/bbox.js"></script>
<script type="text/javascript" src="spec/rect.js"></script>
diff --git a/spec/spec/memory.js b/spec/spec/memory.js
new file mode 100644
index 0000000..b3a60e0
--- /dev/null
+++ b/spec/spec/memory.js
@@ -0,0 +1,52 @@
+describe('Memory', function () {
+ var rect
+
+ beforeEach(function() {
+ rect = draw.rect(100,120)
+ })
+
+ afterEach(function() {
+ draw.clear()
+ })
+
+ describe('remember()', function() {
+ it('accepts an object with values', function() {
+ rect.remember({ bbox: rect.bbox() })
+ rect.size(200,300)
+ expect(rect.remember('bbox').width).toBe(100)
+ })
+ it('accepts key / value arguments', function() {
+ rect.remember('fill', rect.attr('fill'))
+ rect.fill('#f09')
+ expect(rect.remember('fill')).toBe('#000000')
+ })
+ it('acts as a getter with one string argument', function() {
+ rect.remember('opacity', 0.85)
+ expect(rect.remember('opacity')).toBe(0.85)
+ })
+ })
+
+ describe('forget()', function() {
+ it('deletes a given memory', function() {
+ rect.remember({ grass: 'is green', one: 1 })
+ rect.forget('grass')
+ expect(rect.remember('grass')).toBe(undefined)
+ expect(rect.remember('one')).toBe(1)
+ })
+ it('accepts multiple arguments as different memories', function() {
+ rect.remember({ grass: 'might be purple', two: 2, sea: true })
+ rect.forget('grass', 'sea')
+ expect(rect.remember('grass')).toBe(undefined)
+ expect(rect.remember('sea')).toBe(undefined)
+ expect(rect.remember('two')).toBe(2)
+ })
+ it('clears the whole memory without arguments', function() {
+ rect.remember({ grass: 'is never pink', three: 3, tree: true })
+ rect.forget()
+ expect(rect.remember('grass')).toBe(undefined)
+ expect(rect.remember('tree')).toBe(undefined)
+ expect(rect.remember('three')).toBe(undefined)
+ })
+ })
+
+}) \ No newline at end of file