mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-05-01 11:02:56 +02:00
Have tests use prod regexes
This commit is contained in:
@@ -9,7 +9,7 @@ import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
findLinkedChannelReferences,
|
||||
formatTime,
|
||||
isValidLinkedChannelName,
|
||||
HASHTAG_CHANNEL_NAME_PATTERN,
|
||||
parseSenderFromText,
|
||||
} from '../utils/messageParser';
|
||||
|
||||
@@ -103,16 +103,16 @@ describe('formatTime', () => {
|
||||
|
||||
describe('linked channel references', () => {
|
||||
it('accepts lowercase alphanumeric names with single dashes', () => {
|
||||
expect(isValidLinkedChannelName('ops')).toBe(true);
|
||||
expect(isValidLinkedChannelName('ops-1')).toBe(true);
|
||||
expect(isValidLinkedChannelName('1-2-3')).toBe(true);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops')).toBe(true);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops-1')).toBe(true);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('1-2-3')).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects uppercase, leading or trailing dashes, and repeated dashes', () => {
|
||||
expect(isValidLinkedChannelName('Ops')).toBe(false);
|
||||
expect(isValidLinkedChannelName('-ops')).toBe(false);
|
||||
expect(isValidLinkedChannelName('ops-')).toBe(false);
|
||||
expect(isValidLinkedChannelName('ops--room')).toBe(false);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('Ops')).toBe(false);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('-ops')).toBe(false);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops-')).toBe(false);
|
||||
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops--room')).toBe(false);
|
||||
});
|
||||
|
||||
it('finds standalone linked channel references in message text', () => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Parse sender from channel message text.
|
||||
* Channel messages have format "sender: message".
|
||||
*/
|
||||
const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
||||
export const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
||||
const HASHTAG_CHANNEL_REFERENCE_PATTERN = /(^|\s)(#[a-z0-9]+(?:-[a-z0-9]+)*)(?=$|[\s.,;:])/g;
|
||||
|
||||
export function parseSenderFromText(text: string): { sender: string | null; content: string } {
|
||||
@@ -26,9 +26,6 @@ export interface HashtagChannelReference {
|
||||
end: number;
|
||||
}
|
||||
|
||||
export function isValidLinkedChannelName(name: string): boolean {
|
||||
return HASHTAG_CHANNEL_NAME_PATTERN.test(name);
|
||||
}
|
||||
|
||||
export function findLinkedChannelReferences(text: string): HashtagChannelReference[] {
|
||||
const references: HashtagChannelReference[] = [];
|
||||
|
||||
Reference in New Issue
Block a user