56 lines
2.0 KiB
Swift
56 lines
2.0 KiB
Swift
// GraphDSLDiagnosticMapperTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#if os(macOS)
|
|
import Testing
|
|
import LyrebirdGraphDSLEmbedded
|
|
@testable import LyrebirdLiveCompile
|
|
|
|
@Suite("GraphDSLDiagnosticMapper")
|
|
struct GraphDSLDiagnosticMapperTests {
|
|
|
|
@Test
|
|
func parseErrorMapsSpanToLineAndColumn() {
|
|
// Offset 4 in "abc\nX" → line 2, column 1 (the char after the newline).
|
|
let span: DSLSpan = DSLSpan.point(4)
|
|
let error: DSLParseError = DSLParseError(kind: .unexpectedCharacter("%"), span: span)
|
|
let diags: [Diagnostic] = GraphDSLDiagnosticMapper.diagnostics(for: error, source: "abc\n%")
|
|
#expect(diags.count == 1)
|
|
#expect(diags[0].line == 2)
|
|
#expect(diags[0].column == 1)
|
|
#expect(diags[0].severity == .error)
|
|
#expect(diags[0].message.contains("unexpected"))
|
|
}
|
|
|
|
@Test
|
|
func firstColumnOfFirstLineIsOneOne() {
|
|
let error: DSLParseError = DSLParseError(kind: .unclosedParen, span: DSLSpan.point(0))
|
|
let diags: [Diagnostic] = GraphDSLDiagnosticMapper.diagnostics(for: error, source: "OscSin(")
|
|
#expect(diags[0].line == 1)
|
|
#expect(diags[0].column == 1)
|
|
}
|
|
|
|
@Test
|
|
func buildErrorHasNoLine() {
|
|
let error: DSLBuildError = DSLBuildError.unknownBuiltin("Nope")
|
|
let diags: [Diagnostic] = GraphDSLDiagnosticMapper.diagnostics(for: error, source: "Nope()")
|
|
#expect(diags.count == 1)
|
|
#expect(diags[0].line == nil)
|
|
#expect(diags[0].message.contains("Nope"))
|
|
}
|
|
|
|
@Test
|
|
func offsetPastEndClampsToFinalPosition() {
|
|
let error: DSLParseError = DSLParseError(kind: .unclosedParen, span: DSLSpan.point(1_000))
|
|
let diags: [Diagnostic] = GraphDSLDiagnosticMapper.diagnostics(for: error, source: "ab\ncd")
|
|
// Two lines, second is "cd": clamps to line 2, column 3 (past 'd').
|
|
#expect(diags[0].line == 2)
|
|
#expect(diags[0].column == 3)
|
|
}
|
|
}
|
|
|
|
#endif
|