Fix playback rate display dropping meaningful digits (#963)

PlaybackRate.displayText/compactDisplayText used String(format: "%.2gx"), whose significant-figure notation dropped meaningful digits (1.25 -> "1.2x") and rounded others (1.75 -> "1.8x"). Replace with a fixed two-decimal format + trailing-zero strip so whole rates have no decimal (2 -> "2x"), halves show one (1.5 -> "1.5x"), and quarter-steps are preserved (1.25 -> "1.25x"). Adds a Swift Testing suite (PlaybackRateTests) proving red->green.
This commit is contained in:
Yuri Chukhlib
2026-08-23 12:21:54 +02:00
committed by GitHub
parent 63b625bcde
commit 11d370b3b8
2 changed files with 66 additions and 2 deletions

View File

@@ -0,0 +1,51 @@
//
// PlaybackRateTests.swift
// YatteeTests
//
// Tests for PlaybackRate display-text formatting.
//
import Testing
import Foundation
@testable import Yattee
@Suite("PlaybackRate Display Tests")
struct PlaybackRateDisplayTests {
@Test("displayText renders every rate without losing precision")
func displayTextPrecision() {
#expect(PlaybackRate.x025.displayText == "0.25x")
#expect(PlaybackRate.x05.displayText == "0.5x")
#expect(PlaybackRate.x075.displayText == "0.75x")
#expect(PlaybackRate.x125.displayText == "1.25x")
#expect(PlaybackRate.x15.displayText == "1.5x")
#expect(PlaybackRate.x175.displayText == "1.75x")
#expect(PlaybackRate.x2.displayText == "2x")
#expect(PlaybackRate.x25.displayText == "2.5x")
#expect(PlaybackRate.x3.displayText == "3x")
}
@Test("displayText for the normal rate uses the localized label, not the numeric form")
func displayTextNormal() {
let normal = PlaybackRate.x1.displayText
#expect(normal == String(localized: "player.playbackRate.normal"))
#expect(!normal.hasSuffix("x"))
}
@Test("compactDisplayText always shows the numeric value")
func compactDisplayText() {
#expect(PlaybackRate.x1.compactDisplayText == "1x")
#expect(PlaybackRate.x125.compactDisplayText == "1.25x")
#expect(PlaybackRate.x15.compactDisplayText == "1.5x")
#expect(PlaybackRate.x175.compactDisplayText == "1.75x")
#expect(PlaybackRate.x2.compactDisplayText == "2x")
#expect(PlaybackRate.x3.compactDisplayText == "3x")
}
@Test("every case has a non-empty display string")
func allCasesNonEmpty() {
for rate in PlaybackRate.allCases {
#expect(!rate.displayText.isEmpty)
#expect(!rate.compactDisplayText.isEmpty)
}
}
}