@@ -67,50 +67,69 @@ describe('paraphrase', () => {
67
67
} ) ;
68
68
} ) ;
69
69
70
- describe ( 'Resolve nested data' , ( ) => {
71
- const phrase = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g) ;
72
- const phraseNoResolve = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g, { resolve : false } ) ;
73
-
74
- it ( 'resolves dot notation' , ( ) => {
75
- const string = 'Hello, ${name.first} ${name.last}' ;
76
- const data = {
77
- name : {
78
- first : 'Martin' ,
79
- last : 'Prince' ,
80
- } ,
81
- } ;
82
-
83
- expect ( phrase ( string , data ) ) . to . equal ( 'Hello, Martin Prince' ) ;
84
- } ) ;
70
+ describe ( 'options' , ( ) => {
71
+ describe ( 'resolve nested data' , ( ) => {
72
+ const phrase = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g) ;
73
+ const phraseNoResolve = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g, { resolve : false } ) ;
74
+
75
+ it ( 'resolves dot notation' , ( ) => {
76
+ const string = 'Hello, ${name.first} ${name.last}' ;
77
+ const data = {
78
+ name : {
79
+ first : 'Martin' ,
80
+ last : 'Prince' ,
81
+ } ,
82
+ } ;
83
+
84
+ expect ( phrase ( string , data ) ) . to . equal ( 'Hello, Martin Prince' ) ;
85
+ } ) ;
85
86
86
- it ( 'resolves arrays' , ( ) => {
87
- const string = 'Hello, ${0} ${1}' ;
88
- const name = [
89
- 'Martin' ,
90
- 'Prince' ,
91
- ] ;
87
+ it ( 'resolves arrays' , ( ) => {
88
+ const string = 'Hello, ${0} ${1}' ;
89
+ const name = [
90
+ 'Martin' ,
91
+ 'Prince' ,
92
+ ] ;
92
93
93
- expect ( phrase ( string , name ) ) . to . equal ( 'Hello, Martin Prince' ) ;
94
- } ) ;
94
+ expect ( phrase ( string , name ) ) . to . equal ( 'Hello, Martin Prince' ) ;
95
+ } ) ;
95
96
96
- it ( 'misses keys with dots' , ( ) => {
97
- const string = 'Hello, ${name.first} ${name.last}' ;
98
- const data = {
99
- 'name.first' : 'Martin' ,
100
- 'name.last' : 'Prince' ,
101
- } ;
97
+ it ( 'misses keys with dots' , ( ) => {
98
+ const string = 'Hello, ${name.first} ${name.last}' ;
99
+ const data = {
100
+ 'name.first' : 'Martin' ,
101
+ 'name.last' : 'Prince' ,
102
+ } ;
102
103
103
- expect ( phrase ( string , data ) ) . to . equal ( 'Hello, ${name.first} ${name.last}' ) ;
104
+ expect ( phrase ( string , data ) ) . to . equal ( 'Hello, ${name.first} ${name.last}' ) ;
105
+ } ) ;
106
+
107
+ it ( 'does not resolve dot notation (explicit)' , ( ) => {
108
+ const string = 'Hello, ${name.first} ${name.last}' ;
109
+ const data = {
110
+ 'name.first' : 'Martin' ,
111
+ 'name.last' : 'Prince' ,
112
+ } ;
113
+
114
+ expect ( phraseNoResolve ( string , data ) ) . to . equal ( 'Hello, Martin Prince' ) ;
115
+ } ) ;
104
116
} ) ;
105
117
106
- it ( 'does not resolve dot notation (explicit)' , ( ) => {
107
- const string = 'Hello, ${name.first} ${name.last}' ;
108
- const data = {
109
- 'name.first' : 'Martin' ,
110
- 'name.last' : 'Prince' ,
111
- } ;
118
+ describe ( 'clean parsing' , ( ) => {
119
+ it ( 'Should leave unmatched template combinations' , ( ) => {
120
+ const parser = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g, { clean : false } ) ;
121
+ const string = 'Hello, ${name.first} ${name.last}' ;
122
+ const data = { } ;
112
123
113
- expect ( phraseNoResolve ( string , data ) ) . to . equal ( 'Hello, Martin Prince' ) ;
124
+ expect ( parser ( string , data ) ) . to . equal ( 'Hello, ${name.first} ${name.last}' ) ;
125
+ } ) ;
126
+ it ( 'Should remove unmatched template combinations' , ( ) => {
127
+ const parser = paraphrase ( / \$ { ( [ ^ { } ] * ) } / g, { clean : true } ) ;
128
+ const string = 'Hello, ${name.first} ${name.last}' ;
129
+ const data = { } ;
130
+
131
+ expect ( parser ( string , data ) ) . to . equal ( 'Hello, ' ) ;
132
+ } ) ;
114
133
} ) ;
115
134
} ) ;
116
135
0 commit comments