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/renderkid/test | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) |
node_modules
Diffstat (limited to 'node_modules/renderkid/test')
-rw-r--r-- | node_modules/renderkid/test/AnsiPainter.coffee | 22 | ||||
-rw-r--r-- | node_modules/renderkid/test/Layout.coffee | 16 | ||||
-rw-r--r-- | node_modules/renderkid/test/RenderKid.coffee | 273 | ||||
-rw-r--r-- | node_modules/renderkid/test/layout/Block.coffee | 312 | ||||
-rw-r--r-- | node_modules/renderkid/test/layout/SpecialString.coffee | 82 | ||||
-rw-r--r-- | node_modules/renderkid/test/mocha.opts | 6 | ||||
-rw-r--r-- | node_modules/renderkid/test/mochaHelpers.coffee | 10 | ||||
-rw-r--r-- | node_modules/renderkid/test/renderKid/styles/StyleSheet.coffee | 7 | ||||
-rw-r--r-- | node_modules/renderkid/test/tools.coffee | 19 |
9 files changed, 747 insertions, 0 deletions
diff --git a/node_modules/renderkid/test/AnsiPainter.coffee b/node_modules/renderkid/test/AnsiPainter.coffee new file mode 100644 index 000000000..a33898675 --- /dev/null +++ b/node_modules/renderkid/test/AnsiPainter.coffee @@ -0,0 +1,22 @@ +AnsiPainter = require '../src/AnsiPainter' + +paint = (t) -> + AnsiPainter.paint(t) + +describe "AnsiPainter", -> + describe "paint()", -> + it "should handle basic coloring", -> + t = "<bg-white><black>a</black></bg-white>" + paint(t).should.equal '\u001b[30m\u001b[47ma\u001b[0m' + + it "should handle color in color", -> + t = "<red>a<blue>b</blue></red>" + paint(t).should.equal '\u001b[31ma\u001b[0m\u001b[34mb\u001b[0m' + + it "should skip empty tags", -> + t = "<blue></blue>a" + paint(t).should.equal 'a\u001b[0m' + + describe "_replaceSpecialStrings()", -> + it "should work", -> + AnsiPainter::_replaceSpecialStrings('<>"&sp;&').should.equal '<>" &'
\ No newline at end of file diff --git a/node_modules/renderkid/test/Layout.coffee b/node_modules/renderkid/test/Layout.coffee new file mode 100644 index 000000000..845502609 --- /dev/null +++ b/node_modules/renderkid/test/Layout.coffee @@ -0,0 +1,16 @@ +Layout = require '../src/Layout' + +describe "Layout", -> + describe "constructor()", -> + it "should create root block", -> + l = new Layout + expect(l._root).to.exist + l._root._name.should.equal '__root' + + describe "get()", -> + it "should not be allowed when any block is open", -> + l = new Layout + l.openBlock() + (-> + l.get() + ).should.throw Error
\ No newline at end of file diff --git a/node_modules/renderkid/test/RenderKid.coffee b/node_modules/renderkid/test/RenderKid.coffee new file mode 100644 index 000000000..3ca4852f5 --- /dev/null +++ b/node_modules/renderkid/test/RenderKid.coffee @@ -0,0 +1,273 @@ +RenderKid = require '../src/RenderKid' +{strip} = require '../src/AnsiPainter' + +match = (input, expected, setStuff) -> + r = new RenderKid + r.style + span: + display: 'inline' + div: + display: 'block' + + setStuff?(r) + strip(r.render(input)).trim().should.equal expected.trim() + +describe "RenderKid", -> + describe "constructor()", -> + it "should work", -> + new RenderKid + + describe "whitespace management - inline", -> + it "shouldn't put extra whitespaces", -> + input = """ + + a<span>b</span>c + + """ + + expected = """ + + abc + + """ + + match input, expected + + it "should allow 1 whitespace character on each side", -> + input = """ + + a<span> b </span>c + + """ + + expected = """ + + a b c + + """ + + match input, expected + + it "should eliminate extra whitespaces inside text", -> + input = """ + + a<span>b1 \n b2</span>c + + """ + + expected = """ + + ab1 b2c + + """ + + match input, expected + + it "should allow line breaks with <br />", -> + input = """ + + a<span>b1<br />b2</span>c + + """ + + expected = """ + + ab1\nb2c + + """ + + match input, expected + + it "should allow line breaks with &nl;", -> + input = """ + + a<span>b1&nl;b2</span>c + + """ + + expected = """ + + ab1\nb2c + + """ + + match input, expected + + it "should allow whitespaces with &sp;", -> + input = """ + + a<span>b1&sp;b2</span>c + + """ + + expected = """ + + ab1 b2c + + """ + + match input, expected + + describe "whitespace management - block", -> + it "should add one linebreak between two blocks", -> + input = """ + + <div>a</div> + <div>b</div> + + """ + + expected = """ + + a + b + + """ + + match input, expected + + it "should ignore empty blocks", -> + input = """ + + <div>a</div> + <div></div> + <div>b</div> + + """ + + expected = """ + + a + b + + """ + + match input, expected + + it "should add an extra linebreak between two adjacent blocks inside an inline", -> + input = """ + + <span> + <div>a</div> + <div>b</div> + </span> + + """ + + expected = """ + + a + + b + + """ + + match input, expected + + it "example: div(marginBottom:1)+div", -> + input = """ + + <div class="first">a</div> + <div>b</div> + + """ + + expected = """ + + a + + b + + """ + + match input, expected, (r) -> + r.style '.first': marginBottom: 1 + + it "example: div+div(marginTop:1)", -> + input = """ + + <div>a</div> + <div class="second">b</div> + + """ + + expected = """ + + a + + b + + """ + + match input, expected, (r) -> + r.style '.second': marginTop: 1 + + it "example: div(marginBottom:1)+div(marginTop:1)", -> + input = """ + + <div class="first">a</div> + <div class="second">b</div> + + """ + + expected = """ + + a + + + b + + """ + + match input, expected, (r) -> + r.style + '.first': marginBottom: 1 + '.second': marginTop: 1 + + it "example: div(marginBottom:2)+div(marginTop:1)", -> + input = """ + + <div class="first">a</div> + <div class="second">b</div> + + """ + + expected = """ + + a + + + + b + + """ + + match input, expected, (r) -> + r.style + '.first': marginBottom: 2 + '.second': marginTop: 1 + + it "example: div(marginBottom:2)+span+div(marginTop:1)", -> + input = """ + + <div class="first">a</div> + <span>span</span> + <div class="second">b</div> + + """ + + expected = """ + + a + + + span + + b + + """ + + match input, expected, (r) -> + r.style + '.first': marginBottom: 2 + '.second': marginTop: 1
\ No newline at end of file diff --git a/node_modules/renderkid/test/layout/Block.coffee b/node_modules/renderkid/test/layout/Block.coffee new file mode 100644 index 000000000..e5b5ebe38 --- /dev/null +++ b/node_modules/renderkid/test/layout/Block.coffee @@ -0,0 +1,312 @@ +Layout = require '../../src/Layout' +{object} = require 'utila' + +{open, get, conf} = do -> + show = (layout) -> + got = layout.get() + got = got.replace /<[^>]+>/g, '' + + defaultBlockConfig = + linePrependor: options: amount: 2 + + c = (add = {}) -> + object.append defaultBlockConfig, add + + ret = {} + + ret.open = (block, name, top = 0, bottom = 0) -> + config = c + blockPrependor: options: amount: top + blockAppendor: options: amount: bottom + + b = block.openBlock config, name + b.write name + ' | top ' + top + ' bottom ' + bottom + b + + ret.get = (layout) -> + layout.get().replace(/<[^>]+>/g, '') + + ret.conf = (props) -> + config = {} + if props.left? + object.appendOnto config, linePrependor: options: amount: props.left + + if props.right? + object.appendOnto config, lineAppendor: options: amount: props.right + + if props.top? + object.appendOnto config, blockPrependor: options: amount: props.top + + if props.bottom? + object.appendOnto config, blockAppendor: options: amount: props.bottom + + if props.width? + object.appendOnto config, width: props.width + + if props.bullet is yes + object.appendOnto config, linePrependor: options: bullet: {char: '-', alignment: 'left'} + + config + + ret + + +describe "Layout", -> + describe "inline inputs", -> + it "should be merged", -> + l = new Layout + + l.write 'a' + l.write 'b' + + get(l).should.equal 'ab' + + it "should be correctly wrapped", -> + l = new Layout + block = l.openBlock conf width: 20 + block.write '123456789012345678901234567890' + block.close() + get(l).should.equal '12345678901234567890\n1234567890' + + it "should trim from left when wrapping to a new line", -> + l = new Layout + block = l.openBlock conf width: 20 + block.write '12345678901234567890 \t 123456789012345678901' + block.close() + get(l).should.equal '12345678901234567890\n12345678901234567890\n1' + + it "should handle line breaks correctly", -> + l = new Layout + block = l.openBlock conf width: 20 + block.write '\na\n\nb\n' + block.close() + get(l).should.equal '\na\n\nb\n' + + it "should not put extra line breaks when a line is already broken", -> + l = new Layout + block = l.openBlock conf width: 20 + block.write '01234567890123456789\n0123456789' + block.close() + get(l).should.equal '01234567890123456789\n0123456789' + + describe "horizontal margins", -> + it "should account for left margins", -> + l = new Layout + block = l.openBlock conf width: 20, left: 2 + block.write '01' + block.close() + get(l).should.equal ' 01' + + it "should account for right margins", -> + l = new Layout + block = l.openBlock conf width: 20, right: 2 + block.write '01' + block.close() + get(l).should.equal '01 ' + + it "should account for both margins", -> + l = new Layout + block = l.openBlock conf width: 20, right: 2, left: 1 + block.write '01' + block.close() + get(l).should.equal ' 01 ' + + it "should break lines according to left margins", -> + l = new Layout + global.tick = yes + block = l.openBlock conf width: 20, left: 2 + block.write '01234567890123456789' + block.close() + global.tick = no + get(l).should.equal ' 01234567890123456789' + + it "should break lines according to right margins", -> + l = new Layout + block = l.openBlock conf width: 20, right: 2 + block.write '01234567890123456789' + block.close() + get(l).should.equal '01234567890123456789 ' + + it "should break lines according to both margins", -> + l = new Layout + block = l.openBlock conf width: 20, right: 2, left: 1 + block.write '01234567890123456789' + block.close() + get(l).should.equal ' 01234567890123456789 ' + + it "should break lines according to terminal width", -> + l = new Layout terminalWidth: 20 + block = l.openBlock conf right: 2, left: 1 + block.write '01234567890123456789' + block.close() + + # Note: We don't expect ' 01234567890123456 \n 789 ', + # since the first line (' 01234567890123456 ') is a full line + # according to layout.config.terminalWidth and doesn't need + # a break line. + get(l).should.equal ' 01234567890123456 789 ' + + describe "lines and blocks", -> + it "should put one break line between: line, block", -> + l = new Layout + l.write 'a' + l.openBlock().write('b').close() + get(l).should.equal 'a\nb' + + it "should put one break line between: block, line", -> + l = new Layout + l.openBlock().write('a').close() + l.write 'b' + get(l).should.equal 'a\nb' + + it "should put one break line between: line, block, line", -> + l = new Layout + l.write 'a' + l.openBlock().write('b').close() + l.write 'c' + get(l).should.equal 'a\nb\nc' + + it "margin top should work for: line, block", -> + l = new Layout + l.write 'a' + l.openBlock(conf top: 2).write('b').close() + get(l).should.equal 'a\n\n\nb' + + it "margin top should work for: block, line", -> + l = new Layout + l.openBlock(conf top: 1).write('a').close() + l.write 'b' + get(l).should.equal '\na\nb' + + it "margin top should work for: block, line, when block starts with a break", -> + l = new Layout + l.openBlock(conf top: 1).write('\na').close() + l.write 'b' + get(l).should.equal '\n\na\nb' + + it "margin top should work for: line, block, when line ends with a break", -> + l = new Layout + l.write 'a\n' + l.openBlock(conf top: 1).write('b').close() + get(l).should.equal 'a\n\n\nb' + + it "margin top should work for: line, block, when there are two breaks in between", -> + l = new Layout + l.write 'a\n' + l.openBlock(conf top: 1).write('\nb').close() + get(l).should.equal 'a\n\n\n\nb' + + it "margin bottom should work for: line, block", -> + l = new Layout + l.write 'a' + l.openBlock(conf bottom: 1).write('b').close() + get(l).should.equal 'a\nb\n' + + it "margin bottom should work for: block, line", -> + l = new Layout + l.openBlock(conf bottom: 1).write('a').close() + l.write 'b' + get(l).should.equal 'a\n\nb' + + it "margin bottom should work for: block, line, when block ends with a break", -> + l = new Layout + l.openBlock(conf bottom: 1).write('a\n').close() + l.write 'b' + get(l).should.equal 'a\n\n\nb' + + it "margin bottom should work for: block, line, when line starts with a break", -> + l = new Layout + l.openBlock(conf bottom: 1).write('a').close() + l.write '\nb' + get(l).should.equal 'a\n\n\nb' + + it "margin bottom should work for: block, line, when there are two breaks in between", -> + l = new Layout + l.openBlock(conf bottom: 1).write('a\n').close() + l.write '\nb' + get(l).should.equal 'a\n\n\n\nb' + + describe "blocks and blocks", -> + it "should not get extra break lines for full-width lines", -> + l = new Layout + l.openBlock(conf width: 20).write('01234567890123456789').close() + l.openBlock().write('b').close() + get(l).should.equal '01234567890123456789\nb' + + it "should not get extra break lines for full-width lines followed by a margin", -> + l = new Layout + l.openBlock(conf width: 20, bottom: 1).write('01234567890123456789').close() + l.openBlock().write('b').close() + get(l).should.equal '01234567890123456789\n\nb' + + it "a(top: 0, bottom: 0) b(top: 0, bottom: 0)", -> + l = new Layout + l.openBlock().write('a').close() + l.openBlock().write('b').close() + get(l).should.equal 'a\nb' + + it "a(top: 0, bottom: 0) b(top: 1, bottom: 0)", -> + l = new Layout + l.openBlock().write('a').close() + l.openBlock(conf(top: 1)).write('b').close() + get(l).should.equal 'a\n\nb' + + it "a(top: 0, bottom: 1) b(top: 0, bottom: 0)", -> + l = new Layout + l.openBlock(conf(bottom: 1)).write('a').close() + l.openBlock().write('b').close() + get(l).should.equal 'a\n\nb' + + it "a(top: 0, bottom: 1 ) b( top: 1, bottom: 0)", -> + l = new Layout + l.openBlock(conf(bottom: 1)).write('a').close() + l.openBlock(conf(top: 1)).write('b').close() + get(l).should.equal 'a\n\n\nb' + + it "a(top: 0, bottom: 1 br) b(br top: 1, bottom: 0)", -> + l = new Layout + l.openBlock(conf(bottom: 1)).write('a\n').close() + l.openBlock(conf(top: 1)).write('\nb').close() + get(l).should.equal 'a\n\n\n\n\nb' + + it "a(top: 2, bottom: 3 a1-br-a2) b(br-b1-br-br-b2-br top: 2, bottom: 3)", -> + l = new Layout + l.openBlock(conf(top: 2, bottom: 3)).write('a1\na2').close() + l.openBlock(conf(top: 2, bottom: 3)).write('\nb1\n\nb2\n').close() + get(l).should.equal '\n\na1\na2\n\n\n\n\n\n\nb1\n\nb2\n\n\n\n' + + describe "nesting", -> + it "should break one line for nested blocks", -> + l = new Layout + l.write 'a' + b = l.openBlock() + c = b.openBlock().write('c').close() + b.close() + get(l).should.equal 'a\nc' + + it "a(left: 2) > b(top: 2)", -> + l = new Layout + a = l.openBlock(conf(left: 2)) + a.openBlock(conf(top: 2)).write('b').close() + a.close() + get(l).should.equal ' \n \n b' + + it "a(left: 2) > b(bottom: 2)", -> + l = new Layout + a = l.openBlock(conf(left: 2)) + a.openBlock(conf(bottom: 2)).write('b').close() + a.close() + get(l).should.equal ' b\n \n ' + + describe "bullets", -> + it "basic bullet", -> + l = new Layout + l.openBlock(conf(left: 3, bullet: yes)).write('a').close() + get(l).should.equal '- a' + + it "a(left: 3, bullet) > b(top:1)", -> + l = new Layout + a = l.openBlock(conf(left: 3, bullet: yes)) + b = a.openBlock(conf(top: 1)).write('b').close() + a.close() + get(l).should.equal '- \n b'
\ No newline at end of file diff --git a/node_modules/renderkid/test/layout/SpecialString.coffee b/node_modules/renderkid/test/layout/SpecialString.coffee new file mode 100644 index 000000000..acc166fbd --- /dev/null +++ b/node_modules/renderkid/test/layout/SpecialString.coffee @@ -0,0 +1,82 @@ +S = require '../../src/layout/SpecialString' + +describe "SpecialString", -> + describe 'SpecialString()', -> + it 'should return instance', -> + S('s').should.be.instanceOf S + + describe 'length()', -> + it 'should return correct length for normal text', -> + S('hello').length.should.equal 5 + + it 'should return correct length for text containing tabs and tags', -> + S('<a>he<you />l\tlo</a>').length.should.equal 13 + + it "shouldn't count empty tags as tags", -> + S('<>><').length.should.equal 4 + + it "should count length of single tag as 0", -> + S('<html>').length.should.equal 0 + + it "should work correctly with html quoted characters", -> + S(' >< &sp;').length.should.equal 5 + + describe 'splitIn()', -> + it "should work correctly with normal text", -> + S("123456").splitIn(3).should.be.like ['123', '456'] + + it "should work correctly with normal text containing tabs and tags", -> + S("12\t3<hello>456").splitIn(3).should.be.like ['12', '\t', '3<hello>45', '6'] + + it "should not trimLeft all lines when trimLeft is no", -> + S('abc def').splitIn(3).should.be.like ['abc', ' de', 'f'] + + it "should trimLeft all lines when trimLeft is true", -> + S('abc def').splitIn(3, yes).should.be.like ['abc', 'def'] + + describe 'cut()', -> + it "should work correctly with text containing tabs and tags", -> + original = S("12\t3<hello>456") + cut = original.cut(2, 3) + original.str.should.equal '123<hello>456' + cut.str.should.equal '\t' + + it "should trim left when trimLeft is true", -> + original = S ' 132' + cut = original.cut 0, 1, yes + original.str.should.equal '32' + cut.str.should.equal '1' + + it "should be greedy", -> + S("ab<tag>a").cut(0, 2).str.should.equal "ab<tag>" + + describe 'isOnlySpecialChars()', -> + it "should work", -> + S("12\t3<hello>456").isOnlySpecialChars().should.equal no + S("<hello>").isOnlySpecialChars().should.equal yes + + describe 'clone()', -> + it "should return independent instance", -> + a = S('hello') + b = a.clone() + a.str.should.equal b.str + a.should.not.equal b + + describe 'trim()', -> + it "should return an independent instance", -> + s = S('') + s.trim().should.not.equal s + + it 'should return the same string when trim is not required', -> + S('hello').trim().str.should.equal 'hello' + + it 'should return trimmed string', -> + S(' hello').trim().str.should.equal 'hello' + + describe 'trimLeft()', -> + it "should only trim on the left", -> + S(' hello ').trimLeft().str.should.equal 'hello ' + + describe 'trimRight()', -> + it "should only trim on the right", -> + S(' hello ').trimRight().str.should.equal ' hello'
\ No newline at end of file diff --git a/node_modules/renderkid/test/mocha.opts b/node_modules/renderkid/test/mocha.opts new file mode 100644 index 000000000..0b4468244 --- /dev/null +++ b/node_modules/renderkid/test/mocha.opts @@ -0,0 +1,6 @@ +--compilers coffee:coffee-script/register +--recursive +--reporter mocha-pretty-spec-reporter +--ui bdd +--timeout 20000 +--require ./test/mochaHelpers.coffee
\ No newline at end of file diff --git a/node_modules/renderkid/test/mochaHelpers.coffee b/node_modules/renderkid/test/mochaHelpers.coffee new file mode 100644 index 000000000..1e388d33d --- /dev/null +++ b/node_modules/renderkid/test/mochaHelpers.coffee @@ -0,0 +1,10 @@ +chai = require('chai') + +chai +.use(require 'chai-fuzzy') +.use(require 'chai-changes') +.use(require 'sinon-chai') +.should() + +global.expect = chai.expect +global.sinon = require 'sinon'
\ No newline at end of file diff --git a/node_modules/renderkid/test/renderKid/styles/StyleSheet.coffee b/node_modules/renderkid/test/renderKid/styles/StyleSheet.coffee new file mode 100644 index 000000000..d0764c2d1 --- /dev/null +++ b/node_modules/renderkid/test/renderKid/styles/StyleSheet.coffee @@ -0,0 +1,7 @@ +StyleSheet = require '../../../src/renderKid/styles/StyleSheet' + +describe "StyleSheet", -> + describe "normalizeSelector()", -> + it 'should remove unnecessary spaces', -> + StyleSheet.normalizeSelector(' body+a s > a ') + .should.equal 'body+a s>a'
\ No newline at end of file diff --git a/node_modules/renderkid/test/tools.coffee b/node_modules/renderkid/test/tools.coffee new file mode 100644 index 000000000..143d9c5c6 --- /dev/null +++ b/node_modules/renderkid/test/tools.coffee @@ -0,0 +1,19 @@ +tools = require '../src/tools' + +describe "tools", -> + describe "quote()", -> + it "should convert html special strings to their entities", -> + tools.quote(" abc<>\"\n") + .should.equal '&sp;abc<>"<br />' + + describe "stringToDom()", -> + it "should work", -> + tools.stringToDom('<a> text<a1>text</a1> text <a2>text</a2><a3>text</a3>text</a>text') + + describe "objectToDom()", -> + it "should work", -> + tools.objectToDom({a: 'text'}) + + it "should have quoted text nodes", -> + tools.objectToDom({a: '&<> "'}).should.have.deep + .property '[0].children[0].data', '&<>&sp;"'
\ No newline at end of file |