1
0

qsharp.test.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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('qsharp', [
  7. // Generated from sample: https://github.com/microsoft/Quantum/blob/main/samples/azure-quantum/parallel-qrng/ParallelQrng.ipynb
  8. [
  9. {
  10. line: 'open Microsoft.Quantum.Arrays;',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.open.qsharp' },
  13. { startIndex: 4, type: 'white.qsharp' },
  14. { startIndex: 5, type: 'namespace.qsharp' },
  15. { startIndex: 14, type: 'delimiter.qsharp' },
  16. { startIndex: 15, type: 'namespace.qsharp' },
  17. { startIndex: 22, type: 'delimiter.qsharp' },
  18. { startIndex: 23, type: 'namespace.qsharp' },
  19. { startIndex: 29, type: 'delimiter.qsharp' }
  20. ]
  21. },
  22. {
  23. line: 'open Microsoft.Quantum.Measurement;',
  24. tokens: [
  25. { startIndex: 0, type: 'keyword.open.qsharp' },
  26. { startIndex: 4, type: 'white.qsharp' },
  27. { startIndex: 5, type: 'namespace.qsharp' },
  28. { startIndex: 14, type: 'delimiter.qsharp' },
  29. { startIndex: 15, type: 'namespace.qsharp' },
  30. { startIndex: 22, type: 'delimiter.qsharp' },
  31. { startIndex: 23, type: 'namespace.qsharp' },
  32. { startIndex: 34, type: 'delimiter.qsharp' }
  33. ]
  34. },
  35. {
  36. line: '',
  37. tokens: []
  38. },
  39. {
  40. line: 'operation SampleRandomNumber(nQubits : Int) : Result[] {',
  41. tokens: [
  42. { startIndex: 0, type: 'keyword.qsharp' },
  43. { startIndex: 9, type: 'white.qsharp' },
  44. { startIndex: 10, type: 'identifier.qsharp' },
  45. { startIndex: 28, type: 'delimiter.parenthesis.qsharp' },
  46. { startIndex: 29, type: 'identifier.qsharp' },
  47. { startIndex: 36, type: 'white.qsharp' },
  48. { startIndex: 37, type: 'operator.qsharp' },
  49. { startIndex: 38, type: 'white.qsharp' },
  50. { startIndex: 39, type: 'type.qsharp' },
  51. { startIndex: 42, type: 'delimiter.parenthesis.qsharp' },
  52. { startIndex: 43, type: 'white.qsharp' },
  53. { startIndex: 44, type: 'operator.qsharp' },
  54. { startIndex: 45, type: 'white.qsharp' },
  55. { startIndex: 46, type: 'type.qsharp' },
  56. { startIndex: 52, type: 'delimiter.square.qsharp' },
  57. { startIndex: 54, type: 'white.qsharp' },
  58. { startIndex: 55, type: 'delimiter.curly.qsharp' }
  59. ]
  60. },
  61. {
  62. line: ' // We prepare a register of qubits in a uniform',
  63. tokens: [
  64. { startIndex: 0, type: 'white.qsharp' },
  65. { startIndex: 1, type: 'comment.qsharp' }
  66. ]
  67. },
  68. {
  69. line: ' // superposition state, such that when we measure,',
  70. tokens: [
  71. { startIndex: 0, type: 'white.qsharp' },
  72. { startIndex: 1, type: 'comment.qsharp' }
  73. ]
  74. },
  75. {
  76. line: ' // all bitstrings occur with equal probability.',
  77. tokens: [
  78. { startIndex: 0, type: 'white.qsharp' },
  79. { startIndex: 1, type: 'comment.qsharp' }
  80. ]
  81. },
  82. {
  83. line: ' use register = Qubit[nQubits] {',
  84. tokens: [
  85. { startIndex: 0, type: 'white.qsharp' },
  86. { startIndex: 1, type: 'keyword.qsharp' },
  87. { startIndex: 4, type: 'white.qsharp' },
  88. { startIndex: 5, type: 'identifier.qsharp' },
  89. { startIndex: 13, type: 'white.qsharp' },
  90. { startIndex: 14, type: 'operator.qsharp' },
  91. { startIndex: 15, type: 'white.qsharp' },
  92. { startIndex: 16, type: 'type.qsharp' },
  93. { startIndex: 21, type: 'delimiter.square.qsharp' },
  94. { startIndex: 22, type: 'identifier.qsharp' },
  95. { startIndex: 29, type: 'delimiter.square.qsharp' },
  96. { startIndex: 30, type: 'white.qsharp' },
  97. { startIndex: 31, type: 'delimiter.curly.qsharp' }
  98. ]
  99. },
  100. {
  101. line: ' // Set qubits in superposition.',
  102. tokens: [
  103. { startIndex: 0, type: 'white.qsharp' },
  104. { startIndex: 2, type: 'comment.qsharp' }
  105. ]
  106. },
  107. {
  108. line: ' ApplyToEachA(H, register);',
  109. tokens: [
  110. { startIndex: 0, type: 'white.qsharp' },
  111. { startIndex: 2, type: 'identifier.qsharp' },
  112. { startIndex: 14, type: 'delimiter.parenthesis.qsharp' },
  113. { startIndex: 15, type: 'keyword.qsharp' },
  114. { startIndex: 16, type: 'delimiter.qsharp' },
  115. { startIndex: 17, type: 'white.qsharp' },
  116. { startIndex: 18, type: 'identifier.qsharp' },
  117. { startIndex: 26, type: 'delimiter.parenthesis.qsharp' },
  118. { startIndex: 27, type: 'delimiter.qsharp' }
  119. ]
  120. },
  121. {
  122. line: '',
  123. tokens: []
  124. },
  125. {
  126. line: ' // Measure all qubits and return.',
  127. tokens: [
  128. { startIndex: 0, type: 'white.qsharp' },
  129. { startIndex: 2, type: 'comment.qsharp' }
  130. ]
  131. },
  132. {
  133. line: ' return ForEach(MResetZ, register);',
  134. tokens: [
  135. { startIndex: 0, type: 'white.qsharp' },
  136. { startIndex: 2, type: 'keyword.qsharp' },
  137. { startIndex: 8, type: 'white.qsharp' },
  138. { startIndex: 9, type: 'identifier.qsharp' },
  139. { startIndex: 16, type: 'delimiter.parenthesis.qsharp' },
  140. { startIndex: 17, type: 'identifier.qsharp' },
  141. { startIndex: 24, type: 'delimiter.qsharp' },
  142. { startIndex: 25, type: 'white.qsharp' },
  143. { startIndex: 26, type: 'identifier.qsharp' },
  144. { startIndex: 34, type: 'delimiter.parenthesis.qsharp' },
  145. { startIndex: 35, type: 'delimiter.qsharp' }
  146. ]
  147. },
  148. {
  149. line: ' }',
  150. tokens: [
  151. { startIndex: 0, type: 'white.qsharp' },
  152. { startIndex: 1, type: 'delimiter.curly.qsharp' }
  153. ]
  154. },
  155. {
  156. line: '}',
  157. tokens: [{ startIndex: 0, type: 'delimiter.curly.qsharp' }]
  158. }
  159. ]
  160. ]);