Skip to content

Commit

Permalink
Merge pull request #21 from TwilioDevEd/fix-triple-accents
Browse files Browse the repository at this point in the history
  • Loading branch information
hughrawlinson authored Jan 13, 2023
2 parents 8bc6c58 + 30cb849 commit 231a006
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/libs/EncodedChar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/libs/EncodedChar.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/scripts/segmentsCalculator.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/libs/EncodedChar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EncodedChar {
constructor(char: string, encoding: 'GSM-7' | 'UCS-2') {
this.raw = char;
this.encoding = encoding;
this.isGSM7 = Boolean(char && UnicodeToGsm[char.charCodeAt(0)]);
this.isGSM7 = Boolean(char && char.length === 1 && UnicodeToGsm[char.charCodeAt(0)]);
if (this.isGSM7) {
this.codeUnits = UnicodeToGsm[char.charCodeAt(0)];
} else {
Expand Down
21 changes: 21 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const expectExport = require('expect');
const { SegmentedMessage } = require('../dist');
const SmartEncodingMap = require('../dist/libs/SmartEncodingMap').default;

Expand Down Expand Up @@ -215,4 +216,24 @@ describe('Line break styles tests', () => {
const segmentedMessage = new SegmentedMessage(testMessage);
expect(segmentedMessage.numberOfCharacters).toBe(12);
});

test('Triple accents characters - Unicode test', () => {
const testMessage = 'é́́';
const segmentedMessage = new SegmentedMessage(testMessage);
expect(segmentedMessage.numberOfCharacters).toBe(1);
expect(segmentedMessage.numberOfUnicodeScalars).toBe(4);
});

// Test for https://github.com/TwilioDevEd/message-segment-calculator/issues/17
test('Triple accents characters - One Segment test', () => {
const testMessage = 'é́́aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const segmentedMessage = new SegmentedMessage(testMessage);
expect(segmentedMessage.segmentsCount).toBe(1);
});

test('Triple accents characters - Two Segments test', () => {
const testMessage = 'é́́aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const segmentedMessage = new SegmentedMessage(testMessage);
expect(segmentedMessage.segmentsCount).toBe(2);
});
});

0 comments on commit 231a006

Please sign in to comment.