Blame view

node_modules/renderkid/test/layout/SpecialString.coffee 2.69 KB
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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(' &gt;&lt; &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'