rust.test.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. import { testTokenization } from '../test/testRunner';
  6. testTokenization('rust', [
  7. // String
  8. [
  9. {
  10. line: 'let a = "This is a string"',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.rust' },
  13. { startIndex: 3, type: 'white.rust' },
  14. { startIndex: 4, type: 'identifier.rust' },
  15. { startIndex: 5, type: 'white.rust' },
  16. { startIndex: 6, type: 'operator.rust' },
  17. { startIndex: 7, type: 'white.rust' },
  18. { startIndex: 8, type: 'string.quote.rust' },
  19. { startIndex: 9, type: 'string.rust' },
  20. { startIndex: 25, type: 'string.quote.rust' }
  21. ]
  22. }
  23. ],
  24. // Byte literal
  25. [
  26. {
  27. line: "let a = 'c'",
  28. tokens: [
  29. { startIndex: 0, type: 'keyword.rust' },
  30. { startIndex: 3, type: 'white.rust' },
  31. { startIndex: 4, type: 'identifier.rust' },
  32. { startIndex: 5, type: 'white.rust' },
  33. { startIndex: 6, type: 'operator.rust' },
  34. { startIndex: 7, type: 'white.rust' },
  35. { startIndex: 8, type: 'string.byteliteral.rust' }
  36. ]
  37. }
  38. ],
  39. [
  40. {
  41. line: "'\"'",
  42. tokens: [{ startIndex: 0, type: 'string.byteliteral.rust' }]
  43. }
  44. ],
  45. [
  46. {
  47. line: "'\0'",
  48. tokens: [{ startIndex: 0, type: 'string.byteliteral.rust' }]
  49. }
  50. ],
  51. // Comment
  52. [
  53. {
  54. line: '// This is a comment',
  55. tokens: [{ startIndex: 0, type: 'comment.rust' }]
  56. }
  57. ],
  58. // Block Comment
  59. [
  60. {
  61. line: '/* This is a block comment */',
  62. tokens: [{ startIndex: 0, type: 'comment.rust' }]
  63. }
  64. ],
  65. [
  66. {
  67. line: '/* This is a block comment // with a comment */',
  68. tokens: [{ startIndex: 0, type: 'comment.rust' }]
  69. }
  70. ],
  71. // Lifetime Annotation
  72. [
  73. {
  74. line: 'static NAME: &\'static str = "John"',
  75. tokens: [
  76. { startIndex: 0, type: 'keyword.rust' },
  77. { startIndex: 6, type: 'white.rust' },
  78. { startIndex: 7, type: 'identifier.rust' },
  79. { startIndex: 11, type: 'operator.rust' },
  80. { startIndex: 12, type: 'white.rust' },
  81. { startIndex: 13, type: 'operator.rust' },
  82. { startIndex: 14, type: 'identifier.rust' },
  83. { startIndex: 21, type: 'white.rust' },
  84. { startIndex: 22, type: 'keyword.type.rust' },
  85. { startIndex: 25, type: 'white.rust' },
  86. { startIndex: 26, type: 'operator.rust' },
  87. { startIndex: 27, type: 'white.rust' },
  88. { startIndex: 28, type: 'string.quote.rust' },
  89. { startIndex: 29, type: 'string.rust' },
  90. { startIndex: 33, type: 'string.quote.rust' }
  91. ]
  92. }
  93. ],
  94. // Type Keywords
  95. [
  96. {
  97. line: 'let logical: bool = true',
  98. tokens: [
  99. { startIndex: 0, type: 'keyword.rust' },
  100. { startIndex: 3, type: 'white.rust' },
  101. { startIndex: 4, type: 'identifier.rust' },
  102. { startIndex: 11, type: 'operator.rust' },
  103. { startIndex: 12, type: 'white.rust' },
  104. { startIndex: 13, type: 'keyword.type.rust' },
  105. { startIndex: 17, type: 'white.rust' },
  106. { startIndex: 18, type: 'operator.rust' },
  107. { startIndex: 19, type: 'white.rust' },
  108. { startIndex: 20, type: 'keyword.rust' }
  109. ]
  110. }
  111. ],
  112. // Numbers
  113. // Integer
  114. [
  115. {
  116. line: '1000_000_00u32',
  117. tokens: [{ startIndex: 0, type: 'number.rust' }]
  118. }
  119. ],
  120. // Float
  121. [
  122. {
  123. line: '1.0f32',
  124. tokens: [{ startIndex: 0, type: 'number.rust' }]
  125. }
  126. ],
  127. // Hex
  128. [
  129. {
  130. line: '0xFA_01i32',
  131. tokens: [{ startIndex: 0, type: 'number.rust' }]
  132. }
  133. ],
  134. // Exponent
  135. [
  136. {
  137. line: '1.0E-8234987_f64',
  138. tokens: [{ startIndex: 0, type: 'number.rust' }]
  139. }
  140. ],
  141. // Binary
  142. [
  143. {
  144. line: '0b0_1u8',
  145. tokens: [{ startIndex: 0, type: 'number.rust' }]
  146. }
  147. ],
  148. // Octal
  149. [
  150. {
  151. line: '0o0000_0010u64',
  152. tokens: [{ startIndex: 0, type: 'number.rust' }]
  153. }
  154. ]
  155. ]);