v1.4.0 release: live-coding scratch editor, interpreted Graph DSL, ClosureSynthesizer + SampleLoop
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// DSLLexerTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import LyrebirdGraphDSL
|
||||
|
||||
@Suite("DSLLexer")
|
||||
struct DSLLexerTests {
|
||||
|
||||
private func kinds(_ source: String) throws -> [DSLToken.Kind] {
|
||||
try DSLLexer.tokenize(source).map { $0.kind }
|
||||
}
|
||||
|
||||
@Test func tokenizesACall() throws {
|
||||
#expect(try kinds("OscSin(freq: 440)") == [
|
||||
.identifier, .leftParen, .identifier, .colon, .number, .rightParen, .eof,
|
||||
])
|
||||
}
|
||||
|
||||
@Test func tokenizesOperatorsAndParens() throws {
|
||||
#expect(try kinds("(a + b) * 0.5") == [
|
||||
.leftParen, .identifier, .plus, .identifier, .rightParen, .star, .number, .eof,
|
||||
])
|
||||
}
|
||||
|
||||
@Test func skipsCommentsAndCollapsesNewlines() throws {
|
||||
#expect(try kinds("a # comment\n\n\nb") == [
|
||||
.identifier, .newline, .identifier, .eof,
|
||||
])
|
||||
}
|
||||
|
||||
@Test func numberFormsAndUnderscores() throws {
|
||||
let toks: [DSLToken] = try DSLLexer.tokenize("440 0.15 2e3 44_100")
|
||||
let numbers: [String] = toks.filter { $0.kind == .number }.map { $0.text }
|
||||
#expect(numbers == ["440", "0.15", "2e3", "44_100"])
|
||||
}
|
||||
|
||||
@Test func unexpectedCharacterThrows() {
|
||||
#expect(throws: DSLParseError.self) {
|
||||
_ = try DSLLexer.tokenize("a @ b")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func spansCoverSourceText() throws {
|
||||
let toks: [DSLToken] = try DSLLexer.tokenize("OscSin")
|
||||
#expect(toks.first?.span == DSLSpan(start: 0, end: 6))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user