@neo4j-cypher/language-support
Version:
Cypher language support
2,325 lines (2,298 loc) • 88.5 kB
text/typescript
import { applySyntaxColouring } from '../../syntaxColouring/syntaxColouring';
describe('Administration commands syntax colouring', () => {
test('Correctly colours SHOW INDEXES', () => {
const query = 'SHOW INDEXES YIELD *';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'INDEXES',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 13,
startOffset: 13,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 19,
startOffset: 19,
},
token: '*',
tokenType: 'operator',
},
]);
});
test('Correctly colours CREATE INDEX', () => {
const query = 'CREATE INDEX index_name FOR (p:Person) ON (p.name)';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'CREATE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 7,
startOffset: 7,
},
token: 'INDEX',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 13,
startOffset: 13,
},
token: 'index_name',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 24,
startOffset: 24,
},
token: 'FOR',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 0,
startCharacter: 28,
startOffset: 28,
},
token: '(',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 29,
startOffset: 29,
},
token: 'p',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 30,
startOffset: 30,
},
token: ':',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 31,
startOffset: 31,
},
token: 'Person',
tokenType: 'label',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 0,
startCharacter: 37,
startOffset: 37,
},
token: ')',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 39,
startOffset: 39,
},
token: 'ON',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 0,
startCharacter: 42,
startOffset: 42,
},
token: '(',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 43,
startOffset: 43,
},
token: 'p',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 44,
startOffset: 44,
},
token: '.',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 45,
startOffset: 45,
},
token: 'name',
tokenType: 'property',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 0,
startCharacter: 49,
startOffset: 49,
},
token: ')',
tokenType: 'bracket',
},
]);
});
test('Correctly colours DROP INDEX', () => {
const query = 'DROP INDEX index_name';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'DROP',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'INDEX',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 11,
startOffset: 11,
},
token: 'index_name',
tokenType: 'symbolicName',
},
]);
});
test('Correctly colours SHOW CONSTRAINTS', () => {
const query = 'SHOW ALL CONSTRAINTS YIELD *';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'ALL',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 11,
position: {
line: 0,
startCharacter: 9,
startOffset: 9,
},
token: 'CONSTRAINTS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 21,
startOffset: 21,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 27,
startOffset: 27,
},
token: '*',
tokenType: 'operator',
},
]);
});
test('Correctly colours CREATE CONSTRAINT', () => {
const query = `CREATE CONSTRAINT constraint_name IF NOT EXISTS
FOR (p:Person)
REQUIRE p.name IS UNIQUE
OPTIONS {
indexProvider: 'range-1.0'
}`;
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'CREATE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 7,
startOffset: 7,
},
token: 'CONSTRAINT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 15,
position: {
line: 0,
startCharacter: 18,
startOffset: 18,
},
token: 'constraint_name',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 34,
startOffset: 34,
},
token: 'IF',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 37,
startOffset: 37,
},
token: 'NOT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 41,
startOffset: 41,
},
token: 'EXISTS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 1,
startCharacter: 6,
startOffset: 54,
},
token: 'FOR',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 1,
startCharacter: 10,
startOffset: 58,
},
token: '(',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 1,
startCharacter: 11,
startOffset: 59,
},
token: 'p',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 1,
startCharacter: 12,
startOffset: 60,
},
token: ':',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 1,
startCharacter: 13,
startOffset: 61,
},
token: 'Person',
tokenType: 'label',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'parenthesis',
},
length: 1,
position: {
line: 1,
startCharacter: 19,
startOffset: 67,
},
token: ')',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 2,
startCharacter: 6,
startOffset: 75,
},
token: 'REQUIRE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 2,
startCharacter: 14,
startOffset: 83,
},
token: 'p',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 2,
startCharacter: 15,
startOffset: 84,
},
token: '.',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 2,
startCharacter: 16,
startOffset: 85,
},
token: 'name',
tokenType: 'property',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 2,
startCharacter: 21,
startOffset: 90,
},
token: 'IS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 2,
startCharacter: 24,
startOffset: 93,
},
token: 'UNIQUE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 3,
startCharacter: 6,
startOffset: 106,
},
token: 'OPTIONS',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'curly',
},
length: 1,
position: {
line: 3,
startCharacter: 14,
startOffset: 114,
},
token: '{',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 13,
position: {
line: 4,
startCharacter: 8,
startOffset: 124,
},
token: 'indexProvider',
tokenType: 'property',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 4,
startCharacter: 21,
startOffset: 137,
},
token: ':',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 11,
position: {
line: 4,
startCharacter: 23,
startOffset: 139,
},
token: "'range-1.0'",
tokenType: 'stringLiteral',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'curly',
},
length: 1,
position: {
line: 5,
startCharacter: 6,
startOffset: 157,
},
token: '}',
tokenType: 'bracket',
},
]);
});
test('Correctly colours DROP CONSTRAINT', () => {
const query = 'DROP CONSTRAINT constraint_name IF EXISTS';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'DROP',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'CONSTRAINT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 15,
position: {
line: 0,
startCharacter: 16,
startOffset: 16,
},
token: 'constraint_name',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 32,
startOffset: 32,
},
token: 'IF',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 35,
startOffset: 35,
},
token: 'EXISTS',
tokenType: 'keyword',
},
]);
});
test('Correctly colours SHOW FUNCTIONS', () => {
const query = 'SHOW FUNCTIONS EXECUTABLE BY user_name';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'FUNCTIONS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 15,
startOffset: 15,
},
token: 'EXECUTABLE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 26,
startOffset: 26,
},
token: 'BY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 0,
startCharacter: 29,
startOffset: 29,
},
token: 'user_name',
tokenType: 'symbolicName',
},
]);
});
test('Correctly colours SHOW PROCEDURES', () => {
const query = 'SHOW PROCEDURES EXECUTABLE BY user_name';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'PROCEDURES',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 16,
startOffset: 16,
},
token: 'EXECUTABLE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 27,
startOffset: 27,
},
token: 'BY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 0,
startCharacter: 30,
startOffset: 30,
},
token: 'user_name',
tokenType: 'symbolicName',
},
]);
});
test('Correctly colours SHOW SETTINGS', () => {
const query =
"SHOW SETTINGS 'server.bolt.advertised_address', 'server.bolt.listen_address' YIELD *";
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'SETTINGS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 32,
position: {
line: 0,
startCharacter: 14,
startOffset: 14,
},
token: "'server.bolt.advertised_address'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 46,
startOffset: 46,
},
token: ',',
tokenType: 'separator',
},
{
bracketInfo: undefined,
length: 28,
position: {
line: 0,
startCharacter: 48,
startOffset: 48,
},
token: "'server.bolt.listen_address'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 77,
startOffset: 77,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 83,
startOffset: 83,
},
token: '*',
tokenType: 'operator',
},
]);
});
test('Correctly colours SHOW TRANSACTION / TERMINATE TRANSACTIONS', () => {
const query = `SHOW TRANSACTIONS
YIELD transactionId AS txId, username
WHERE username = 'user_name'
TERMINATE TRANSACTIONS txId
YIELD message
WHERE NOT message = 'Transaction terminated.'
RETURN txId
`;
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 12,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'TRANSACTIONS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 1,
startCharacter: 6,
startOffset: 24,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 13,
position: {
line: 1,
startCharacter: 12,
startOffset: 30,
},
token: 'transactionId',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 1,
startCharacter: 26,
startOffset: 44,
},
token: 'AS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 1,
startCharacter: 29,
startOffset: 47,
},
token: 'txId',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 1,
startCharacter: 33,
startOffset: 51,
},
token: ',',
tokenType: 'separator',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 1,
startCharacter: 35,
startOffset: 53,
},
token: 'username',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 2,
startCharacter: 6,
startOffset: 68,
},
token: 'WHERE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 2,
startCharacter: 12,
startOffset: 74,
},
token: 'username',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 2,
startCharacter: 21,
startOffset: 83,
},
token: '=',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 11,
position: {
line: 2,
startCharacter: 23,
startOffset: 85,
},
token: "'user_name'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 3,
startCharacter: 4,
startOffset: 101,
},
token: 'TERMINATE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 12,
position: {
line: 3,
startCharacter: 14,
startOffset: 111,
},
token: 'TRANSACTIONS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 3,
startCharacter: 27,
startOffset: 124,
},
token: 'txId',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 4,
startCharacter: 6,
startOffset: 135,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 4,
startCharacter: 12,
startOffset: 141,
},
token: 'message',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 5,
startCharacter: 6,
startOffset: 155,
},
token: 'WHERE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 5,
startCharacter: 12,
startOffset: 161,
},
token: 'NOT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 5,
startCharacter: 16,
startOffset: 165,
},
token: 'message',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 5,
startCharacter: 24,
startOffset: 173,
},
token: '=',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 25,
position: {
line: 5,
startCharacter: 26,
startOffset: 175,
},
token: "'Transaction terminated.'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 6,
startCharacter: 6,
startOffset: 207,
},
token: 'RETURN',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 6,
startCharacter: 13,
startOffset: 214,
},
token: 'txId',
tokenType: 'variable',
},
]);
});
test('Correctly colours CREATE DATABASE', () => {
const query =
'CREATE DATABASE `topology-example` IF NOT EXISTS TOPOLOGY 1 PRIMARY 0 SECONDARIES';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'CREATE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 7,
startOffset: 7,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 18,
position: {
line: 0,
startCharacter: 16,
startOffset: 16,
},
token: '`topology-example`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 35,
startOffset: 35,
},
token: 'IF',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 38,
startOffset: 38,
},
token: 'NOT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 42,
startOffset: 42,
},
token: 'EXISTS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 49,
startOffset: 49,
},
token: 'TOPOLOGY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 58,
startOffset: 58,
},
token: '1',
tokenType: 'numberLiteral',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 0,
startCharacter: 60,
startOffset: 60,
},
token: 'PRIMARY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 68,
startOffset: 68,
},
token: '0',
tokenType: 'numberLiteral',
},
{
bracketInfo: undefined,
length: 11,
position: {
line: 0,
startCharacter: 70,
startOffset: 70,
},
token: 'SECONDARIES',
tokenType: 'keyword',
},
]);
});
test('Correctly colours START DATABASE', () => {
const query = 'START DATABASE `database-name`';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'START',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 6,
startOffset: 6,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 15,
position: {
line: 0,
startCharacter: 15,
startOffset: 15,
},
token: '`database-name`',
tokenType: 'symbolicName',
},
]);
});
test('Correctly colours STOP DATABASE', () => {
const query = 'STOP DATABASE `database-name`';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'STOP',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 15,
position: {
line: 0,
startCharacter: 14,
startOffset: 14,
},
token: '`database-name`',
tokenType: 'symbolicName',
},
]);
});
test('Correctly colours ALTER DATABASE', () => {
const query =
'ALTER DATABASE `topology-example` SET TOPOLOGY 1 PRIMARY SET ACCESS READ ONLY';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'ALTER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 6,
startOffset: 6,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 18,
position: {
line: 0,
startCharacter: 15,
startOffset: 15,
},
token: '`topology-example`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 34,
startOffset: 34,
},
token: 'SET',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 38,
startOffset: 38,
},
token: 'TOPOLOGY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 47,
startOffset: 47,
},
token: '1',
tokenType: 'numberLiteral',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 0,
startCharacter: 49,
startOffset: 49,
},
token: 'PRIMARY',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 57,
startOffset: 57,
},
token: 'SET',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 61,
startOffset: 61,
},
token: 'ACCESS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 68,
startOffset: 68,
},
token: 'READ',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 73,
startOffset: 73,
},
token: 'ONLY',
tokenType: 'keyword',
},
]);
});
test('Correctly colours SHOW DATABASES', () => {
const query = `SHOW DATABASES
YIELD name, currentStatus
WHERE name CONTAINS 'my'
AND currentStatus = 'online'
`;
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'SHOW',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'DATABASES',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 1,
startCharacter: 6,
startOffset: 21,
},
token: 'YIELD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 1,
startCharacter: 12,
startOffset: 27,
},
token: 'name',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 1,
startCharacter: 16,
startOffset: 31,
},
token: ',',
tokenType: 'separator',
},
{
bracketInfo: undefined,
length: 13,
position: {
line: 1,
startCharacter: 18,
startOffset: 33,
},
token: 'currentStatus',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 2,
startCharacter: 6,
startOffset: 53,
},
token: 'WHERE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 2,
startCharacter: 12,
startOffset: 59,
},
token: 'name',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 2,
startCharacter: 17,
startOffset: 64,
},
token: 'CONTAINS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 2,
startCharacter: 26,
startOffset: 73,
},
token: "'my'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 3,
startCharacter: 6,
startOffset: 84,
},
token: 'AND',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 13,
position: {
line: 3,
startCharacter: 10,
startOffset: 88,
},
token: 'currentStatus',
tokenType: 'variable',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 3,
startCharacter: 24,
startOffset: 102,
},
token: '=',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 3,
startCharacter: 26,
startOffset: 104,
},
token: "'online'",
tokenType: 'stringLiteral',
},
]);
});
test('Correctly colours CREATE ALIAS', () => {
const query = `CREATE OR REPLACE ALIAS \`composite-database-name\`.\`alias-in-composite-name\`
FOR DATABASE \`database-name\`
AT $url
USER user_name
PASSWORD $password
PROPERTIES { property: $value }
`;
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'CREATE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 7,
startOffset: 7,
},
token: 'OR',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 0,
startCharacter: 10,
startOffset: 10,
},
token: 'REPLACE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 18,
startOffset: 18,
},
token: 'ALIAS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 25,
position: {
line: 0,
startCharacter: 24,
startOffset: 24,
},
token: '`composite-database-name`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 49,
startOffset: 49,
},
token: '.',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 25,
position: {
line: 0,
startCharacter: 50,
startOffset: 50,
},
token: '`alias-in-composite-name`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 1,
startCharacter: 6,
startOffset: 83,
},
token: 'FOR',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 1,
startCharacter: 10,
startOffset: 87,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 15,
position: {
line: 1,
startCharacter: 19,
startOffset: 96,
},
token: '`database-name`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 2,
startCharacter: 6,
startOffset: 118,
},
token: 'AT',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 2,
startCharacter: 9,
startOffset: 121,
},
token: '$',
tokenType: 'paramDollar',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 2,
startCharacter: 10,
startOffset: 122,
},
token: 'url',
tokenType: 'paramValue',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 3,
startCharacter: 6,
startOffset: 132,
},
token: 'USER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 3,
startCharacter: 11,
startOffset: 137,
},
token: 'user_name',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 4,
startCharacter: 6,
startOffset: 153,
},
token: 'PASSWORD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 4,
startCharacter: 15,
startOffset: 162,
},
token: '$',
tokenType: 'paramDollar',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 4,
startCharacter: 16,
startOffset: 163,
},
token: 'password',
tokenType: 'paramValue',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 5,
startCharacter: 6,
startOffset: 178,
},
token: 'PROPERTIES',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'curly',
},
length: 1,
position: {
line: 5,
startCharacter: 17,
startOffset: 189,
},
token: '{',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 5,
startCharacter: 19,
startOffset: 191,
},
token: 'property',
tokenType: 'property',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 5,
startCharacter: 27,
startOffset: 199,
},
token: ':',
tokenType: 'operator',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 5,
startCharacter: 29,
startOffset: 201,
},
token: '$',
tokenType: 'paramDollar',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 5,
startCharacter: 30,
startOffset: 202,
},
token: 'value',
tokenType: 'paramValue',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'curly',
},
length: 1,
position: {
line: 5,
startCharacter: 36,
startOffset: 208,
},
token: '}',
tokenType: 'bracket',
},
]);
});
test('Correctly colours ALTER ALIAS', () => {
const query = `ALTER ALIAS \`remote-database-alias\` IF EXISTS
SET DATABASE
USER user_name
PASSWORD $password
`;
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'ALTER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 6,
startOffset: 6,
},
token: 'ALIAS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 23,
position: {
line: 0,
startCharacter: 12,
startOffset: 12,
},
token: '`remote-database-alias`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 36,
startOffset: 36,
},
token: 'IF',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 39,
startOffset: 39,
},
token: 'EXISTS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 1,
startCharacter: 6,
startOffset: 52,
},
token: 'SET',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 1,
startCharacter: 10,
startOffset: 56,
},
token: 'DATABASE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 4,
position: {
line: 2,
startCharacter: 6,
startOffset: 71,
},
token: 'USER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 9,
position: {
line: 2,
startCharacter: 11,
startOffset: 76,
},
token: 'user_name',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 3,
startCharacter: 6,
startOffset: 92,
},
token: 'PASSWORD',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 3,
startCharacter: 15,
startOffset: 101,
},
token: '$',
tokenType: 'paramDollar',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 3,
startCharacter: 16,
startOffset: 102,
},
token: 'password',
tokenType: 'paramValue',
},
]);
});
test('Correctly colours DROP ALIAS', () => {
const query = 'DROP ALIAS `database-alias` IF EXISTS FOR DATABASE';
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 4,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'DROP',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 5,
startOffset: 5,
},
token: 'ALIAS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 16,
position: {
line: 0,
startCharacter: 11,
startOffset: 11,
},
token: '`database-alias`',
tokenType: 'symbolicName',
},
{
bracketInfo: undefined,
length: 2,
position: {
line: 0,
startCharacter: 28,
startOffset: 28,
},
token: 'IF',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 31,
startOffset: 31,
},
token: 'EXISTS',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 38,
startOffset: 38,
},
token: 'FOR',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 8,
position: {
line: 0,
startCharacter: 42,
startOffset: 42,
},
token: 'DATABASE',
tokenType: 'keyword',
},
]);
});
test('Correctly colours ENABLE SERVER', () => {
const query = "ENABLE SERVER 'serverId'";
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'ENABLE',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 7,
startOffset: 7,
},
token: 'SERVER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 10,
position: {
line: 0,
startCharacter: 14,
startOffset: 14,
},
token: "'serverId'",
tokenType: 'stringLiteral',
},
]);
});
test('Correctly colours ALTER SERVER', () => {
const query = "ALTER SERVER 'name' SET OPTIONS {modeConstraint: 'PRIMARY'}";
expect(applySyntaxColouring(query)).toEqual([
{
bracketInfo: undefined,
length: 5,
position: {
line: 0,
startCharacter: 0,
startOffset: 0,
},
token: 'ALTER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 6,
startOffset: 6,
},
token: 'SERVER',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 6,
position: {
line: 0,
startCharacter: 13,
startOffset: 13,
},
token: "'name'",
tokenType: 'stringLiteral',
},
{
bracketInfo: undefined,
length: 3,
position: {
line: 0,
startCharacter: 20,
startOffset: 20,
},
token: 'SET',
tokenType: 'keyword',
},
{
bracketInfo: undefined,
length: 7,
position: {
line: 0,
startCharacter: 24,
startOffset: 24,
},
token: 'OPTIONS',
tokenType: 'keyword',
},
{
bracketInfo: {
bracketLevel: 0,
bracketType: 'curly',
},
length: 1,
position: {
line: 0,
startCharacter: 32,
startOffset: 32,
},
token: '{',
tokenType: 'bracket',
},
{
bracketInfo: undefined,
length: 14,
position: {
line: 0,
startCharacter: 33,
startOffset: 33,
},
token: 'modeConstraint',
tokenType: 'property',
},
{
bracketInfo: undefined,
length: 1,
position: {
line: 0,
startCharacter: 47,
startOffset: 47,
},
token: ':',
tokenType: 'operator',
},
{
bracketInfo: unde