Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/Splash/Syntax/SyntaxHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public struct SyntaxHighlighter<Format: OutputFormat> {
state = (token, type)
return
}

builder.addToken(token, ofType: type)
if token != whitespace {
builder.addToken(token, ofType: type)
}
builder.addWhitespace(whitespace)
state = nil
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/Splash/Theming/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public struct Font {
resource = .system
self.size = size
}

/// Initialize an instance with an existing, custom, font.
public init(_ font: Loaded) {
resource = .preloaded(font)
self.size = Double(font.pointSize)
}
}

public extension Font {
Expand Down
58 changes: 58 additions & 0 deletions Tests/SplashTests/Tests/AttributedStringTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#if !os(Linux)

import Foundation
import XCTest
import Splash

final class AttributedStringOutputFormatTests: SplashTestCase {
private var highlighter: SyntaxHighlighter<AttributedStringOutputFormat>!

override func setUp() {
super.setUp()
highlighter = SyntaxHighlighter(format: AttributedStringOutputFormat(theme: Theme.presentation(withFont: .init(size: 15))))
}

func testBasicAttributedStringOutputMatchesInput() {
let input = """
public struct Test: SomeProtocol {
func hello() -> Int { return 7 }
}
"""
let output = highlighter.highlight(input)
XCTAssertEqual(input, output.string)
}

func testNewlinesAttributedStringOutputMatchesInput() {
let input = """

typealias a = b
typealias b = c

print("hello")
"""
let output = highlighter.highlight(input)
XCTAssertEqual(input, output.string)
}

func testInnerNewlinesAttributedStringOutputMatchesInput() {
let input = """
typealias a = b
typealias b = c

print("hello")

print("hello")
print("hello")


print("hello")
"""
let output = highlighter.highlight(input)
XCTAssertEqual(input, output.string)
}

func testAllTestsRunOnLinux() {
}
}

#endif