123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import { testTokenization } from '../test/testRunner';
- testTokenization('rust', [
- // String
- [
- {
- line: 'let a = "This is a string"',
- tokens: [
- { startIndex: 0, type: 'keyword.rust' },
- { startIndex: 3, type: 'white.rust' },
- { startIndex: 4, type: 'identifier.rust' },
- { startIndex: 5, type: 'white.rust' },
- { startIndex: 6, type: 'operator.rust' },
- { startIndex: 7, type: 'white.rust' },
- { startIndex: 8, type: 'string.quote.rust' },
- { startIndex: 9, type: 'string.rust' },
- { startIndex: 25, type: 'string.quote.rust' }
- ]
- }
- ],
- // Byte literal
- [
- {
- line: "let a = 'c'",
- tokens: [
- { startIndex: 0, type: 'keyword.rust' },
- { startIndex: 3, type: 'white.rust' },
- { startIndex: 4, type: 'identifier.rust' },
- { startIndex: 5, type: 'white.rust' },
- { startIndex: 6, type: 'operator.rust' },
- { startIndex: 7, type: 'white.rust' },
- { startIndex: 8, type: 'string.byteliteral.rust' }
- ]
- }
- ],
- [
- {
- line: "'\"'",
- tokens: [{ startIndex: 0, type: 'string.byteliteral.rust' }]
- }
- ],
- [
- {
- line: "'\0'",
- tokens: [{ startIndex: 0, type: 'string.byteliteral.rust' }]
- }
- ],
- // Comment
- [
- {
- line: '// This is a comment',
- tokens: [{ startIndex: 0, type: 'comment.rust' }]
- }
- ],
- // Block Comment
- [
- {
- line: '/* This is a block comment */',
- tokens: [{ startIndex: 0, type: 'comment.rust' }]
- }
- ],
- [
- {
- line: '/* This is a block comment // with a comment */',
- tokens: [{ startIndex: 0, type: 'comment.rust' }]
- }
- ],
- // Lifetime Annotation
- [
- {
- line: 'static NAME: &\'static str = "John"',
- tokens: [
- { startIndex: 0, type: 'keyword.rust' },
- { startIndex: 6, type: 'white.rust' },
- { startIndex: 7, type: 'identifier.rust' },
- { startIndex: 11, type: 'operator.rust' },
- { startIndex: 12, type: 'white.rust' },
- { startIndex: 13, type: 'operator.rust' },
- { startIndex: 14, type: 'identifier.rust' },
- { startIndex: 21, type: 'white.rust' },
- { startIndex: 22, type: 'keyword.type.rust' },
- { startIndex: 25, type: 'white.rust' },
- { startIndex: 26, type: 'operator.rust' },
- { startIndex: 27, type: 'white.rust' },
- { startIndex: 28, type: 'string.quote.rust' },
- { startIndex: 29, type: 'string.rust' },
- { startIndex: 33, type: 'string.quote.rust' }
- ]
- }
- ],
- // Type Keywords
- [
- {
- line: 'let logical: bool = true',
- tokens: [
- { startIndex: 0, type: 'keyword.rust' },
- { startIndex: 3, type: 'white.rust' },
- { startIndex: 4, type: 'identifier.rust' },
- { startIndex: 11, type: 'operator.rust' },
- { startIndex: 12, type: 'white.rust' },
- { startIndex: 13, type: 'keyword.type.rust' },
- { startIndex: 17, type: 'white.rust' },
- { startIndex: 18, type: 'operator.rust' },
- { startIndex: 19, type: 'white.rust' },
- { startIndex: 20, type: 'keyword.rust' }
- ]
- }
- ],
- // Numbers
- // Integer
- [
- {
- line: '1000_000_00u32',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ],
- // Float
- [
- {
- line: '1.0f32',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ],
- // Hex
- [
- {
- line: '0xFA_01i32',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ],
- // Exponent
- [
- {
- line: '1.0E-8234987_f64',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ],
- // Binary
- [
- {
- line: '0b0_1u8',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ],
- // Octal
- [
- {
- line: '0o0000_0010u64',
- tokens: [{ startIndex: 0, type: 'number.rust' }]
- }
- ]
- ]);
|