Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lvce-editor/test-syntax-highlighting
test syntax highlighting functions
https://github.com/lvce-editor/test-syntax-highlighting
lvce-editor syntax-highlighting test
Last synced: 3 days ago
JSON representation
test syntax highlighting functions
- Host: GitHub
- URL: https://github.com/lvce-editor/test-syntax-highlighting
- Owner: lvce-editor
- License: mit
- Created: 2022-06-18T20:18:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-26T17:31:33.000Z (20 days ago)
- Last Synced: 2024-10-26T19:17:16.016Z (20 days ago)
- Topics: lvce-editor, syntax-highlighting, test
- Language: JavaScript
- Homepage:
- Size: 347 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @lvce-editor/test-syntax-highlighting
Utility package for testing syntax highlighting functions for the lvce-editor.
## Install
```
$ npm install @lvce-editor/test-syntax-highlighting
```## Usage
Create an extension manifest:
```json
{
"id": "language-basics-xyz",
"languages": [
{
"id": "xyz",
"extensions": [".xyz"],
"tokenize": "src/tokenizeXyz.js"
}
]
}
```Then create the tokenize function
```js
// src/tokenizeXyz.js
export const TokenType = {
Text: 1,
}export const TokenMap = {
[TokenType.Text]: 'Text',
}export const initialLineState = {
state: 1,
tokens: [],
}export const hasArrayReturn = true
export const tokenizeLine = (line) => {
const tokens = [TokenType.Text, line.length]
return {
state: 1,
tokens,
}
}
```Then add sample code into `test/cases/sample-code.xyz`
```
sample xyz code
```Then a test script to your package json file
```json
{
"scripts": {
"test": "test-syntax-highlighting"
}
}
```Then run `npm test` which will create `test/baselines/sample-code.txt`. That file contains the tokens that were generated by the tokenizeLine function for `test/cases/sample-code.xyz`:
```
Text
```## Successful tests
When the tests succeed, you will get output similar to this:
```
> test-syntax-highlighting1 test passed in 4ms
```## Failing tests
When a test fails, you will get output similar to this:
```
mismatch sample-code
1 test failed, 0 tests passed
```When that happens, you need can either
- adjust your tokenize function to output the tokens specified in `test/baselines/sample-code.txt` or
- delete `test/baselines/sample-code.txt` and rerun `npm test` to regenerate the expected tokens in `test/baselines/sample-code.txt`