|
10 | 10 |
|
11 | 11 | const {assert} = require('chai');
|
12 | 12 |
|
13 |
| -const {parseComment} = require('./auto-run-helpers.js'); |
| 13 | +const {parseComment, parseFollowUps} = require('./auto-run-helpers.js'); |
14 | 14 |
|
15 | 15 | describe('parsing comments', () => {
|
16 | 16 | it('parses out the prompt and evaluation sections using the "old" syntax', () => {
|
@@ -86,3 +86,84 @@ describe('parsing comments', () => {
|
86 | 86 | assert.deepEqual(result, {prompt: 'A', explanation: 'B\nC\nD'});
|
87 | 87 | });
|
88 | 88 | });
|
| 89 | + |
| 90 | +describe('parseFollowUps', () => { |
| 91 | + it('should return an empty array when no followup keys exist', () => { |
| 92 | + const comment = { |
| 93 | + prompt: 'Test prompt', |
| 94 | + explanation: 'Test explanation', |
| 95 | + }; |
| 96 | + assert.deepEqual(parseFollowUps(comment), []); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should parse a single followup', () => { |
| 100 | + const comment = { |
| 101 | + prompt: 'Test prompt', |
| 102 | + followup1: 'First follow up', |
| 103 | + }; |
| 104 | + assert.deepEqual(parseFollowUps(comment), ['First follow up']); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should parse multiple sequential followups in order', () => { |
| 108 | + const comment = { |
| 109 | + followup2: 'Second follow up', |
| 110 | + prompt: 'Test prompt', |
| 111 | + followup1: 'First follow up', |
| 112 | + explanation: 'Test explanation', |
| 113 | + followup3: 'Third follow up', |
| 114 | + }; |
| 115 | + assert.deepEqual(parseFollowUps(comment), [ |
| 116 | + 'First follow up', |
| 117 | + 'Second follow up', |
| 118 | + 'Third follow up', |
| 119 | + ]); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should parse non-sequential followups and filter empty slots', () => { |
| 123 | + const comment = { |
| 124 | + followup3: 'Third follow up', |
| 125 | + prompt: 'Test prompt', |
| 126 | + followup1: 'First follow up', |
| 127 | + }; |
| 128 | + assert.deepEqual(parseFollowUps(comment), ['First follow up', 'Third follow up']); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should throw an error for invalid followup keys (non-numeric index)', () => { |
| 132 | + const comment = { |
| 133 | + followup1: 'First follow up', |
| 134 | + followupX: 'Invalid key', |
| 135 | + }; |
| 136 | + assert.throws(() => parseFollowUps(comment), 'Found invalid followup prompt: followupX, Invalid key'); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should throw an error for invalid followup keys (no index)', () => { |
| 140 | + const comment = { |
| 141 | + followup: 'Invalid key', |
| 142 | + followup1: 'First follow up', |
| 143 | + }; |
| 144 | + assert.throws(() => parseFollowUps(comment), /^Found invalid followup prompt: followup,/); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should throw an error when encountering empty string values for followups', () => { |
| 148 | + const comment = { |
| 149 | + followup1: '', |
| 150 | + followup2: 'Second follow up', |
| 151 | + }; |
| 152 | + assert.throws(() => { |
| 153 | + parseFollowUps(comment); |
| 154 | + }, /Found empty followup value at followup1/); |
| 155 | + }); |
| 156 | + |
| 157 | + it('should correctly parse followup keys with multiple digits', () => { |
| 158 | + const comment = { |
| 159 | + followup10: 'Tenth follow up', |
| 160 | + followup1: 'First follow up', |
| 161 | + followup2: 'Second follow up', |
| 162 | + }; |
| 163 | + assert.deepEqual(parseFollowUps(comment), [ |
| 164 | + 'First follow up', |
| 165 | + 'Second follow up', |
| 166 | + 'Tenth follow up', |
| 167 | + ]); |
| 168 | + }); |
| 169 | +}); |
0 commit comments