Advertisement
Guest User

Test

a guest
Nov 9th, 2022
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import test from 'tape'
  2. import { retext } from 'retext'
  3. import retextRepeatedWords from './index.js'
  4.  
  5. test('retextRepeatedWords()', (t) => {
  6. t.deepEqual(
  7. JSON.parse(
  8. JSON.stringify(
  9. retext()
  10. .use(retextRepeatedWords)
  11. .processSync('Well, it it doesn’t have to be.').messages
  12. )
  13. ),
  14. [
  15. {
  16. name: '1:7-1:12',
  17. message: 'Expected `it` once, not twice',
  18. reason: 'Expected `it` once, not twice',
  19. line: 1,
  20. column: 7,
  21. source: 'retext-repeated-words',
  22. ruleId: 'it',
  23. position: {
  24. start: { line: 1, column: 7, offset: 6 },
  25. end: { line: 1, column: 12, offset: 11 }
  26. },
  27. fatal: false,
  28. actual: 'it it',
  29. expected: ['it'],
  30. url: 'https://github.com/retextjs/retext-repeated-words#readme'
  31. }
  32. ],
  33. 'should emit messages'
  34. )
  35.  
  36. t.deepEqual(
  37. retext()
  38. .use(retextRepeatedWords)
  39. .processSync(
  40. 'Well, it it doesn’t have to to be. Like a fish in the\nthe sea.'
  41. )
  42. .messages.map(String),
  43. [
  44. '1:7-1:12: Expected `it` once, not twice',
  45. '1:26-1:31: Expected `to` once, not twice',
  46. '1:51-2:4: Expected `the` once, not twice'
  47. ],
  48. 'should catch repeated words'
  49. )
  50.  
  51. t.deepEqual(
  52. retext()
  53. .use(retextRepeatedWords)
  54. .processSync(
  55. 'Well, it it doesn’t have to to be. Like a fish in the\r\nthe sea.'
  56. )
  57. .messages.map(String),
  58. [
  59. '1:7-1:12: Expected `it` once, not twice',
  60. '1:26-1:31: Expected `to` once, not twice',
  61. '1:51-2:4: Expected `the` once, not twice'
  62. ],
  63. 'should catch repeated words'
  64. )
  65.  
  66. t.deepEqual(
  67. retext()
  68. .use(retextRepeatedWords)
  69. .processSync('LIKE A FISH IN THE\nTHE SEA.')
  70. .messages.map(String),
  71. ['1:16-2:4: Expected `THE` once, not twice'],
  72. 'should catch repeated words when uppercase'
  73. )
  74.  
  75. t.deepEqual(
  76. retext().use(retextRepeatedWords).processSync('Duran Duran is awesome.')
  77. .messages,
  78. [],
  79. 'should ignore sentence cased words'
  80. )
  81.  
  82. t.deepEqual(
  83. retext().use(retextRepeatedWords).processSync('D. D. will pop up with.')
  84. .messages,
  85. [],
  86. 'should ignore initialisms'
  87. )
  88.  
  89. t.deepEqual(
  90. retext().use(retextRepeatedWords).processSync('DURAN Duran').messages,
  91. [],
  92. 'should ignore differently cases words'
  93. )
  94.  
  95. t.deepEqual(
  96. retext()
  97. .use(retextRepeatedWords)
  98. .processSync('the most heartening exhibition they had had since')
  99. .messages,
  100. [],
  101. 'should ignore some valid repetitions'
  102. )
  103.  
  104. t.deepEqual(
  105. retext()
  106. .use(retextRepeatedWords)
  107. .processSync(
  108. 'The Mau Mau Uprising, also known as the Mau Mau Rebellion, Mau Mau Revolt, or Kenya Emergency, was a military conflict that took place in British Kenya'
  109. ).messages,
  110. [],
  111. 'should ignore some valid repetitions (mau)'
  112. )
  113.  
  114. t.end()
  115. })
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement