11import assert from "power-assert" ;
22import { Syntax , split as splitSentences } from "../src/sentence-splitter" ;
3- describe ( "sentence-utils" , function ( ) {
4- it ( "should return array" , function ( ) {
3+ describe ( "sentence-utils" , function ( ) {
4+ it ( "should return array" , function ( ) {
55 let sentences = splitSentences ( "text" ) ;
66 assert . equal ( sentences . length , 1 ) ;
77 let sentence = sentences [ 0 ] ;
@@ -10,7 +10,7 @@ describe("sentence-utils", function () {
1010 assert . deepEqual ( sentences [ 0 ] . loc . start , { line : 1 , column : 0 } ) ;
1111 assert . deepEqual ( sentences [ 0 ] . loc . end , { line : 1 , column : 4 } ) ;
1212 } ) ;
13- it ( "should return sentences split by first line break" , function ( ) {
13+ it ( "should return sentences split by first line break" , function ( ) {
1414 let sentences = splitSentences ( "\ntext" ) ;
1515 assert . equal ( sentences . length , 2 ) ;
1616 var whiteSpace0 = sentences [ 0 ] ;
@@ -24,7 +24,7 @@ describe("sentence-utils", function () {
2424 assert . deepEqual ( sentence1 . loc . start , { line : 2 , column : 0 } ) ;
2525 assert . deepEqual ( sentence1 . loc . end , { line : 2 , column : 4 } ) ;
2626 } ) ;
27- it ( "should return sentences split by last line break" , function ( ) {
27+ it ( "should return sentences split by last line break" , function ( ) {
2828 let sentences = splitSentences ( "text\n" ) ;
2929 assert . equal ( sentences . length , 2 ) ;
3030 var sentence0 = sentences [ 0 ] ;
@@ -38,7 +38,7 @@ describe("sentence-utils", function () {
3838 assert . deepEqual ( whiteSpace1 . loc . start , { line : 1 , column : 4 } ) ;
3939 assert . deepEqual ( whiteSpace1 . loc . end , { line : 2 , column : 0 } ) ;
4040 } ) ;
41- it ( "should return sentences split by line break*2" , function ( ) {
41+ it ( "should return sentences split by line break*2" , function ( ) {
4242 let sentences = splitSentences ( "text\n\ntext" ) ;
4343 assert . equal ( sentences . length , 4 ) ;
4444 var sentence0 = sentences [ 0 ] ;
@@ -63,7 +63,7 @@ describe("sentence-utils", function () {
6363 assert . deepEqual ( sentence3 . loc . end , { line : 3 , column : 4 } ) ;
6464
6565 } ) ;
66- it ( "should return sentences split by 。" , function ( ) {
66+ it ( "should return sentences split by 。" , function ( ) {
6767 let sentences = splitSentences ( "text。。text" ) ;
6868 assert . equal ( sentences . length , 2 ) ;
6969 var sentence0 = sentences [ 0 ] ;
@@ -75,7 +75,7 @@ describe("sentence-utils", function () {
7575 assert . deepEqual ( sentence1 . loc . start , { line : 1 , column : 6 } ) ;
7676 assert . deepEqual ( sentence1 . loc . end , { line : 1 , column : 10 } ) ;
7777 } ) ;
78- it ( "should return sentences split by 。 and linebreak" , function ( ) {
78+ it ( "should return sentences split by 。 and linebreak" , function ( ) {
7979 let sentences = splitSentences ( "text。\ntext" ) ;
8080 assert . equal ( sentences . length , 3 ) ;
8181 var sentence0 = sentences [ 0 ] ;
@@ -91,7 +91,7 @@ describe("sentence-utils", function () {
9191 assert . deepEqual ( sentence2 . loc . start , { line : 2 , column : 0 } ) ;
9292 assert . deepEqual ( sentence2 . loc . end , { line : 2 , column : 4 } ) ;
9393 } ) ;
94- it ( "should return sentences split by !?" , function ( ) {
94+ it ( "should return sentences split by !?" , function ( ) {
9595 let sentences = splitSentences ( "text!?text" ) ;
9696 assert . equal ( sentences . length , 2 ) ;
9797 var sentence0 = sentences [ 0 ] ;
@@ -103,16 +103,16 @@ describe("sentence-utils", function () {
103103 assert . deepEqual ( sentence1 . loc . start , { line : 1 , column : 6 } ) ;
104104 assert . deepEqual ( sentence1 . loc . end , { line : 1 , column : 10 } ) ;
105105 } ) ;
106- it ( "should sentences split by last 。" , function ( ) {
106+ it ( "should sentences split by last 。" , function ( ) {
107107 let sentences = splitSentences ( "text。" ) ;
108108 assert . equal ( sentences . length , 1 ) ;
109109 let sentence = sentences [ 0 ] ;
110110 assert . strictEqual ( sentence . raw , "text。" ) ;
111111 assert . deepEqual ( sentences [ 0 ] . loc . start , { line : 1 , column : 0 } ) ;
112112 assert . deepEqual ( sentences [ 0 ] . loc . end , { line : 1 , column : 5 } ) ;
113113 } ) ;
114- context ( "with options" , function ( ) {
115- it ( "should separate by whiteSpace" , function ( ) {
114+ context ( "with options" , function ( ) {
115+ it ( "should separate by whiteSpace" , function ( ) {
116116 var options = {
117117 newLineCharacters : "\n\n"
118118 } ;
@@ -135,7 +135,7 @@ describe("sentence-utils", function () {
135135 assert . deepEqual ( sentence3 . loc . start , { line : 3 , column : 0 } ) ;
136136 assert . deepEqual ( sentence3 . loc . end , { line : 3 , column : 4 } ) ;
137137 } ) ;
138- it ( "should separate by charRegExp" , function ( ) {
138+ it ( "should separate by charRegExp" , function ( ) {
139139 let sentences = splitSentences ( "text¶text" , {
140140 charRegExp : / ¶ /
141141 } ) ;
@@ -149,5 +149,30 @@ describe("sentence-utils", function () {
149149 assert . deepEqual ( sentence1 . loc . start , { line : 1 , column : 5 } ) ;
150150 assert . deepEqual ( sentence1 . loc . end , { line : 1 , column : 9 } ) ;
151151 } ) ;
152+ it ( "should separate by splitChars" , function ( ) {
153+ let sentences = splitSentences ( "text¶text" , {
154+ separatorChars : [ "¶" ]
155+ } ) ;
156+ assert . equal ( sentences . length , 2 ) ;
157+ var sentence0 = sentences [ 0 ] ;
158+ assert . strictEqual ( sentence0 . raw , "text¶" ) ;
159+ assert . deepEqual ( sentence0 . loc . start , { line : 1 , column : 0 } ) ;
160+ assert . deepEqual ( sentence0 . loc . end , { line : 1 , column : 5 } ) ;
161+ var sentence1 = sentences [ 1 ] ;
162+ assert . strictEqual ( sentence1 . raw , "text" ) ;
163+ assert . deepEqual ( sentence1 . loc . start , { line : 1 , column : 5 } ) ;
164+ assert . deepEqual ( sentence1 . loc . end , { line : 1 , column : 9 } ) ;
165+ } ) ;
166+ it ( "should not set separatorChars and charRegExp" , function ( ) {
167+ try {
168+ splitSentences ( "text¶text" , {
169+ separatorChars : [ "¶" ] ,
170+ charRegExp : / ¶ /
171+ } ) ;
172+ throw new Error ( "FAIL" ) ;
173+ } catch ( error ) {
174+ assert . equal ( error . name , "AssertionError" ) ;
175+ }
176+ } ) ;
152177 } ) ;
153178} ) ;
0 commit comments