<commit_before>import replaceSymbols from '../../src/lib/default-transformer';
import chai from 'chai';
import spies from 'chai-spies';

chai.use(spies);

let {expect, spy} = chai;

describe('default-transformer', () => {
    let project, baseURI;
    beforeEach(() => {
        project = null;
        baseURI = null;
    });

    it('replaces #hashtags with markdown hashtag links', () => {
        const tagLink = replaceSymbols('#test', {project, baseURI});
        expect(tagLink).to.equal('[#test](/talk/search?query=test)');
    });

    it('works in a sentence with multiple tags & a URL', () => {
        const sentence = `#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`

        const htmlSentence = replaceSymbols(sentence, {project, baseURI})
        expect(htmlSentence).to.equal(`#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`)
    })

    it('ignores links with hashes', () => {
        const url = "http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users";
        const markup = replaceSymbols(url, {project, baseURI});

        expect(markup).to.equal(url)
    })

    it('allows delimiters in hashtags', () => {
        ['#test-tag', '#test_tag', '#test.tag'].forEach((tag) => {
            const parsedTag = replaceSymbols(tag, {project, baseURI})
            expect(parsedTag).to.equal(`[${tag}](/talk/search?query=${tag.slice(1, tag.length)})`)
        })
    })

    it('replaces ^S<subject_id> mentions with subject links', () =>{
        project = { slug: "test/project" };
        const subjectLink = replaceSymbols('^S123456', {project, baseURI});;
        expect(subjectLink).to.equal('[Subject 123456](/projects/test/project/talk/subjects/123456)');
    });

    it('replaces project #hashtag mentions with project links', () =>{
        project = { slug: "test/project" };
        const subjectLink = replaceSymbols('#S123456', {project, baseURI});;
        expect(subjectLink).to.equal('[#S123456](/projects/test/project/talk/search?query=S123456)');
    });


    it('does not format subject Ids when not in a routed context', () =>{
        const subjectLink = replaceSymbols('^S123456', {project, baseURI});<commit_msg>Fix hashtag links to correctly go to the hashtag results, and not include occurrences of the word with no hash.<commit_after>import replaceSymbols from '../../src/lib/default-transformer';
import chai from 'chai';
import spies from 'chai-spies';

chai.use(spies);

let {expect, spy} = chai;

describe('default-transformer', () => {
    let project, baseURI;
    beforeEach(() => {
        project = null;
        baseURI = null;
    });

    it('replaces #hashtags with markdown hashtag links', () => {
        const tagLink = replaceSymbols('#test', {project, baseURI});
        expect(tagLink).to.equal('[#test](/talk/search?query=test)');
    });

    it('works in a sentence with multiple tags & a URL', () => {
        const sentence = `#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`

        const htmlSentence = replaceSymbols(sentence, {project, baseURI})
        expect(htmlSentence).to.equal(`#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`)
    })

    it('ignores links with hashes', () => {
        const url = "http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users";
        const markup = replaceSymbols(url, {project, baseURI});

        expect(markup).to.equal(url)
    })

    it('allows delimiters in hashtags', () => {
        ['#test-tag', '#test_tag', '#test.tag'].forEach((tag) => {
            const parsedTag = replaceSymbols(tag, {project, baseURI})
            expect(parsedTag).to.equal(`[${tag}](/talk/search?query=${tag.slice(1, tag.length)})`)
        })
    })

    it('replaces ^S<subject_id> mentions with subject links', () =>{
        project = { slug: "test/project" };
        const subjectLink = replaceSymbols('^S123456', {project, baseURI});;
        expect(subjectLink).to.equal('[Subject 123456](/projects/test/project/talk/subjects/123456)');
    });

    it('replaces project #hashtag mentions with project links', () =>{
        project = { slug: "test/project" };
        const subjectLink = replaceSymbols('#S123456', {project, baseURI});;
        expect(subjectLink).to.equal('[#S123456](/projects/test/project/talk/tags/S123456)');
    });


    it('does not format subject Ids when not in a routed context', () =>{
        const subjectLink = replaceSymbols('^S123456', {project, baseURI});
{'fraction_non_alphanumeric': 0.17186165670367207, 'fraction_numerical': 0.018360375747224593, 'mean_word_length': 3.354089219330855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3936310', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1434, 'n_words': 300}