create-file.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { expect } from 'expect';
  2. import { fileEqual } from './create-file';
  3. // eslint-disable-next-line @typescript-eslint/require-await -- async iterable
  4. async function *createSource(input: string[]) {
  5. for (const line of input) {
  6. yield line;
  7. }
  8. }
  9. async function test(a: string[], b: string[], expected: boolean) {
  10. expect((await fileEqual(a, createSource(b)))).toBe(expected);
  11. }
  12. describe('fileEqual', () => {
  13. it('same', () => test(
  14. ['A', 'B'],
  15. ['A', 'B'],
  16. true
  17. ));
  18. it('ignore comment 1', async () => {
  19. await test(
  20. ['# A', 'B'],
  21. ['# B', 'B'],
  22. true
  23. );
  24. });
  25. it('ignore comment 2', () => test(
  26. ['# A', '# C', 'B'],
  27. ['# A', '# D', 'B'],
  28. true
  29. ));
  30. it('ignore comment 3', () => test(
  31. ['# A', '# C', 'B'],
  32. ['# A', '# D', 'A'],
  33. false
  34. ));
  35. it('comment more', () => test(
  36. ['# A', 'B'],
  37. ['# A', '# B', 'B'],
  38. false
  39. ));
  40. it('comment less', () => test(
  41. ['# A', '# B', 'B'],
  42. ['# A', 'B'],
  43. false
  44. ));
  45. it('larger', () => test(
  46. ['A', 'B'],
  47. ['A', 'B', 'C'],
  48. false
  49. ));
  50. it('smaller', () => test(
  51. ['A', 'B', 'C'],
  52. ['A', 'B'],
  53. false
  54. ));
  55. it('eol more #1', () => test(
  56. ['A', 'B'],
  57. ['A', 'B', ''],
  58. false
  59. ));
  60. it('eol more #2', () => test(
  61. ['A', 'B', ''],
  62. ['A', 'B', '', ''],
  63. false
  64. ));
  65. it('eol less #1', () => test(
  66. ['A', 'B', ''],
  67. ['A', 'B'],
  68. false
  69. ));
  70. it('eol less #2', () => test(
  71. ['A', 'B', '', ''],
  72. ['A', 'B', ''],
  73. false
  74. ));
  75. it('sgmodule', () => test(
  76. ['#!name=[Sukka] URL Redirect', '#!desc=Last Updated: 2025-04-21T13:01:42.570Z Size: 127', '', 'always-real-ip'],
  77. ['#!name=[Sukka] URL Redirect', '#!desc=Last Updated: 2025-04-20T13:01:42.570Z Size: 130', '', 'always-real-ip'],
  78. true
  79. ));
  80. });