From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- .../renderkid/test/layout/SpecialString.coffee | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 node_modules/renderkid/test/layout/SpecialString.coffee (limited to 'node_modules/renderkid/test/layout/SpecialString.coffee') diff --git a/node_modules/renderkid/test/layout/SpecialString.coffee b/node_modules/renderkid/test/layout/SpecialString.coffee new file mode 100644 index 00000000..acc166fb --- /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('hel\tlo').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('').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\t3456").splitIn(3).should.be.like ['12', '\t', '345', '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\t3456") + cut = original.cut(2, 3) + original.str.should.equal '123456' + 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("aba").cut(0, 2).str.should.equal "ab" + + describe 'isOnlySpecialChars()', -> + it "should work", -> + S("12\t3456").isOnlySpecialChars().should.equal no + S("").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 -- cgit v1.2.3