diff --git a/Sources/DiffableTextKit/Models/Proposal.swift b/Sources/DiffableTextKit/Models/Proposal.swift index c080da52..b42c1d88 100644 --- a/Sources/DiffableTextKit/Models/Proposal.swift +++ b/Sources/DiffableTextKit/Models/Proposal.swift @@ -70,7 +70,7 @@ public struct Proposal { /// Returns a lazy snapshot with the proposed change applied to it. @inlinable public func merged() -> LazySequence]>> {[ proposal.base[.. String { + value + } + + @inlinable public func interpret(_ value: String, with cache: inout Void) -> Commit { + Commit(value, Snapshot(value)) + } + + @inlinable public func resolve(_ proposal: Proposal, with cache: inout Void) throws -> Commit { + let S0 = Snapshot(proposal.lazy.merged().nonvirtuals()); return Commit(S0.characters, S0) + } +} + +//*============================================================================* +// MARK: * Normal x Init +//*============================================================================* + +extension DiffableTextStyle where Self == NormalTextStyle { + + //=------------------------------------------------------------------------= + // MARK: Initializers + //=------------------------------------------------------------------------= + + /// A normal text style, without bells and whistles. + @inlinable @inline(__always) public static var normal: Self { .init() } +} diff --git a/Sources/DiffableTextKitXPattern/Style.swift b/Sources/DiffableTextKitXPattern/Style.swift index 31e042cf..ebdab7c0 100644 --- a/Sources/DiffableTextKitXPattern/Style.swift +++ b/Sources/DiffableTextKitXPattern/Style.swift @@ -210,7 +210,7 @@ extension PatternTextStyle { //=----------------------------------= // Position == Placeholder //=----------------------------------= - if let predicate = placeholders[pattern[qIndex]] { + if let predicate = placeholders[pattern[qIndex]] { guard cIndex != content.endIndex else { break matches } let nonvirtual = content[cIndex] guard predicate(nonvirtual) /**/ else { break matches } diff --git a/Sources/DiffableTextViews/Exports.swift b/Sources/DiffableTextViews/Exports.swift index b9a549c8..b7b1bc79 100644 --- a/Sources/DiffableTextViews/Exports.swift +++ b/Sources/DiffableTextViews/Exports.swift @@ -18,6 +18,8 @@ @_exported import struct DiffableTextKit.EqualsTextStyle +@_exported import struct DiffableTextKit.NormalTextStyle + @_exported import struct DiffableTextKit.StandaloneTextStyle @_exported import struct DiffableTextKit.PrefixTextStyle diff --git a/Tests/DiffableTextKitTests/Styles/Normal.swift b/Tests/DiffableTextKitTests/Styles/Normal.swift new file mode 100644 index 00000000..278fe0db --- /dev/null +++ b/Tests/DiffableTextKitTests/Styles/Normal.swift @@ -0,0 +1,52 @@ +//=----------------------------------------------------------------------------= +// This source file is part of the DiffableTextViews open source project. +// +// Copyright (c) 2022 Oscar Byström Ericsson +// Licensed under Apache License, Version 2.0 +// +// See http://www.apache.org/licenses/LICENSE-2.0 for license information. +//=----------------------------------------------------------------------------= + +#if DEBUG + +@testable import DiffableTextKit + +import XCTest + +//*============================================================================* +// MARK: * Normal x Tests +//*============================================================================* + +final class NormalTests: XCTestCase { + + //=------------------------------------------------------------------------= + // MARK: State + //=------------------------------------------------------------------------= + + let normal = NormalTextStyle() + + //=------------------------------------------------------------------------= + // MARK: Tests + //=------------------------------------------------------------------------= + + func testFormat() { + XCTAssertEqual(normal.format("2"), "2") + } + + func testInterpret() { + XCTAssertEqual(normal.interpret("3"), Commit("3", "3")) + } + + func testResolve() { + let base = Snapshot("13") + Snapshot("o(><)o", as: .phantom) + let middle = base.index(base.startIndex, offsetBy: 1) + let proposal = Proposal(base, with: "2", in: middle ..< middle) + + let resolved = try! normal.resolve(proposal) + + XCTAssertEqual(resolved.value, "123") + XCTAssertEqual(resolved.snapshot, "123") + } +} + +#endif