47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
// SnippetHarnessTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
@testable import LyrebirdLiveCompile
|
|
|
|
#if os(macOS)
|
|
|
|
@Suite("SnippetHarness")
|
|
struct SnippetHarnessTests {
|
|
|
|
@Test
|
|
func wrappedSourceContainsPreambleAndUserBody() {
|
|
let wrapped: WrappedSnippet = SnippetHarness.wrap(userBody: "context.reportMessage(\"hello\")")
|
|
#expect(wrapped.source.contains("import LyrebirdSynth"))
|
|
#expect(wrapped.source.contains("import LyrebirdLiveCompile"))
|
|
#expect(wrapped.source.contains("@_cdecl(\"lyrebird_snippet_entry\")"))
|
|
#expect(wrapped.source.contains("Unmanaged<SnippetContext>"))
|
|
#expect(wrapped.source.contains("context.reportMessage(\"hello\")"))
|
|
}
|
|
|
|
@Test
|
|
func userBodyLineOffsetMatchesActualSourceLayout() {
|
|
let body: String = "let x = 1"
|
|
let wrapped: WrappedSnippet = SnippetHarness.wrap(userBody: body)
|
|
let lines: [String.SubSequence] = wrapped.source.split(separator: "\n", omittingEmptySubsequences: false)
|
|
// Line at index `offset - 1` (0-indexed) should be the first line of the body.
|
|
let bodyLineIndex: Int = wrapped.userBodyLineOffset - 1
|
|
#expect(bodyLineIndex >= 0)
|
|
#expect(bodyLineIndex < lines.count)
|
|
#expect(String(lines[bodyLineIndex]) == body)
|
|
}
|
|
|
|
@Test
|
|
func multilineUserBodyIsPreservedVerbatim() {
|
|
let body: String = "let a = 1\nlet b = 2\ncontext.reportMessage(\"\\(a + b)\")"
|
|
let wrapped: WrappedSnippet = SnippetHarness.wrap(userBody: body)
|
|
#expect(wrapped.source.contains(body))
|
|
}
|
|
}
|
|
|
|
#endif
|