<commit_before>import { parse } from '../../../lib/calendar/vcal';
import {
    getDayAndSetpos,
    getIsRruleCustom,
    getSupportedRrule,
    getSupportedUntil,
    getIsRruleSupported,
    getIsStandardByday,
    getHasConsistentRrule,
    getIsRruleSimple,
} from '../../../lib/calendar/rrule';
import { FREQUENCY } from '../../../lib/calendar/constants';

describe('getIsStandardByday', () => {
    it('returns true for standard BYDAY strings', () => {
        const bydays = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
        expect(bydays.map(getIsStandardByday)).toEqual(bydays.map(() => true));
    });

    it('returns false for non-standard BYDAY strings', () => {
        const bydays = ['1SU', 'SUN', 'S', 'DO', ''];
        expect(bydays.map(getIsStandardByday)).toEqual(bydays.map(() => false));
    });
});

describe('getDayAndSetpos', () => {
    it('gets the day and setpos correctly', () => {
        const bydays = ['1SU', '+2MO', '-1FR', 'WE'];
        const results = [{ setpos: 1, day: 'SU' }, { setpos: 2, day: 'MO' }, { setpos: -1, day: 'FR' }, { day: 'WE' }];
        expect(bydays.map((byday) => getDayAndSetpos(byday))).toEqual(results);
    });
});

describe('getSupportedUntil', () => {
    it('should keep the date for all-day events', () => {
        const tzid = 'Pacific/Niue';
        const until = { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true };
        const expected = { year: 2020, month: 6, day: 27 };
        expect(getSupportedUntil(until, true, tzid)).toEqual(expected);
    });

    it('should always return the same until if it was at the end of the day already', () => {
        const tzid = 'Pacific/Niue';
        const until = { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true };
        expect(getSupportedUntil(until, false, tzid)).toEqual(until);
    });

    it('should always return an until at the end of the day', () => {
        const tzid = 'Pacific/Niue';
        const untils = [
            { year: 2020, month: 6, day: 27, hours: 15, minutes: 14, isUTC: true },
            { year: 2020, month: 6, day: 27 },
        ];
        const expected = [
            { year: 2020, month: 6, day: 28, hours: 10, minutes: 59, seconds: 59, isUTC: true },
            { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true },
        ];
        expect(untils.map((until) => getSupportedUntil(until, false, tzid))).toEqual(expected);
    });
});

describe('getIsRruleSimple', () => {
    it('returns true for simple recurring events', () => {
        const rrules = [
            {
                freq: FREQUENCY.DAILY,
                interval: 1,
            },
            {
                freq: FREQUENCY.WEEKLY,
                interval: 1,
                byday: 'SA',
            },
            {
                freq: FREQUENCY.MONTHLY,
                interval: 1,
                bymonthday: 23,
            },
            {
                freq: FREQUENCY.YEARLY,
                interval: 1,
                bymonth: 5,
            },
            {<commit_msg>Add a test for getSupportedUntil for all-day events with guessTzid<commit_after>import { parse } from '../../../lib/calendar/vcal';
import {
    getDayAndSetpos,
    getIsRruleCustom,
    getSupportedRrule,
    getSupportedUntil,
    getIsRruleSupported,
    getIsStandardByday,
    getHasConsistentRrule,
    getIsRruleSimple,
} from '../../../lib/calendar/rrule';
import { FREQUENCY } from '../../../lib/calendar/constants';

describe('getIsStandardByday', () => {
    it('returns true for standard BYDAY strings', () => {
        const bydays = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
        expect(bydays.map(getIsStandardByday)).toEqual(bydays.map(() => true));
    });

    it('returns false for non-standard BYDAY strings', () => {
        const bydays = ['1SU', 'SUN', 'S', 'DO', ''];
        expect(bydays.map(getIsStandardByday)).toEqual(bydays.map(() => false));
    });
});

describe('getDayAndSetpos', () => {
    it('gets the day and setpos correctly', () => {
        const bydays = ['1SU', '+2MO', '-1FR', 'WE'];
        const results = [{ setpos: 1, day: 'SU' }, { setpos: 2, day: 'MO' }, { setpos: -1, day: 'FR' }, { day: 'WE' }];
        expect(bydays.map((byday) => getDayAndSetpos(byday))).toEqual(results);
    });
});

describe('getSupportedUntil', () => {
    it('should keep the date for all-day events', () => {
        const tzid = 'Pacific/Niue';
        const until = { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true };
        const expected = { year: 2020, month: 6, day: 27 };
        expect(getSupportedUntil(until, true, tzid)).toEqual(expected);
    });

    it('should always return the same until if it was at the end of the day already', () => {
        const tzid = 'Pacific/Niue';
        const until = { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true };
        expect(getSupportedUntil(until, false, tzid)).toEqual(until);
    });

    it('should always return an until at the end of the day', () => {
        const tzid = 'Pacific/Niue';
        const untils = [
            { year: 2020, month: 6, day: 27, hours: 15, minutes: 14, isUTC: true },
            { year: 2020, month: 6, day: 27 },
        ];
        const expected = [
            { year: 2020, month: 6, day: 28, hours: 10, minutes: 59, seconds: 59, isUTC: true },
            { year: 2020, month: 6, day: 27, hours: 10, minutes: 59, seconds: 59, isUTC: true },
        ];
        expect(untils.map((until) => getSupportedUntil(until, false, tzid))).toEqual(expected);
    });

    it('should keep the right date for all-day events when a guess tzid is passed', () => {
        const tzid = 'Pacific/Niue';
        const guessTzid = 'Asia/Taipei';
        const until = { year: 2020, month: 11, day: 24, hours: 16, minutes: 0, seconds: 0, isUTC: true };
        const expected = { year: 2020, month: 11, day: 25 };
        expect(getSupportedUntil(until, true, tzid, guessTzid)).toEqual(expected);
    });
});

describe('getIsRruleSimple', () => {
    it('returns true for simple recurring events', () => {
        const rrules = [
            {
                freq: FREQUENCY.DAILY,
                interval: 1,
            },
            {
                freq: FREQUENCY.WEEKLY,
                interval: 1,
                byday: 'SA',
            },
            {
                freq: FREQUENCY.MONTHLY,
                interval: 1,
                bymonthday: 23,
            },
            {
                freq: FREQUENCY.YEARLY,
                interval: 1,
                bymonth: 5,
            },
            {
{'fraction_non_alphanumeric': 0.16577460600654179, 'fraction_numerical': 0.030032708890871247, 'mean_word_length': 2.1522961574507966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, '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': '5706931', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2095, 'n_words': 571}