feat: add PlayMode enum (single=0, loop=1)

This commit is contained in:
km2023
2026-05-06 10:31:36 +08:00
parent b42f848c31
commit be851b05ec
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import Foundation
/// `loop`
///
/// - `single` (0):
/// - `loop` (1):
public enum PlayMode: Int, Codable, Equatable {
case single = 0
case loop = 1
}

View File

@@ -0,0 +1,22 @@
import XCTest
@testable import DuooomiBleSDK
final class PlayModeTests: XCTestCase {
func testRawValues() {
XCTAssertEqual(PlayMode.single.rawValue, 0)
XCTAssertEqual(PlayMode.loop.rawValue, 1)
}
func testInitFromRawValue() {
XCTAssertEqual(PlayMode(rawValue: 0), .single)
XCTAssertEqual(PlayMode(rawValue: 1), .loop)
XCTAssertNil(PlayMode(rawValue: 2))
}
func testCodableRoundTrip() throws {
let data = try JSONEncoder().encode(PlayMode.loop)
XCTAssertEqual(String(data: data, encoding: .utf8), "1")
let decoded = try JSONDecoder().decode(PlayMode.self, from: Data("0".utf8))
XCTAssertEqual(decoded, .single)
}
}