Have tests use prod regexes

This commit is contained in:
Jack Kingsman
2026-04-04 13:13:37 -07:00
parent b19585db6d
commit 9ebf63491c
2 changed files with 9 additions and 12 deletions

View File

@@ -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', () => {

View File

@@ -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[] = [];