SynctexOutputParserTests.js 2.6 KB

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