SynctexOutputParser.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import Path from 'node:path'
  2. import { expect, describe, beforeEach, it } from 'vitest'
  3. const MODULE_PATH = Path.join(
  4. import.meta.dirname,
  5. '../../../app/js/SynctexOutputParser'
  6. )
  7. describe('SynctexOutputParser', function () {
  8. beforeEach(async function (ctx) {
  9. ctx.SynctexOutputParser = (await import(MODULE_PATH)).default
  10. })
  11. describe('parseViewOutput', function () {
  12. it('parses valid output', function (ctx) {
  13. const output = `This is SyncTeX command line utility, version 1.5
  14. SyncTeX result begin
  15. Output:/compile/output.pdf
  16. Page:1
  17. x:136.537964
  18. y:661.437561
  19. h:133.768356
  20. v:663.928223
  21. W:343.711060
  22. H:9.962640
  23. before:
  24. offset:-1
  25. middle:
  26. after:
  27. Output:/compile/output.pdf
  28. Page:2
  29. x:178.769592
  30. y:649.482361
  31. h:134.768356
  32. v:651.973022
  33. W:342.711060
  34. H:19.962640
  35. before:
  36. offset:-1
  37. middle:
  38. after:
  39. SyncTeX result end
  40. `
  41. const records = ctx.SynctexOutputParser.parseViewOutput(output)
  42. expect(records).to.deep.equal([
  43. {
  44. page: 1,
  45. h: 133.768356,
  46. v: 663.928223,
  47. width: 343.71106,
  48. height: 9.96264,
  49. },
  50. {
  51. page: 2,
  52. h: 134.768356,
  53. v: 651.973022,
  54. width: 342.71106,
  55. height: 19.96264,
  56. },
  57. ])
  58. })
  59. it('handles garbage', function (ctx) {
  60. const output = 'This computer is on strike!'
  61. const records = ctx.SynctexOutputParser.parseViewOutput(output)
  62. expect(records).to.deep.equal([])
  63. })
  64. })
  65. describe('parseEditOutput', function () {
  66. it('parses valid output', function (ctx) {
  67. const output = `This is SyncTeX command line utility, version 1.5
  68. SyncTeX result begin
  69. Output:/compile/output.pdf
  70. Input:/compile/main.tex
  71. Line:17
  72. Column:-1
  73. Offset:0
  74. Context:
  75. SyncTeX result end
  76. `
  77. const records = ctx.SynctexOutputParser.parseEditOutput(
  78. output,
  79. '/compile'
  80. )
  81. expect(records).to.deep.equal([
  82. { file: 'main.tex', line: 17, column: -1 },
  83. ])
  84. })
  85. it('handles values that contain colons', function (ctx) {
  86. const output = `This is SyncTeX command line utility, version 1.5
  87. SyncTeX result begin
  88. Output:/compile/output.pdf
  89. Input:/compile/this-file:has-a-weird-name.tex
  90. Line:17
  91. Column:-1
  92. Offset:0
  93. Context:
  94. SyncTeX result end
  95. `
  96. const records = ctx.SynctexOutputParser.parseEditOutput(
  97. output,
  98. '/compile'
  99. )
  100. expect(records).to.deep.equal([
  101. { file: 'this-file:has-a-weird-name.tex', line: 17, column: -1 },
  102. ])
  103. })
  104. it('handles garbage', function (ctx) {
  105. const output = '2 + 2 = 4'
  106. const records = ctx.SynctexOutputParser.parseEditOutput(output)
  107. expect(records).to.deep.equal([])
  108. })
  109. })
  110. })