Skip to content

Commit

Permalink
fixed user state parsing left-overs and added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Jul 19, 2022
1 parent edf267e commit 83abcc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/UserState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public struct UserState: MessageWithBadges {
let deprecatedKeys = ["turbo", "mod", "subscriber", "user-type"]
let sometimesUnavailableKeys = ["id"]
self.parsingLeftOvers = parser.getLeftOvers(
excludedUnusedKeys: deprecatedKeys + sometimesUnavailableKeys
excludedUnusedKeys: deprecatedKeys,
excludedUnavailableKeys: sometimesUnavailableKeys
)
}
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/TwitchIRCTests/IncomingMessageTests/UserStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ final class UserStateTests: XCTestCase {
XCTAssertEqual(userState.emoteSets, ["0", "33", "50", "237", "793", "2126", "3517", "4578", "5569", "9400", "10337", "12239"])
XCTAssertTrue(userState.parsingLeftOvers.isEmpty, "Non-empty parsing left-overs: \(userState.parsingLeftOvers)")
}

func testParsedValues2() throws {
let string = "@badge-info=;badges=staff/1;color=#0D4200;display-name=ronni;emote-sets=0,33,50,237,793,2126,3517,4578,5569,9400,10337,12239;mod=1;subscriber=1;id=cf930357-1196-4627-9a59-1657b8b62295;turbo=1;user-type=staff :tmi.twitch.tv USERSTATE #dallas"

let userState: UserState = try TestUtils.parseAndUnwrap(string: string)

XCTAssertEqual(userState.channel, "dallas")
XCTAssertEqual(userState.badgeInfo, [])
XCTAssertEqual(userState.badges, ["staff/1"])
XCTAssertEqual(userState.color, "#0D4200")
XCTAssertEqual(userState.displayName, "ronni")
XCTAssertEqual(userState.emoteSets, ["0", "33", "50", "237", "793", "2126", "3517", "4578", "5569", "9400", "10337", "12239"])
XCTAssertEqual(userState.id, "cf930357-1196-4627-9a59-1657b8b62295")
XCTAssertTrue(userState.parsingLeftOvers.isEmpty, "Non-empty parsing left-overs: \(userState.parsingLeftOvers)")
}
}

0 comments on commit 83abcc2

Please sign in to comment.