@praphan.o/thai-sentence-cut
Version:
การตัดข้อความภาษาไทยโดยไม่นับสระลอยและวรรณยุกต์
49 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const expect = require("chai").expect;
const index_1 = require("../src/index");
// const { lengthOfThaiString, splitThaiStringByLength } = require("../src");
const testString = "ประโยคยาวๆ ที่ใช้ทดสอบการตัดคำและการนับความยาวของตัวอักขระโดยไม่สนใจสระและวรรณยุกต์ไทย";
const testStringMultiline = "ประโยคยาวๆ\nที่ใช้ทดสอบ\nการตัดคำและการนับความยาวของตัวอักขระโดยไม่สนใจสระและวรรณยุกต์ไทยของเรา";
const testStringWithSpecialChar = "ทดสอบภาษาไทย (ตัวอย่าง)";
const len = (0, index_1.lengthOfThaiString)(testString);
const splitted = (0, index_1.splitThaiStringByLength)(testString, 20);
const multiLineSplitted = (0, index_1.splitThaiStringByLength)(testStringMultiline, 20);
const splittedWithSpecialChars = (0, index_1.splitThaiStringByLength)(testStringWithSpecialChar, 10);
console.log(splittedWithSpecialChars);
describe("lengthOfThaiString", () => {
it("should return number", () => {
expect(len).to.be.a("number");
});
it("should equal to 76", () => {
expect(len).to.be.eql(76);
});
});
describe("splitThaiStringByLength", () => {
it("should return an array", () => {
expect(splitted).to.be.an("array");
});
it("should have length of 4", () => {
expect(splitted.length).to.be.eql(4);
});
it("should have same content when joined", () => {
expect(splitted.join("")).to.be.equals(testString);
});
});
describe("splitThaiStringByLength with multi-line string", () => {
it("should return an array", () => {
expect(multiLineSplitted).to.be.an("array");
});
it("should have length of 6", () => {
expect(multiLineSplitted.length).to.be.eql(6);
});
});
describe("Test string with special character", () => {
it("should return an array", () => {
expect(splittedWithSpecialChars).to.be.an("array");
});
it("should have length of 3", () => {
expect(splittedWithSpecialChars.length).to.be.eql(3);
});
});
//# sourceMappingURL=index.spec.js.map