From 825737f3eb3203be1edf297cbbfb8c8500fa1e91 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 14:31:52 +0100 Subject: [PATCH 1/8] Add basic linkify-matrix tests --- test/linkify-matrix-test.ts | 227 ++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 test/linkify-matrix-test.ts diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts new file mode 100644 index 00000000000..22ae6daaebc --- /dev/null +++ b/test/linkify-matrix-test.ts @@ -0,0 +1,227 @@ +import * as linkify from "linkifyjs"; +import linkifyMatrix from '../src/linkify-matrix'; + +describe('linkify-matrix', () => { + beforeAll(() => { + linkifyMatrix(linkify); + }); + describe('roomalias', () => { + it('properly parses #_foonetic_xkcd:matrix.org', () => { + const test = '#_foonetic_xkcd:matrix.org'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#_foonetic_xkcd:matrix.org", + type: "roomalias", + value: "#_foonetic_xkcd:matrix.org", + }])); + }); + it('properly parses #foo:localhost', () => { + const test = "#foo:localhost"; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:localhost", + type: "roomalias", + value: "#foo:localhost", + }])); + }); + it('accept #foo:bar.com', () => { + const test = '#foo:bar.com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:bar.com", + type: "roomalias", + value: "#foo:bar.com", + + }])); + }); + it('accept #foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { + const test = '#foo:com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:com", + type: "roomalias", + value: "#foo:com", + }])); + }); + it('accept repeated TLDs (e.g .org.uk)', () => { + const test = '#foo:bar.org.uk'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:bar.org.uk", + type: "roomalias", + value: "#foo:bar.org.uk", + }])); + }); + it('ignores trailing `:`', () => { + const test = '#foo:bar.com:'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:bar.com", + type: "roomalias", + value: "#foo:bar.com", + + }])); + }); + it('accept :NUM (port specifier)', () => { + const test = '#foo:bar.com:2225'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:bar.com:2225", + type: "roomalias", + value: "#foo:bar.com:2225", + }])); + }); + it('ignores all the trailing :', () => { + const test = '#foo:bar.com::::'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo:bar.com", + type: "roomalias", + value: "#foo:bar.com", + + }])); + }); + it('properly parses room alias with dots in name', () => { + const test = '#foo.asdf:bar.com::::'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo.asdf:bar.com", + type: "roomalias", + value: "#foo.asdf:bar.com", + + }])); + }); + // This test does not work and does not parse the room + it.skip('does not parse room alias with too many separators', () => { + const test = '#foo:::bar.com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "#foo", + type: 'roomalias', + value: '#foo', + }, + { + href: "http://bar.com", + type: "url", + value: "bar.com", + }])); + }); + // This should not parse correctly, but it's been working this way in the previous version too + it.skip('does not parse multiple room aliases in one string', () => { + const test = '#foo:bar.com-baz.com'; + const found = linkify.find(test); + expect(found).toEqual(([])); + }); + }); + + describe('groupid', () => { + it('properly parses +foo:localhost', () => { + const test = "+foo:localhost"; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "+foo:localhost", + type: "groupid", + value: "+foo:localhost", + }])); + }); + it('accept +foo:bar.com', () => { + const test = '+foo:bar.com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "+foo:bar.com", + type: "groupid", + value: "+foo:bar.com", + }])); + }); + it('accept +foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { + const test = '+foo:com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "+foo:com", + type: "groupid", + value: "+foo:com", + }])); + }); + it('accept repeated TLDs (e.g .org.uk)', () => { + const test = '+foo:bar.org.uk'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "+foo:bar.org.uk", + type: "groupid", + value: "+foo:bar.org.uk", + }])); + }); + // This test should not be failing according to the linkify-matrix code + // TODO: Fix the implementation so the test properly ignores trailing ':' + it.skip('do not accept trailing `:`', () => { + const test = '+foo:bar.com:'; + const found = linkify.find(test); + expect(found).toEqual(([])); + }); + it('accept :NUM (port specifier)', () => { + const test = '+foo:bar.com:2225'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "+foo:bar.com:2225", + type: "groupid", + value: "+foo:bar.com:2225", + }])); + }); + }); + + describe('userid', () => { + // It does not parse a single user ID without domain + it.skip('properly parses @foo', () => { + const test = "@foo"; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "@foo", + type: "userid", + value: "@foo", + }])); + }); + it('accept @foo:bar.com', () => { + const test = '@foo:bar.com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "@foo:bar.com", + type: "userid", + value: "@foo:bar.com", + }])); + }); + it('accept @foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { + const test = '@foo:com'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "@foo:com", + type: "userid", + value: "@foo:com", + }])); + }); + it('accept repeated TLDs (e.g .org.uk)', () => { + const test = '@foo:bar.org.uk'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "@foo:bar.org.uk", + type: "userid", + value: "@foo:bar.org.uk", + }])); + }); + // This test should not be failing according to the linkify-matrix code + // TODO: Fix the implementation so the test properly ignores trailing ':' + it.skip('do not accept trailing `:`', () => { + const test = '@foo:bar.com:'; + const found = linkify.find(test); + expect(found).toEqual(([])); + }); + it('accept :NUM (port specifier)', () => { + const test = '@foo:bar.com:2225'; + const found = linkify.find(test); + expect(found).toEqual(([{ + href: "@foo:bar.com:2225", + type: "userid", + value: "@foo:bar.com:2225", + }])); + }); + }); +}); From 4d67706613ed1475ee6e59b660967758f11f5dfd Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:36:30 +0100 Subject: [PATCH 2/8] Add missing header --- test/linkify-matrix-test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index 22ae6daaebc..fad04b4ca0c 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -1,3 +1,18 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ import * as linkify from "linkifyjs"; import linkifyMatrix from '../src/linkify-matrix'; From cdedb645595cea0ccbeecfb114371c8dfb2bb4f1 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:36:49 +0100 Subject: [PATCH 3/8] Fix different beforeAll call --- test/linkify-matrix-test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index fad04b4ca0c..a24b7fd5294 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -16,10 +16,11 @@ limitations under the License. import * as linkify from "linkifyjs"; import linkifyMatrix from '../src/linkify-matrix'; +beforeAll(() => { + linkifyMatrix(linkify); +}); + describe('linkify-matrix', () => { - beforeAll(() => { - linkifyMatrix(linkify); - }); describe('roomalias', () => { it('properly parses #_foonetic_xkcd:matrix.org', () => { const test = '#_foonetic_xkcd:matrix.org'; From fc62a2ac5b1528a1dad6f40b9665e30333ef600a Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:37:38 +0100 Subject: [PATCH 4/8] Fix stray new line --- test/linkify-matrix-test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index a24b7fd5294..f0df3e407d6 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -47,7 +47,6 @@ describe('linkify-matrix', () => { href: "#foo:bar.com", type: "roomalias", value: "#foo:bar.com", - }])); }); it('accept #foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { From 0b8d98ea0f1ecf3bfbb932b68568d3ba044ddf95 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:38:36 +0100 Subject: [PATCH 5/8] Fix invalid test --- test/linkify-matrix-test.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index f0df3e407d6..bcbe61a0460 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -106,16 +106,10 @@ describe('linkify-matrix', () => { }])); }); - // This test does not work and does not parse the room - it.skip('does not parse room alias with too many separators', () => { + it('does not parse room alias with too many separators', () => { const test = '#foo:::bar.com'; const found = linkify.find(test); expect(found).toEqual(([{ - href: "#foo", - type: 'roomalias', - value: '#foo', - }, - { href: "http://bar.com", type: "url", value: "bar.com", From 231e0deff76473b78bbe34f3142542b0fd485c81 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:39:54 +0100 Subject: [PATCH 6/8] Fix test not parsing multiple room aliases --- test/linkify-matrix-test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index bcbe61a0460..645b253d9e4 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -115,11 +115,14 @@ describe('linkify-matrix', () => { value: "bar.com", }])); }); - // This should not parse correctly, but it's been working this way in the previous version too - it.skip('does not parse multiple room aliases in one string', () => { + it('does not parse multiple room aliases in one string', () => { const test = '#foo:bar.com-baz.com'; const found = linkify.find(test); - expect(found).toEqual(([])); + expect(found).toEqual(([{ + "href": "#foo:bar.com-baz.com", + "type": "roomalias", + "value": "#foo:bar.com-baz.com", + }])); }); }); From a35cfb0a0d904ebfcb54fe6502311d898567ebdf Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:41:38 +0100 Subject: [PATCH 7/8] Fix mor tests --- test/linkify-matrix-test.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index 645b253d9e4..5750995ee73 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -163,12 +163,14 @@ describe('linkify-matrix', () => { value: "+foo:bar.org.uk", }])); }); - // This test should not be failing according to the linkify-matrix code - // TODO: Fix the implementation so the test properly ignores trailing ':' - it.skip('do not accept trailing `:`', () => { + it('ignore trailing `:`', () => { const test = '+foo:bar.com:'; const found = linkify.find(test); - expect(found).toEqual(([])); + expect(found).toEqual(([{ + "href": "+foo:bar.com", + "type": "groupid", + "value": "+foo:bar.com", + }])); }); it('accept :NUM (port specifier)', () => { const test = '+foo:bar.com:2225'; @@ -219,12 +221,14 @@ describe('linkify-matrix', () => { value: "@foo:bar.org.uk", }])); }); - // This test should not be failing according to the linkify-matrix code - // TODO: Fix the implementation so the test properly ignores trailing ':' - it.skip('do not accept trailing `:`', () => { + it('do not accept trailing `:`', () => { const test = '@foo:bar.com:'; const found = linkify.find(test); - expect(found).toEqual(([])); + expect(found).toEqual(([{ + href: "@foo:bar.com", + type: "userid", + value: "@foo:bar.com", + }])); }); it('accept :NUM (port specifier)', () => { const test = '@foo:bar.com:2225'; From cb53cb55a37d0221e04292943692b72d6fee3a7c Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 25 Nov 2021 21:42:10 +0100 Subject: [PATCH 8/8] Fix test without domain --- test/linkify-matrix-test.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index 5750995ee73..9ab6e3921eb 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -184,15 +184,10 @@ describe('linkify-matrix', () => { }); describe('userid', () => { - // It does not parse a single user ID without domain - it.skip('properly parses @foo', () => { + it('should not parse @foo without domain', () => { const test = "@foo"; const found = linkify.find(test); - expect(found).toEqual(([{ - href: "@foo", - type: "userid", - value: "@foo", - }])); + expect(found).toEqual(([])); }); it('accept @foo:bar.com', () => { const test = '@foo:bar.com';