(
beforeText: string,
beforeExpectation: string,
afterText: string,
afterExpectation: string,
)
| 167 | }); |
| 168 | |
| 169 | function assertCharDiff( |
| 170 | beforeText: string, |
| 171 | beforeExpectation: string, |
| 172 | afterText: string, |
| 173 | afterExpectation: string, |
| 174 | ) { |
| 175 | const codes = computeCharacterDiffs(beforeText, afterText); |
| 176 | if (codes === null) { |
| 177 | expect(codes).not.toBeNull(); |
| 178 | throw new Error(); |
| 179 | } |
| 180 | // 'Declined to generate a diff when one was expected.'); |
| 181 | |
| 182 | const [beforeCodes, afterCodes] = codes; |
| 183 | |
| 184 | const process = function (codes: CharacterDiff[], txt: string) { |
| 185 | return codes |
| 186 | .map(function (code) { |
| 187 | let part = txt.substring(code[1], code[2]); |
| 188 | if (code[0] != null) part = '[' + part + ']'; |
| 189 | return part; |
| 190 | }) |
| 191 | .join(''); |
| 192 | }; |
| 193 | |
| 194 | const beforeActual = process(beforeCodes, beforeText), |
| 195 | afterActual = process(afterCodes, afterText); |
| 196 | |
| 197 | expect(beforeActual).toEqual(beforeExpectation); |
| 198 | expect(afterActual).toEqual(afterExpectation); |
| 199 | } |
| 200 | |
| 201 | // See https://github.com/danvk/github-syntax/issues/17 |
| 202 | test('pure add with assertCharDiff', () => { |
no test coverage detected