liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
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
describe 'key-list', ->
  afterEach -> delete @subject.open
  afterEach -> delete @subject.close
  Given -> @subject = require '../lib/key-list'
 
  context 'default pattern', ->
    Given -> @str = 'some test to be {{ interpolated }} where the interpolation may or may not have {{spaces}}'
    When -> @list = @subject.getKeys @str
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'mustache', ->
    Given -> @str = 'some test to be {{ interpolated }} where the interpolation may or may not have {{spaces}}'
    When -> @list = @subject.getKeys @str, 'mustache'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'thin-mustache', ->
    Given -> @str = 'some test to be { interpolated } where the interpolation may or may not have {spaces}'
    When -> @list = @subject.getKeys @str, 'thin-mustache'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'glasses', ->
    Given -> @str = 'some test to be {% interpolated %} where the interpolation may or may not have {%spaces%}'
    When -> @list = @subject.getKeys @str, 'glasses'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'perl', ->
    Given -> @str = 'some test to be [% interpolated %] where the interpolation may or may not have [%spaces%]'
    When -> @list = @subject.getKeys @str, 'perl'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'ejs', ->
    Given -> @str = 'some test to be <%= interpolated %> where the interpolation may or may not have <%=spaces%>'
    When -> @list = @subject.getKeys @str, 'ejs'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'coffee', ->
    Given -> @str = 'some test to be #{ interpolated } where the interpolation may or may not have #{spaces}'
    When -> @list = @subject.getKeys @str, 'coffee'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'es6', ->
    Given -> @str = 'some test to be ${ interpolated } where the interpolation may or may not have ${spaces}'
    When -> @list = @subject.getKeys @str, 'es6'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'razor', ->
    Given -> @str = 'some test to be @interpolated where the interpolation does not have @spaces'
    When -> @list = @subject.getKeys @str, 'razor'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'express', ->
    Given -> @str = 'some test to be :interpolated where the interpolation does not have :spaces'
    When -> @list = @subject.getKeys @str, 'express'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'custom string pattern', ->
    Given -> @str = 'some test to be @| interpolated | where the interpolation does not have @|spaces|'
    When -> @list = @subject.getKeys @str, '@\\|\\s*([a-zA-Z0-9_\\$]+)\\s*\\|'
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'custom regex pattern', ->
    Given -> @str = 'some test to be @| interpolated | where the interpolation does not have @|spaces|'
    When -> @list = @subject.getKeys @str, /@\|\s*([a-zA-Z0-9_\$]+)\s*\|/g
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'with open and close', ->
    Given -> @str = 'some test to be @| interpolated | where the interpolation does not have @|spaces|'
    Given -> @subject.open = '@\\|\\s*'
    Given -> @subject.close = '\\s*\\|'
    When -> @list = @subject.getKeys @str
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'with open but not close', ->
    Given -> @str = 'some test to be {{ interpolated }} where the interpolation does not have {{spaces}}'
    Given -> @subject.open = '@\\|\\s*'
    When -> @list = @subject.getKeys @str
    Then -> expect(@list).to.deep.equal ['interpolated', 'spaces']
 
  context 'with nested keys', ->
    Given -> @str = 'some test to be {{ interpo.lated }} where the interpolation may or may not have {{spaces}}'
    When -> @list = @subject.getKeys @str
    Then -> expect(@list).to.deep.equal ['interpo.lated', 'spaces']