Back to Repositories

Testing CameLIGO Syntax Tokenization Implementation in monaco-editor

This test suite validates the tokenization functionality for the CameLIGO language syntax in Monaco Editor, focusing on syntax highlighting and token parsing capabilities.

Test Coverage Overview

The test suite provides comprehensive coverage for CameLIGO syntax tokenization, including:

  • Single-line and multi-line comment parsing
  • Keyword identification and highlighting
  • Number format validation (integers, floats, hexadecimal)
  • Delimiter and whitespace handling

Implementation Analysis

The testing approach utilizes Monaco Editor’s testTokenization framework to verify token classification and syntax highlighting rules. Each test case defines expected token types and their corresponding string indices, ensuring accurate lexical analysis of CameLIGO code elements.

The implementation follows a pattern-based testing strategy, examining various syntax combinations and edge cases.

Technical Details

Testing infrastructure includes:

  • Monaco Editor’s built-in test runner
  • Custom token validation utilities
  • Structured test cases with line-by-line token mapping
  • Support for multiple token types: comments, keywords, numbers, delimiters

Best Practices Demonstrated

The test suite exemplifies high-quality testing practices through systematic organization and comprehensive coverage. Notable aspects include:

  • Granular test cases for individual syntax elements
  • Explicit token boundary testing
  • Clear separation of test scenarios
  • Thorough validation of language-specific features

microsoft/monaco-editor

src/basic-languages/cameligo/cameligo.test.ts

            
/*---------------------------------------------------------------------------------------------
 *  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('cameligo', [
	// Comments - single line
	[
		{
			line: '//',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	[
		{
			line: '    // a comment',
			tokens: [
				{ startIndex: 0, type: 'white.cameligo' },
				{ startIndex: 4, type: 'comment.cameligo' }
			]
		}
	],

	[
		{
			line: '// a comment',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	[
		{
			line: '//sticky comment',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	// Comments - multi line (single line)
	[
		{
			line: '(**)',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	[
		{
			line: '    (* a comment *)',
			tokens: [
				{ startIndex: 0, type: 'white.cameligo' },
				{ startIndex: 4, type: 'comment.cameligo' }
			]
		}
	],

	[
		{
			line: '(* a comment *)',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	[
		{
			line: '(*sticky comment*)',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	// Comments - multi line (multi line)
	[
		{
			line: '(* start of multiline comment ',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		},
		{
			line: 'a comment between curly',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		},
		{
			line: 'end of multiline comment*)',
			tokens: [{ startIndex: 0, type: 'comment.cameligo' }]
		}
	],

	// Keywords
	[
		{
			line: 'let check if Current.amount',
			tokens: [
				{ startIndex: 0, type: 'keyword.let.cameligo' },
				{ startIndex: 3, type: 'white.cameligo' },
				{ startIndex: 4, type: 'identifier.cameligo' },
				{ startIndex: 9, type: 'white.cameligo' },
				{ startIndex: 10, type: 'keyword.if.cameligo' },
				{ startIndex: 12, type: 'white.cameligo' },
				{ startIndex: 13, type: 'keyword.current.cameligo' },
				{ startIndex: 20, type: 'delimiter.cameligo' },
				{ startIndex: 21, type: 'identifier.cameligo' }
			]
		}
	],

	// Numbers
	[
		{
			line: '0',
			tokens: [{ startIndex: 0, type: 'number.cameligo' }]
		}
	],
	[
		{
			line: '0;',
			tokens: [
				{ startIndex: 0, type: 'number.cameligo' },
				{ startIndex: 1, type: 'delimiter.cameligo' }
			]
		}
	],
	[
		{
			line: '2.4',
			tokens: [{ startIndex: 0, type: 'number.float.cameligo' }]
		}
	],
	[
		{
			line: '2.4;',
			tokens: [
				{ startIndex: 0, type: 'number.float.cameligo' },
				{ startIndex: 3, type: 'delimiter.cameligo' }
			]
		}
	],
	[
		{
			line: '$123FF',
			tokens: [{ startIndex: 0, type: 'number.hex.cameligo' }]
		}
	]
]);