import XCTest @testable import RouterOSAssistant /// RouterOS' `/interface monitor-traffic once` reports throughput as human-formatted /// strings with a unit suffix, never a bare integer — confirmed live (2026-09-15, hEX/RouterOS /// 7.x): "50.7kbps", "34.0kbps". The original implementation did `Int(fields[...] ?? "0") ?? 0`, /// which silently parsed every real value to 0 (a numeric string followed by letters isn't a /// valid `Int`), so the traffic indicator never showed as active regardless of real traffic. final class SSHTransportTrafficParsingTests: XCTestCase { func testParsesKbpsWithDecimalPoint() { XCTAssertEqual(SSHTransport.parseBitsPerSecond("50.7kbps"), 50_700) XCTAssertEqual(SSHTransport.parseBitsPerSecond("34.0kbps"), 34_000) } func testParsesMbpsAndGbps() { XCTAssertEqual(SSHTransport.parseBitsPerSecond("1.5Mbps"), 1_500_000) XCTAssertEqual(SSHTransport.parseBitsPerSecond("2Gbps"), 2_000_000_000) } /// "kbps" itself ends with "bps" — the plain "bps" suffix must not be matched first, or /// "50.7kbps" would parse as if it were "50.7" followed by a stray "k". func testDoesNotConfuseKbpsWithPlainBps() { XCTAssertEqual(SSHTransport.parseBitsPerSecond("500bps"), 500) } func testIdleReportsZero() { XCTAssertEqual(SSHTransport.parseBitsPerSecond("0"), 0) XCTAssertEqual(SSHTransport.parseBitsPerSecond("0bps"), 0) } func testMissingOrUnparsableFallsBackToZero() { XCTAssertEqual(SSHTransport.parseBitsPerSecond(nil), 0) XCTAssertEqual(SSHTransport.parseBitsPerSecond("n/a"), 0) } }