create-file.test.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { expect } from 'chai';
  2. import { fileEqual } from './create-file';
  3. // eslint-disable-next-line @typescript-eslint/require-await -- async iterable
  4. const createSource = async function *(input: string[]) {
  5. for (const line of input) {
  6. yield line;
  7. }
  8. };
  9. const test = async (a: string[], b: string[], expected: boolean) => {
  10. expect((await fileEqual(a, createSource(b)))).to.eq(expected);
  11. };
  12. describe('fileEqual', () => {
  13. it('same', () => test(
  14. ['A', 'B'],
  15. ['A', 'B'],
  16. true
  17. ));
  18. it('ignore comment', async () => {
  19. await test(
  20. ['# A', 'B'],
  21. ['# B', 'B'],
  22. true
  23. );
  24. await test(
  25. ['# A', '# C', 'B'],
  26. ['# A', '# D', 'B'],
  27. true
  28. );
  29. });
  30. it('comment more', () => test(
  31. ['# A', 'B'],
  32. ['# A', '# B', 'B'],
  33. false
  34. ));
  35. it('larger', () => test(
  36. ['A', 'B'],
  37. ['A', 'B', 'C'],
  38. false
  39. ));
  40. it('smaller', () => test(
  41. ['A', 'B', 'C'],
  42. ['A', 'B'],
  43. false
  44. ));
  45. it('eol', () => test(
  46. ['A', 'B'],
  47. ['A', 'B', ''],
  48. true
  49. ));
  50. });