Skip to content

Commit 222800f

Browse files
committed
test: Use createSorterFromLine() instead of parseSortLine() in tests
This is preparation for removing parseSortLine(), which is effectively a duplicate of createSorterFromLine()
1 parent 7a3a3cb commit 222800f

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

tests/Query/Filter/Field.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe('sorting - base class usability and implementation', () => {
6262
});
6363

6464
it('should fail to parse a "valid" line', () => {
65-
// expect(unsupported.parseSortLine('sort by unsupported')).toThrow(Error);
6665
const line = 'sort by unsupported';
6766
expect(unsupported.createSorterFromLine(line)).toBeNull();
6867
const sorting = unsupported.parseSortLine(line);
@@ -97,7 +96,7 @@ describe('sorting - base class usability and implementation', () => {
9796
});
9897

9998
it('should compare two tasks', () => {
100-
const sorting = supported.parseSortLine('sort by description-length');
99+
const sorting = supported.createSorterFromLine('sort by description-length');
101100
const a = new TaskBuilder().description('short description').build();
102101
const b = new TaskBuilder().description('very looooooooong description').build();
103102
expectTaskComparesBefore(sorting!, a, b);

tests/Query/Filter/RecurringField.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('sorting by recurring', () => {
6060

6161
it('parses sort by recurrence', () => {
6262
const field = new RecurringField();
63-
expect(field.parseSortLine('sort by recurring')).not.toBeNull();
63+
expect(field.createSorterFromLine('sort by recurring')).not.toBeNull();
6464
});
6565

6666
it('sort by due', () => {

tests/Query/Filter/TagsField.test.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,20 @@ describe('Sort by tags', () => {
362362
});
363363

364364
it('should parse a valid line with default tag number', () => {
365-
const sorter = tagsField.parseSortLine('sort by tag');
365+
const sorter = tagsField.createSorterFromLine('sort by tag');
366366
expect(sorter?.property).toEqual('tag');
367367
expect(sorter?.comparator(tag_a, tag_b)).toBeLessThan(0);
368368
expectTaskComparesBefore(sorter!, tag_a, tag_b);
369369
});
370370

371371
it('should parse a valid line with a non-default tag number', () => {
372-
const sorter = tagsField.parseSortLine('sort by tag 2');
372+
const sorter = tagsField.createSorterFromLine('sort by tag 2');
373373
expect(sorter?.property).toEqual('tag');
374374
expectTaskComparesBefore(sorter!, tags_a_b, tags_a_c);
375375
});
376376

377377
it('should parse a valid line with reverse and a non-default tag number', () => {
378-
const sorter = tagsField.parseSortLine('sort by tag reverse 2');
378+
const sorter = tagsField.createSorterFromLine('sort by tag reverse 2');
379379
expect(sorter?.property).toEqual('tag');
380380
expectTaskComparesAfter(sorter!, tags_a_b, tags_a_c);
381381
});
@@ -417,7 +417,10 @@ describe('Sort by tags', () => {
417417

418418
// Act / Assert
419419
expect(
420-
Sort.by([new TagsField().parseSortLine('sort by tag 1')!], [t1, t3, t5, t7, t6, t4, t2, t8, t9, t10]),
420+
Sort.by(
421+
[new TagsField().createSorterFromLine('sort by tag 1')!],
422+
[t1, t3, t5, t7, t6, t4, t2, t8, t9, t10],
423+
),
421424
).toEqual(expectedOrder);
422425
});
423426

@@ -438,7 +441,7 @@ describe('Sort by tags', () => {
438441
// Act / Assert
439442
expect(
440443
Sort.by(
441-
[new TagsField().parseSortLine('sort by tag reverse 1')!],
444+
[new TagsField().createSorterFromLine('sort by tag reverse 1')!],
442445
[t1, t3, t5, t7, t6, t4, t2, t8, t9, t10],
443446
),
444447
).toEqual(expectedOrder);
@@ -451,7 +454,9 @@ describe('Sort by tags', () => {
451454
const t4 = fromLine({ line: '- [ ] a #iii #ddd' });
452455
const t5 = fromLine({ line: '- [ ] a #hhh #eee' });
453456
const expectedOrder = [t1, t2, t3, t4, t5];
454-
expect(Sort.by([new TagsField().parseSortLine('sort by tag 2')!], [t4, t3, t2, t1, t5])).toEqual(expectedOrder);
457+
expect(Sort.by([new TagsField().createSorterFromLine('sort by tag 2')!], [t4, t3, t2, t1, t5])).toEqual(
458+
expectedOrder,
459+
);
455460
});
456461

457462
it('should sort correctly reversed by second tag with no global filter', () => {
@@ -461,7 +466,7 @@ describe('Sort by tags', () => {
461466
const t4 = fromLine({ line: '- [ ] a #iii #ddd' });
462467
const t5 = fromLine({ line: '- [ ] a #hhh #eee' });
463468
const expectedOrder = [t5, t4, t3, t2, t1];
464-
expect(Sort.by([new TagsField().parseSortLine('sort by tag reverse 2')!], [t4, t3, t2, t1, t5])).toEqual(
469+
expect(Sort.by([new TagsField().createSorterFromLine('sort by tag reverse 2')!], [t4, t3, t2, t1, t5])).toEqual(
465470
expectedOrder,
466471
);
467472
});
@@ -489,7 +494,7 @@ describe('Sort by tags', () => {
489494
// Act
490495
expect(
491496
Sort.by(
492-
[new TagsField().parseSortLine('sort by tag 1')!],
497+
[new TagsField().createSorterFromLine('sort by tag 1')!],
493498
[t1, t12, t3, t13, t5, t7, t6, t4, t2, t8, t9, t10, t11],
494499
),
495500
).toEqual(expectedOrder);
@@ -521,7 +526,7 @@ describe('Sort by tags', () => {
521526
// Act
522527
expect(
523528
Sort.by(
524-
[new TagsField().parseSortLine('sort by tag reverse 1')!],
529+
[new TagsField().createSorterFromLine('sort by tag reverse 1')!],
525530
[t1, t12, t3, t13, t5, t7, t6, t4, t2, t8, t9, t10, t11],
526531
),
527532
).toEqual(expectedOrder);
@@ -545,7 +550,10 @@ describe('Sort by tags', () => {
545550
const expectedOrder = [t1, t2, t3, t4, t5, t6, t7, t8];
546551

547552
// Act
548-
const result = Sort.by([new TagsField().parseSortLine('sort by tag 2')!], [t4, t7, t5, t2, t3, t1, t8, t6]);
553+
const result = Sort.by(
554+
[new TagsField().createSorterFromLine('sort by tag 2')!],
555+
[t4, t7, t5, t2, t3, t1, t8, t6],
556+
);
549557

550558
// Assert
551559
expect(result).toEqual(expectedOrder);
@@ -570,7 +578,7 @@ describe('Sort by tags', () => {
570578

571579
// Act
572580
const result = Sort.by(
573-
[new TagsField().parseSortLine('sort by tag reverse 2')!],
581+
[new TagsField().createSorterFromLine('sort by tag reverse 2')!],
574582
[t4, t7, t5, t2, t3, t1, t8, t6],
575583
);
576584

@@ -608,8 +616,8 @@ describe('Sort by tags', () => {
608616
expect(
609617
Sort.by(
610618
[
611-
new TagsField().parseSortLine('sort by tag 2')!, // tag 2 - ascending
612-
new TagsField().parseSortLine('sort by tag 1')!, // tag 1 - ascending
619+
new TagsField().createSorterFromLine('sort by tag 2')!, // tag 2 - ascending
620+
new TagsField().createSorterFromLine('sort by tag 1')!, // tag 1 - ascending
613621
new DescriptionField().createNormalSorter(), // then description - ascending
614622
],
615623
input,

0 commit comments

Comments
 (0)