diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/dom-converter/scripts/coffee/test | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) |
node_modules
Diffstat (limited to 'node_modules/dom-converter/scripts/coffee/test')
4 files changed, 174 insertions, 0 deletions
diff --git a/node_modules/dom-converter/scripts/coffee/test/_prepare.coffee b/node_modules/dom-converter/scripts/coffee/test/_prepare.coffee new file mode 100644 index 000000000..e2b854968 --- /dev/null +++ b/node_modules/dom-converter/scripts/coffee/test/_prepare.coffee @@ -0,0 +1,5 @@ +path = require 'path' + +pathToLib = path.resolve __dirname, '../../js/lib' + +require('little-popo')(pathToLib, no)
\ No newline at end of file diff --git a/node_modules/dom-converter/scripts/coffee/test/domConverter.coffee b/node_modules/dom-converter/scripts/coffee/test/domConverter.coffee new file mode 100644 index 000000000..62d13ad11 --- /dev/null +++ b/node_modules/dom-converter/scripts/coffee/test/domConverter.coffee @@ -0,0 +1,17 @@ +require './_prepare'
+
+domConverter = mod 'domConverter'
+
+describe "input types"
+
+it "should work with objects", ->
+
+ domConverter.objectToDom {}
+
+it "should work with arrays", ->
+
+ domConverter.objectToDom []
+
+it "should not work with other types", ->
+
+ (-> domConverter.objectToDom 'a').should.throw Error
\ No newline at end of file diff --git a/node_modules/dom-converter/scripts/coffee/test/objectToSaneObject.coffee b/node_modules/dom-converter/scripts/coffee/test/objectToSaneObject.coffee new file mode 100644 index 000000000..4673f2c57 --- /dev/null +++ b/node_modules/dom-converter/scripts/coffee/test/objectToSaneObject.coffee @@ -0,0 +1,73 @@ +require './_prepare'
+
+objectToSaneObject = mod 'objectToSaneObject'
+
+describe "sanitize()"
+
+test "case: 'text'", ->
+
+ input = 'text'
+
+ expectation = ['text']
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
+
+test "case: ['text']", ->
+
+ input = ['text']
+
+ expectation = ['text']
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
+
+test "case: {a:b}", ->
+
+ input = a: 'b'
+
+ expectation = [{a: ['b']}]
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
+
+test "case: {a:[b: 'c']}", ->
+
+ input = a: [b: 'c']
+
+ expectation = [{a: [{b: ['c']}]}]
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
+
+test "case: {a:b: 'c'}", ->
+
+ input = a: b: 'c'
+
+ expectation = [{
+ a: [{
+ b: ['c']
+ }]
+ }]
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
+
+test "case: {a:b: ['c', d: 'e']}", ->
+
+ input = a: b: ['c', d: 'e']
+
+ expectation = [{
+ a: [{
+ b: ['c', {d: ['e']}]
+ }]
+ }]
+
+ ret = objectToSaneObject.sanitize input
+
+ ret.should.be.like expectation
\ No newline at end of file diff --git a/node_modules/dom-converter/scripts/coffee/test/saneObjectToDom.coffee b/node_modules/dom-converter/scripts/coffee/test/saneObjectToDom.coffee new file mode 100644 index 000000000..661db8fcf --- /dev/null +++ b/node_modules/dom-converter/scripts/coffee/test/saneObjectToDom.coffee @@ -0,0 +1,79 @@ +require './_prepare'
+
+s2d = mod 'saneObjectToDom'
+
+describe "_arrayToChildren()"
+
+it "should work", ->
+
+ ret = s2d._arrayToChildren [
+
+ {
+ a: 'text'
+ }
+ {
+ 'b.someClass': ['b1', 'b2']
+ }
+ {
+ c: [
+
+ {d: 'text'}
+ {e: []}
+
+ ]
+ }
+
+ ]
+
+ ret.should.be.an 'array'
+ ret.should.have.length.of 3
+
+ for node in ret
+
+ node.should.be.an 'object'
+ node.should.have
+ .keys ['type', 'name', 'attribs', 'children', 'next', 'prev', 'parent']
+
+ a = ret[0]
+
+ a.children.should.be.an 'array'
+ a.children.should.have.length.of 1
+
+ aChild = a.children[0]
+ aChild.should.be.an 'object'
+ aChild.should.be.like {type: 'text', data: 'text'}
+
+ expect(a.prev).to.equal null
+ expect(a.parent).to.equal null
+
+ b = ret[1]
+
+ a.next.should.equal b
+ b.prev.should.equal a
+ b.attribs.should.be.like
+
+ class: 'someClass'
+
+ bChildren = b.children
+
+ bChildren[0].should.be.like {type: 'text', data: 'b1'}
+ bChildren[1].should.be.like {type: 'text', data: 'b2'}
+
+ ret.should.have.deep.property '[2].children[1].name', 'e'
+
+
+describe "_parseTag"
+
+it "should work", ->
+
+ s2d.
+ _parseTag('tagName#id.c1.c2[a=b, d="1 2 3"]')
+ .should.be.like
+
+ name: 'tagName'
+
+ attribs:
+
+ id: 'id'
+
+ class: 'c1 c2'
|