ruby.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. }],
  24. // Single digit
  25. [{
  26. line: 'x == 1 ',
  27. tokens: [
  28. { startIndex: 0, type: 'identifier.ruby' },
  29. { startIndex: 1, type: '' },
  30. { startIndex: 2, type: 'operator.ruby' },
  31. { startIndex: 4, type: '' },
  32. { startIndex: 5, type: 'number.ruby' },
  33. { startIndex: 6, type: '' }
  34. ]
  35. }],
  36. // Regex
  37. [{
  38. line: 'text =~ /Ruby/',
  39. tokens: [
  40. { startIndex: 0, type: 'identifier.ruby' },
  41. { startIndex: 4, type: '' },
  42. { startIndex: 5, type: 'operator.ruby' },
  43. { startIndex: 7, type: '' },
  44. { startIndex: 8, type: 'regexp.delim.ruby' },
  45. { startIndex: 9, type: 'regexp.ruby' },
  46. { startIndex: 13, type: 'regexp.delim.ruby' }
  47. ]
  48. }],
  49. [{
  50. line: 'text.sub!(/Rbuy/, "Ruby")',
  51. tokens: [
  52. { startIndex: 0, type: 'identifier.ruby' },
  53. { startIndex: 4, type: '' },
  54. { startIndex: 5, type: 'identifier.ruby' },
  55. { startIndex: 9, type: 'delimiter.parenthesis.ruby' },
  56. { startIndex: 10, type: 'regexp.delim.ruby' },
  57. { startIndex: 11, type: 'regexp.ruby' },
  58. { startIndex: 15, type: 'regexp.delim.ruby' },
  59. { startIndex: 16, type: 'delimiter.ruby' },
  60. { startIndex: 17, type: '' },
  61. { startIndex: 18, type: 'string.d.delim.ruby' },
  62. { startIndex: 19, type: 'string.$S2.ruby' },
  63. { startIndex: 23, type: 'string.d.delim.ruby' },
  64. { startIndex: 24, type: 'delimiter.parenthesis.ruby' }
  65. ]
  66. }],
  67. // make sure that division does not match regex
  68. [{
  69. line: 'a / b',
  70. tokens: [
  71. { startIndex: 0, type: 'identifier.ruby' },
  72. { startIndex: 1, type: '' },
  73. { startIndex: 2, type: 'operator.ruby' },
  74. { startIndex: 3, type: '' },
  75. { startIndex: 4, type: 'identifier.ruby' }
  76. ]
  77. }],
  78. // Heredoc
  79. [{
  80. line: '<<HERE',
  81. tokens: [
  82. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  83. ]
  84. }, {
  85. line: 'do some string',
  86. tokens: [
  87. { startIndex: 0, type: 'string.heredoc.ruby' }
  88. ]
  89. }, {
  90. line: 'HERE',
  91. tokens: [
  92. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  93. ]
  94. }],
  95. [{
  96. line: 'x <<HERE',
  97. tokens: [
  98. { startIndex: 0, type: 'identifier.ruby' },
  99. { startIndex: 1, type: 'string.heredoc.delimiter.ruby' }
  100. ]
  101. }, {
  102. line: 'do some string',
  103. tokens: [
  104. { startIndex: 0, type: 'string.heredoc.ruby' }
  105. ]
  106. }, {
  107. line: 'HERE',
  108. tokens: [
  109. { startIndex: 0, type: 'string.heredoc.delimiter.ruby' }
  110. ]
  111. }],
  112. [{
  113. line: 'x<<HERE',
  114. tokens: [
  115. { startIndex: 0, type: 'identifier.ruby' },
  116. { startIndex: 1, type: 'operator.ruby' },
  117. { startIndex: 3, type: 'constructor.identifier.ruby' }
  118. ]
  119. }],
  120. [{
  121. line: 'x<<-HERE',
  122. tokens: [
  123. { startIndex: 0, type: 'identifier.ruby' },
  124. { startIndex: 1, type: 'string.heredoc.delimiter.ruby' }
  125. ]
  126. }],
  127. [{
  128. line: 'x<<~HERE',
  129. tokens: [
  130. { startIndex: 0, type: 'identifier.ruby' },
  131. { startIndex: 1, type: 'string.heredoc.delimiter.ruby' }
  132. ]
  133. }]
  134. ]);