@@ -4,16 +4,16 @@ import assert from "power-assert"
4
4
import { parse } from "markdown-to-ast" ;
5
5
import StringSource from "../src/StringSource" ;
6
6
import { split as sentenceSplitter } from "sentence-splitter" ;
7
- describe ( "StringSource" , function ( ) {
8
- describe ( "#toString" , function ( ) {
9
- it ( "should concat string" , function ( ) {
7
+ describe ( "StringSource" , function ( ) {
8
+ describe ( "#toString" , function ( ) {
9
+ it ( "should concat string" , function ( ) {
10
10
let AST = parse ( "**str**" ) ;
11
11
let source = new StringSource ( AST ) ;
12
12
assert . equal ( source + "!!" , "str!!" ) ;
13
13
} ) ;
14
14
} ) ;
15
- context ( "Each Pattern" , function ( ) {
16
- it ( "should return relative position of the node" , function ( ) {
15
+ context ( "Each Pattern" , function ( ) {
16
+ it ( "should return relative position of the node" , function ( ) {
17
17
let AST = parse ( `1st P
18
18
19
19
**2nd** P` ) ;
@@ -45,7 +45,7 @@ describe("StringSource", function () {
45
45
value : " P"
46
46
} ) ;
47
47
} ) ;
48
- it ( "Str" , function ( ) {
48
+ it ( "Str" , function ( ) {
49
49
let AST = parse ( "**str**" ) ;
50
50
let source = new StringSource ( AST ) ;
51
51
let result = source . toString ( ) ;
@@ -59,7 +59,7 @@ describe("StringSource", function () {
59
59
value : "str"
60
60
} ) ;
61
61
} ) ;
62
- it ( "Str that contain break line" , function ( ) {
62
+ it ( "Str that contain break line" , function ( ) {
63
63
let AST = parse ( "**st\nr**" ) ;
64
64
let source = new StringSource ( AST ) ;
65
65
let result = source . toString ( ) ;
@@ -73,7 +73,7 @@ describe("StringSource", function () {
73
73
value : "st\nr"
74
74
} ) ;
75
75
} ) ;
76
- it ( "Link" , function ( ) {
76
+ it ( "Link" , function ( ) {
77
77
let AST = parse ( "_[link](http://example)" ) ;
78
78
let source = new StringSource ( AST ) ;
79
79
let result = source . toString ( ) ;
@@ -94,7 +94,7 @@ describe("StringSource", function () {
94
94
value : "link"
95
95
} ) ;
96
96
} ) ;
97
- it ( "Str + `Code` + Str" , function ( ) {
97
+ it ( "Str + `Code` + Str" , function ( ) {
98
98
let AST = parse ( "text`code`text" ) ;
99
99
let source = new StringSource ( AST ) ;
100
100
let result = source . toString ( ) ;
@@ -119,7 +119,7 @@ describe("StringSource", function () {
119
119
value : "text"
120
120
} ) ;
121
121
} ) ;
122
- it ( "Header" , function ( ) {
122
+ it ( "Header" , function ( ) {
123
123
let AST = parse ( "# Header" ) ;
124
124
let source = new StringSource ( AST ) ;
125
125
let result = source . toString ( ) ;
@@ -132,7 +132,7 @@ describe("StringSource", function () {
132
132
value : "Header"
133
133
} ) ;
134
134
} ) ;
135
- it ( "Image + Str" , function ( ) {
135
+ it ( "Image + Str" , function ( ) {
136
136
let AST = parse ( " text" ) ;
137
137
let source = new StringSource ( AST ) ;
138
138
let result = source . toString ( ) ;
@@ -151,7 +151,7 @@ describe("StringSource", function () {
151
151
value : " text"
152
152
} ) ;
153
153
} ) ;
154
- it ( "confuse pattern" , function ( ) {
154
+ it ( "confuse pattern" , function ( ) {
155
155
let AST = parse ( "" ) ;
156
156
let source = new StringSource ( AST ) ;
157
157
let result = source . toString ( ) ;
@@ -164,7 +164,7 @@ describe("StringSource", function () {
164
164
value : "!"
165
165
} ) ;
166
166
} ) ;
167
- it ( "Empty" , function ( ) {
167
+ it ( "Empty" , function ( ) {
168
168
let AST = parse ( "" ) ;
169
169
let source = new StringSource ( AST ) ;
170
170
let result = source . toString ( ) ;
@@ -173,8 +173,8 @@ describe("StringSource", function () {
173
173
} ) ;
174
174
} ) ;
175
175
176
- describe ( "#originalIndexFromIndex" , function ( ) {
177
- it ( "Str + Link" , function ( ) {
176
+ describe ( "#originalIndexFromIndex" , function ( ) {
177
+ it ( "Str + Link" , function ( ) {
178
178
var originalText = "This is [Example!?](http://example.com/)" ;
179
179
let AST = parse ( originalText ) ;
180
180
let source = new StringSource ( AST ) ;
@@ -187,7 +187,7 @@ describe("StringSource", function () {
187
187
assert . equal ( index2 , 15 ) ;
188
188
assert . equal ( source . originalIndexFromIndex ( index2 ) , 16 ) ;
189
189
} ) ;
190
- it ( "should return original position for index" , function ( ) {
190
+ it ( "should return original position for index" , function ( ) {
191
191
var originalText = " text" ;
192
192
let AST = parse ( originalText ) ;
193
193
let source = new StringSource ( AST ) ;
@@ -198,15 +198,27 @@ describe("StringSource", function () {
198
198
assert . deepEqual ( source . originalIndexFromIndex ( indexOf ) , 27 ) ;
199
199
assert . equal ( originalText . slice ( 27 ) , "text" ) ;
200
200
} ) ;
201
- it ( "should return null when not found position for index" , function ( ) {
201
+ it ( "should return original position for index - end match" , function ( ) {
202
+ var originalText = " text" ;
203
+ let AST = parse ( originalText ) ;
204
+ let source = new StringSource ( AST ) ;
205
+ let result = source . toString ( ) ;
206
+ const indexOf = result . indexOf ( "text" ) ;
207
+ assert . equal ( indexOf , 4 ) ;
208
+ assert . equal ( indexOf + ( "text" . length - 1 ) , 7 ) ;
209
+ assert . equal ( originalText [ 30 ] , "t" ) ;
210
+ assert . equal ( source . originalIndexFromIndex ( indexOf + ( "text" . length - 1 ) ) , 30 ) ;
211
+ assert . equal ( originalText [ source . originalIndexFromIndex ( indexOf + ( "text" . length - 1 ) ) ] , "t" ) ;
212
+ } ) ;
213
+ it ( "should return null when not found position for index" , function ( ) {
202
214
var originalText = " text" ;
203
215
let AST = parse ( originalText ) ;
204
216
let source = new StringSource ( AST ) ;
205
217
let result = source . toString ( ) ;
206
218
assert . equal ( result , "alt text" ) ;
207
219
assert . equal ( source . originalIndexFromIndex ( 1000 ) , null ) ;
208
220
} ) ;
209
- it ( "should return null when -1" , function ( ) {
221
+ it ( "should return null when -1" , function ( ) {
210
222
var originalText = " text" ;
211
223
let AST = parse ( originalText ) ;
212
224
let source = new StringSource ( AST ) ;
@@ -215,8 +227,8 @@ describe("StringSource", function () {
215
227
assert . equal ( source . originalIndexFromIndex ( - 1 ) , null ) ;
216
228
} ) ;
217
229
} ) ;
218
- describe ( "#originalPositionFromPosition" , function ( ) {
219
- it ( "Str + Link" , function ( ) {
230
+ describe ( "#originalPositionFromPosition" , function ( ) {
231
+ it ( "Str + Link" , function ( ) {
220
232
var originalText = "This is [Example!?](http://example.com/)" ;
221
233
let AST = parse ( originalText ) ;
222
234
let source = new StringSource ( AST ) ;
@@ -237,7 +249,7 @@ describe("StringSource", function () {
237
249
column : 16
238
250
} ) ;
239
251
} ) ;
240
- it ( "should return original position for index" , function ( ) {
252
+ it ( "should return original position for index" , function ( ) {
241
253
var originalText = "First\n text" ;
242
254
let AST = parse ( originalText ) ;
243
255
let source = new StringSource ( AST ) ;
@@ -254,7 +266,7 @@ describe("StringSource", function () {
254
266
column : 27
255
267
} ) ;
256
268
} ) ;
257
- it ( "should return null when not found position for index" , function ( ) {
269
+ it ( "should return null when not found position for index" , function ( ) {
258
270
var originalText = " text" ;
259
271
let AST = parse ( originalText ) ;
260
272
let source = new StringSource ( AST ) ;
@@ -265,17 +277,17 @@ describe("StringSource", function () {
265
277
column : - 1
266
278
} ) , null ) ;
267
279
} ) ;
268
- it ( "should throw error when position is not object" , function ( ) {
280
+ it ( "should throw error when position is not object" , function ( ) {
269
281
var originalText = " text" ;
270
282
let AST = parse ( originalText ) ;
271
283
let source = new StringSource ( AST ) ;
272
284
let result = source . toString ( ) ;
273
285
assert . equal ( result , "alt text" ) ;
274
- assert . throws ( function ( ) {
286
+ assert . throws ( function ( ) {
275
287
source . originalPositionFromPosition ( ) ;
276
288
} ) ;
277
289
} ) ;
278
- it ( "with sentenceSplitter" , function ( ) {
290
+ it ( "with sentenceSplitter" , function ( ) {
279
291
var originalText = "`1`st.\n" +
280
292
"``2`nd.`\n" +
281
293
"`3`rd Text." ;
@@ -307,5 +319,5 @@ describe("StringSource", function () {
307
319
} ) ;
308
320
} ) ;
309
321
} ) ;
310
-
322
+
311
323
} ) ;
0 commit comments