2024-04-15 17:18:32 -07:00
|
|
|
import { kclErrorsToDiagnostics, KCLError } from './errors'
|
2025-01-17 14:34:36 -05:00
|
|
|
import { defaultArtifactGraph, topLevelRange } from 'lang/wasm'
|
2023-08-08 10:50:27 +10:00
|
|
|
|
|
|
|
describe('test kclErrToDiagnostic', () => {
|
|
|
|
it('converts KCL errors to CodeMirror diagnostics', () => {
|
|
|
|
const errors: KCLError[] = [
|
|
|
|
{
|
2024-06-24 11:45:40 -04:00
|
|
|
name: '',
|
|
|
|
message: '',
|
2023-08-08 10:50:27 +10:00
|
|
|
kind: 'semantic',
|
|
|
|
msg: 'Semantic error',
|
2025-01-17 14:34:36 -05:00
|
|
|
sourceRange: topLevelRange(0, 1),
|
2024-12-16 13:10:31 -05:00
|
|
|
operations: [],
|
2025-01-08 20:02:30 -05:00
|
|
|
artifactCommands: [],
|
2025-01-17 14:34:36 -05:00
|
|
|
artifactGraph: defaultArtifactGraph(),
|
2023-08-08 10:50:27 +10:00
|
|
|
},
|
|
|
|
{
|
2024-06-24 11:45:40 -04:00
|
|
|
name: '',
|
|
|
|
message: '',
|
2023-08-08 10:50:27 +10:00
|
|
|
kind: 'type',
|
|
|
|
msg: 'Type error',
|
2025-01-17 14:34:36 -05:00
|
|
|
sourceRange: topLevelRange(4, 5),
|
2024-12-16 13:10:31 -05:00
|
|
|
operations: [],
|
2025-01-08 20:02:30 -05:00
|
|
|
artifactCommands: [],
|
2025-01-17 14:34:36 -05:00
|
|
|
artifactGraph: defaultArtifactGraph(),
|
2023-08-08 10:50:27 +10:00
|
|
|
},
|
|
|
|
]
|
2024-04-15 17:18:32 -07:00
|
|
|
const diagnostics = kclErrorsToDiagnostics(errors)
|
2023-08-08 10:50:27 +10:00
|
|
|
expect(diagnostics).toEqual([
|
|
|
|
{
|
|
|
|
from: 0,
|
|
|
|
to: 1,
|
|
|
|
message: 'Semantic error',
|
|
|
|
severity: 'error',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: 4,
|
|
|
|
to: 5,
|
|
|
|
message: 'Type error',
|
|
|
|
severity: 'error',
|
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|