ruby.test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. 'use strict';
  6. import {testTokenization} from './testRunner';
  7. testTokenization('ruby', [
  8. // Keywords
  9. [{
  10. line: 'class Klass def init() end',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.class.ruby' },
  13. { startIndex: 5, type: '' },
  14. { startIndex: 6, type: 'constructor.identifier.ruby' },
  15. { startIndex: 11, type: '' },
  16. { startIndex: 12, type: 'keyword.def.ruby' },
  17. { startIndex: 15, type: '' },
  18. { startIndex: 16, type: 'identifier.ruby' },
  19. { startIndex: 20, type: 'delimiter.parenthesis.ruby' },
  20. { startIndex: 22, type: '' },
  21. { startIndex: 23, type: 'keyword.def.ruby' }
  22. ]}],
  23. // Single digit
  24. [{
  25. line: 'x == 1 ',
  26. tokens: [
  27. { startIndex: 0, type: 'identifier.ruby' },
  28. { startIndex: 1, type: '' },
  29. { startIndex: 2, type: 'operator.ruby' },
  30. { startIndex: 4, type: '' },
  31. { startIndex: 5, type: 'number.ruby' },
  32. { startIndex: 6, type: '' }
  33. ]}],
  34. // Regex
  35. [{
  36. line: 'text =~ /Ruby/',
  37. tokens: [
  38. { startIndex: 0, type: 'identifier.ruby' },
  39. { startIndex: 4, type: '' },
  40. { startIndex: 5, type: 'operator.ruby' },
  41. { startIndex: 7, type: '' },
  42. { startIndex: 8, type: 'regexp.delim.ruby' },
  43. { startIndex: 9, type: 'regexp.ruby' },
  44. { startIndex: 13, type: 'regexp.delim.ruby' }
  45. ]}],
  46. [{
  47. line: 'text.sub!(/Rbuy/, "Ruby")',
  48. tokens: [
  49. { startIndex: 0, type: 'identifier.ruby' },
  50. { startIndex: 4, type: '' },
  51. { startIndex: 5, type: 'identifier.ruby' },
  52. { startIndex: 9, type: 'delimiter.parenthesis.ruby' },
  53. { startIndex: 10, type: 'regexp.delim.ruby' },
  54. { startIndex: 11, type: 'regexp.ruby' },
  55. { startIndex: 15, type: 'regexp.delim.ruby' },
  56. { startIndex: 16, type: 'delimiter.ruby' },
  57. { startIndex: 17, type: '' },
  58. { startIndex: 18, type: 'string.d.delim.ruby' },
  59. { startIndex: 19, type: 'string.$S2.ruby' },
  60. { startIndex: 23, type: 'string.d.delim.ruby' },
  61. { startIndex: 24, type: 'delimiter.parenthesis.ruby' }
  62. ]}],
  63. // make sure that division does not match regex
  64. [{
  65. line: 'a / b',
  66. tokens: [
  67. { startIndex: 0, type: 'identifier.ruby' },
  68. { startIndex: 1, type: '' },
  69. { startIndex: 2, type: 'operator.ruby' },
  70. { startIndex: 3, type: '' },
  71. { startIndex: 4, type: 'identifier.ruby' }
  72. ]}],
  73. // Heredoc
  74. [{
  75. line: '<<HERE',
  76. tokens: [
  77. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  78. ]}, {
  79. line: 'do some string',
  80. tokens: [
  81. { startIndex: 0, type: 'string.heredoc.ruby' }
  82. ]}, {
  83. line: 'HERE',
  84. tokens: [
  85. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  86. ]}],
  87. [{
  88. line: 'x <<HERE',
  89. tokens: [
  90. { startIndex: 0, type: 'identifier.ruby' },
  91. { startIndex: 1, type: 'string.heredoc.delimiter.ruby' }
  92. ]}, {
  93. line: 'do some string',
  94. tokens: [
  95. { startIndex: 0, type: 'string.heredoc.ruby' }
  96. ]}, {
  97. line: 'HERE',
  98. tokens: [
  99. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  100. ]}],
  101. [{
  102. line: 'x<<HERE',
  103. tokens: [
  104. { startIndex: 0, type: 'identifier.ruby' },
  105. { startIndex: 1, type: 'operator.ruby' },
  106. { startIndex: 3, type: 'constructor.identifier.ruby' }
  107. ]}],
  108. [{
  109. line: 'x<<-HERE',
  110. tokens: [
  111. { startIndex: 0, type: 'identifier.ruby' },
  112. { startIndex: 1, type: 'string.heredoc.delimiter.ruby' }
  113. ]}]
  114. ]);