-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
//=----------------------------------------------------------------------------= | ||
|
||
//*============================================================================* | ||
// MARK: * Normal | ||
//*============================================================================* | ||
|
||
/// A normal text style, without bells and whistles. | ||
public struct NormalTextStyle: DiffableTextStyle { | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Initializers | ||
//=------------------------------------------------------------------------= | ||
|
||
@inlinable @inline(__always) public init() { } | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Utilities | ||
//=------------------------------------------------------------------------= | ||
|
||
@inlinable @inline(__always) public func format(_ value: String, with cache: inout Void) -> String { | ||
value | ||
} | ||
|
||
@inlinable public func interpret(_ value: String, with cache: inout Void) -> Commit<String> { | ||
Commit(value, Snapshot(value)) | ||
} | ||
|
||
@inlinable public func resolve(_ proposal: Proposal, with cache: inout Void) throws -> Commit<String> { | ||
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() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |