summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2018-12-22 00:41:54 +0900
committerAya Morisawa <AyaMorisawa4869@gmail.com>2018-12-22 00:44:38 +0900
commit580191fb172eccbbd12c2dfbccbd8346f38de91e (patch)
tree816c15f8fdbb57d4b312ea523dbb20c8a2ce7abf /test
parentFix sharedInbox location (#3711) (diff)
downloadsharkey-580191fb172eccbbd12c2dfbccbd8346f38de91e.tar.gz
sharkey-580191fb172eccbbd12c2dfbccbd8346f38de91e.tar.bz2
sharkey-580191fb172eccbbd12c2dfbccbd8346f38de91e.zip
Improve MFM bracket matching
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
Diffstat (limited to 'test')
-rw-r--r--test/mfm.ts95
1 files changed, 94 insertions, 1 deletions
diff --git a/test/mfm.ts b/test/mfm.ts
index 4811e1bbb2..6bbbe146ca 100644
--- a/test/mfm.ts
+++ b/test/mfm.ts
@@ -6,7 +6,7 @@ import * as assert from 'assert';
import analyze from '../src/mfm/parse';
import toHtml from '../src/mfm/html';
-import { createTree as tree, createLeaf as leaf, MfmTree } from '../src/mfm/parser';
+import { createTree as tree, createLeaf as leaf, MfmTree, removeOrphanedBrackets } from '../src/mfm/parser';
function text(text: string): MfmTree {
return leaf('text', { text });
@@ -49,6 +49,99 @@ describe('createTree', () => {
});
});
+describe('removeOrphanedBrackets', () => {
+ it('single (contained)', () => {
+ const input = '(foo)';
+ const expected = '(foo)';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('single (head)', () => {
+ const input = '(foo)bar';
+ const expected = '(foo)bar';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('single (tail)', () => {
+ const input = 'foo(bar)';
+ const expected = 'foo(bar)';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('a', () => {
+ const input = '(foo';
+ const expected = '';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('b', () => {
+ const input = ')foo';
+ const expected = '';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('nested', () => {
+ const input = 'foo(「(bar)」)';
+ const expected = 'foo(「(bar)」)';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('no brackets', () => {
+ const input = 'foo';
+ const expected = 'foo';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('with foreign bracket (single)', () => {
+ const input = 'foo(bar))';
+ const expected = 'foo(bar)';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('with foreign bracket (open)', () => {
+ const input = 'foo(bar';
+ const expected = 'foo';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('with foreign bracket (close)', () => {
+ const input = 'foo)bar';
+ const expected = 'foo';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('with foreign bracket (close and open)', () => {
+ const input = 'foo)(bar';
+ const expected = 'foo';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('various bracket type', () => {
+ const input = 'foo「(bar)」(';
+ const expected = 'foo「(bar)」';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+
+ it('intersected', () => {
+ const input = 'foo(「)」';
+ const expected = 'foo(「)」';
+ const actual = removeOrphanedBrackets(input);
+ assert.deepStrictEqual(actual, expected);
+ });
+});
+
describe('MFM', () => {
it('can be analyzed', () => {
const tokens = analyze('@himawari @hima_sub@namori.net お腹ペコい :cat: #yryr');