Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
escaping backticks on formatting test-update
Browse files Browse the repository at this point in the history
  • Loading branch information
yaya-usman committed Mar 31, 2022
1 parent 46771de commit 2e1533c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/editor/operations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
formatRange,
} from "../../src/editor/operations";
import { Formatting } from "../../src/components/views/rooms/MessageComposerFormatBar";
import { longestBacktickSequence } from '../../src/editor/deserialize';

const SERIALIZED_NEWLINE = { "text": "\n", "type": "newline" };

Expand All @@ -44,6 +45,23 @@ describe('editor/operations: formatting operations', () => {
expect(model.serializeParts()).toEqual([{ "text": "hello _world_!", "type": "plain" }]);
});

it('works for escaping backticks in between texts', () => {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([
pc.plain("hello ` world!"),
], pc, renderer);

const range = model.startRange(model.positionForOffset(0, false),
model.positionForOffset(13, false)); // hello ` world

expect(range.parts[0].text.trim().includes("`")).toBeTruthy();
expect(longestBacktickSequence(range.parts[0].text.trim())).toBe(1);
expect(model.serializeParts()).toEqual([{ "text": "hello ` world!", "type": "plain" }]);
toggleInlineFormat(range, "`".repeat(longestBacktickSequence(range.parts[0].text.trim()) + 1));
expect(model.serializeParts()).toEqual([{ "text": "``hello ` world``!", "type": "plain" }]);
});

it('works for parts of words', () => {
const renderer = createRenderer();
const pc = createPartCreator();
Expand Down

0 comments on commit 2e1533c

Please sign in to comment.