|
1 | 1 | # encoding: utf-8 |
2 | 2 | require File.expand_path('../test_helper', __FILE__) |
3 | 3 | require 'task_list' |
| 4 | +require 'task_list/filter' |
4 | 5 |
|
5 | 6 | class TaskListTest < Test::Unit::TestCase |
6 | | - |
7 | | - def test_updates_task_list_item_by_index |
8 | | - text = <<-md |
9 | | -- [ ] index 1, incomplete |
10 | | -- [x] index 2, complete |
11 | | - md |
12 | | - |
13 | | - assert_match "- [x] index 1, incomplete", update(text, 1, true).source |
14 | | - assert_match "- [ ] index 2, complete", update(text, 2, false).source |
15 | | - end |
16 | | - |
17 | | - def test_updates_task_lists_in_numbered_lists |
18 | | - text = <<-md |
19 | | -1. [ ] index 1, incomplete |
20 | | -14. [x] index 2, complete |
21 | | - md |
22 | | - |
23 | | - assert_match "1. [x] index 1, incomplete", update(text, 1, true).source |
24 | | - assert_match "14. [ ] index 2, complete", update(text, 2, false).source |
25 | | - end |
26 | | - |
27 | | - def test_updates_ignore_task_lists_in_code_fences |
28 | | - text = <<-md |
29 | | -``` |
30 | | -- [ ] should not be indexed |
31 | | -- [x] nor this |
32 | | -``` |
33 | | -
|
34 | | -- [ ] index 1, incomplete |
35 | | -- [x] index 2, complete |
36 | | - md |
37 | | - |
38 | | - assert_match "- [x] index 1, incomplete", update(text, 1, true).source |
39 | | - assert_match "- [ ] index 2, complete", update(text, 2, false).source |
40 | | - end |
41 | | - |
42 | | - def test_updates_ignores_items_in_paras |
43 | | - text = <<-md |
44 | | -here's a paragraph: |
45 | | -
|
46 | | -[ ] should not be indexed |
47 | | -[x] nor this |
48 | | -
|
49 | | -- [ ] index 1, incomplete |
50 | | -- [x] index 2, complete |
51 | | - md |
52 | | - |
53 | | - assert_match "- [x] index 1, incomplete", update(text, 1, true).source |
54 | | - assert_match "- [ ] index 2, complete", update(text, 2, false).source |
55 | | - end |
56 | | - |
57 | | - def test_update_cleans_carriage_returns_for_matches |
58 | | - text = <<-md |
59 | | -``` markdown\r |
60 | | -- [ ] foo\r |
61 | | -```\r |
62 | | -\r |
63 | | -- [ ] index 1, incomplete\r |
64 | | -- [x] index 2, complete\r |
65 | | - md |
66 | | - |
67 | | - assert_match "- [x] index 1, incomplete", update(text, 1, true).source |
68 | | - assert_match "- [ ] index 2, complete", update(text, 2, false).source |
69 | | - end |
70 | | - |
71 | | - def test_task_list_for_nil_body |
72 | | - assert task_list(nil).items.empty?, "no task list items are expected" |
| 7 | + class Record < Struct.new(:body) |
| 8 | + def task_list_items |
| 9 | + [] |
| 10 | + end |
73 | 11 | end |
74 | 12 |
|
75 | | - def test_task_list_summary |
76 | | - summary = task_list("").summary |
77 | | - assert !summary.items?, "no task list items are expected" |
78 | | - |
79 | | - text = <<-md |
80 | | -- [ ] one |
81 | | -- [x] two |
82 | | -
|
83 | | -``` |
84 | | -- [ ] don't count me yo |
85 | | -- [x] nor me |
86 | | -``` |
87 | | - md |
88 | | - |
89 | | - summary = task_list(text).summary |
90 | | - assert summary.items?, "task list items are expected" |
91 | | - assert_equal 2, summary.item_count |
92 | | - assert_equal 1, summary.complete_count |
93 | | - assert_equal 1, summary.incomplete_count |
| 13 | + def test_has_summary |
| 14 | + assert summary = task_list("- [ ] one").summary, "summary expected" |
| 15 | + assert_kind_of TaskList::Summary, summary |
94 | 16 | end |
95 | 17 |
|
96 | 18 | def task_list(text) |
97 | | - TaskList.new(text) |
98 | | - end |
99 | | - |
100 | | - def update(text, index, checked) |
101 | | - task_list(text).update(index, checked) |
| 19 | + TaskList.new(Record.new(text)) |
102 | 20 | end |
103 | 21 | end |
0 commit comments