get-args.test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const assert = require('node:assert/strict')
  2. const { describe, test } = require('node:test')
  3. const getArgumentsForPosition = require('./get-args.js')
  4. describe('getArgumentsForPosition', () => {
  5. describe('editor-specific argument formats', () => {
  6. for (const editor of [
  7. 'atom',
  8. 'Atom',
  9. 'Atom Beta',
  10. 'subl',
  11. 'sublime',
  12. 'sublime_text',
  13. 'wstorm',
  14. 'charm',
  15. 'zed',
  16. ]) {
  17. test(`${editor} uses "file:line:column"`, () => {
  18. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), ['file:10:5'])
  19. })
  20. }
  21. test('notepad++ uses -n/-c flags', () => {
  22. assert.deepEqual(getArgumentsForPosition('notepad++', 'file', 10, 5), ['-n10', '-c5', 'file'])
  23. })
  24. for (const editor of ['vim', 'mvim']) {
  25. test(`${editor} uses +call cursor()`, () => {
  26. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), [
  27. '+call cursor(10, 5)',
  28. 'file',
  29. ])
  30. })
  31. }
  32. for (const editor of ['joe', 'gvim']) {
  33. test(`${editor} uses +line`, () => {
  34. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), ['+10', 'file'])
  35. })
  36. }
  37. for (const editor of ['emacs', 'emacsclient']) {
  38. test(`${editor} uses +line:column`, () => {
  39. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), ['+10:5', 'file'])
  40. })
  41. }
  42. for (const editor of ['rmate', 'mate', 'mine']) {
  43. test(`${editor} uses --line`, () => {
  44. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), ['--line', 10, 'file'])
  45. })
  46. }
  47. for (const editor of [
  48. 'code',
  49. 'Code',
  50. 'code-insiders',
  51. 'Code - Insiders',
  52. 'codium',
  53. 'trae',
  54. 'antigravity',
  55. 'cursor',
  56. 'vscodium',
  57. 'VSCodium',
  58. ]) {
  59. test(`${editor} uses -r -g "file:line:column"`, () => {
  60. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), ['-r', '-g', 'file:10:5'])
  61. })
  62. }
  63. for (const editor of ['idea', 'idea64', 'webstorm', 'pycharm', 'clion', 'rider']) {
  64. test(`${editor} uses --line/--column`, () => {
  65. assert.deepEqual(getArgumentsForPosition(editor, 'file', 10, 5), [
  66. '--line',
  67. 10,
  68. '--column',
  69. 5,
  70. 'file',
  71. ])
  72. })
  73. }
  74. })
  75. test('defaults columnNumber to 1 when omitted', () => {
  76. assert.deepEqual(getArgumentsForPosition('code', 'file', 10), ['-r', '-g', 'file:10:1'])
  77. })
  78. describe('editor resolution via path.basename and extension stripping', () => {
  79. test('resolves a full POSIX path', () => {
  80. assert.deepEqual(getArgumentsForPosition('/usr/local/bin/code', 'file', 10, 5), [
  81. '-r',
  82. '-g',
  83. 'file:10:5',
  84. ])
  85. })
  86. if (process.platform === 'win32') {
  87. test('resolves a full Windows path with .exe', () => {
  88. assert.deepEqual(getArgumentsForPosition('C:\\path\\Code.exe', 'file', 10, 5), [
  89. '-r',
  90. '-g',
  91. 'file:10:5',
  92. ])
  93. })
  94. test('resolves notepad++ from a full path with .exe', () => {
  95. assert.deepEqual(getArgumentsForPosition('C:\\tools\\notepad++.exe', 'file', 10, 5), [
  96. '-n10',
  97. '-c5',
  98. 'file',
  99. ])
  100. })
  101. }
  102. test('strips .cmd extension case-insensitively', () => {
  103. assert.deepEqual(getArgumentsForPosition('code.CMD', 'file', 10, 5), [
  104. '-r',
  105. '-g',
  106. 'file:10:5',
  107. ])
  108. })
  109. })
  110. })