Esempio n. 1
0
func TestParseID2(t *testing.T) {
	for _, details := range steamIDTests {
		steamID, err := steamid.ParseV2(details.ExpectedID2)
		if err != nil {
			t.Errorf("ParseV2(%q): error parsing: %s", details.ExpectedID2, err)
			continue
		}

		if u := steamID.Universe(); u != details.Universe {
			t.Errorf("Universe(%q): got %d, expected %d", details.ExpectedID2, u, details.Universe)
		}

		typ := steamID.AccountType()

		if inst := steamID.AccountInstance(); inst != details.Instance &&
			!(typ == steamid.AccountTypeIndividual && details.Instance != 1) { // Version 2 IDs can't carry instance information
			t.Errorf("AccountInstance(%q): got %d, expected %d", details.ExpectedID2, inst, details.Instance)
		}

		if typ != details.Type {
			t.Errorf("AccountType(%q): got %d, expected %d", details.ExpectedID2, typ, details.Type)
		}

		if id := steamID.AccountID(); id != details.ID {
			t.Errorf("AccountID(%q): got %d, expected %d", details.ExpectedID2, id, details.ID)
		}
	}
}
Esempio n. 2
0
func BenchmarkParseID2(b *testing.B) {
	const testID = "STEAM_0:0:1"

	for i := 0; i < b.N; i++ {
		if _, err := steamid.ParseV2(testID); err != nil {
			b.Fatal(err)
		}
	}
}