-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatting.test.ts
83 lines (66 loc) · 2.94 KB
/
formatting.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { expect } from "chai";
import * as formatting from "../dst/formatting";
describe("#formatStringKey()", () => {
it("should prefix the string with 0x, capitalize letters, and be 8 digits", () => {
expect(formatting.formatStringKey(0x12ab)).to.equal("0x000012AB");
});
it("should throw if the value is > 32 bit", () => {
expect(() => formatting.formatStringKey(0x123456780)).to.throw();
});
it("should throw if the value is negative", () => {
expect(() => formatting.formatStringKey(-1)).to.throw();
});
});
describe("#formatResourceType()", () => {
it("should capitalize letters and and be 8 digits", () => {
expect(formatting.formatResourceType(0x12ab)).to.equal("000012AB");
});
it("should throw if the value is > 32 bit", () => {
expect(() => formatting.formatResourceType(0x123456780)).to.throw();
});
it("should throw if the value is negative", () => {
expect(() => formatting.formatResourceType(-1)).to.throw();
});
});
describe("#formatResourceGroup()", () => {
it("should capitalize letters and and be 8 digits", () => {
expect(formatting.formatResourceGroup(0x12ab)).to.equal("000012AB");
});
it("should throw if the value is > 32 bit", () => {
expect(() => formatting.formatResourceGroup(0x123456780)).to.throw();
});
it("should throw if the value is negative", () => {
expect(() => formatting.formatResourceGroup(-1)).to.throw();
});
});
describe("#formatResourceInstance()", () => {
it("should capitalize letters and and be 16 digits", () => {
expect(formatting.formatResourceInstance(0x12abn)).to.equal("00000000000012AB");
});
it("should throw if the value is > 64 bit", () => {
expect(() => formatting.formatResourceInstance(0xFFFFFFFFFFFFFFFFFFFFn)).to.throw();
});
it("should throw if the value is negative", () => {
expect(() => formatting.formatResourceInstance(-1n)).to.throw();
});
});
describe("#formatResourceTGI()", () => {
it("should format given values with : delimeter", () => {
expect(formatting.formatResourceTGI(0x12345678, 0x87654321, 0x1234n)).to.equal("12345678:87654321:0000000000001234");
});
it("should format given values with the given delimeter", () => {
expect(formatting.formatResourceTGI(0x12345678, 0x87654321, 0x1234n, '-')).to.equal("12345678-87654321-0000000000001234");
});
});
describe("#formatResourceKey()", () => {
it("should format given values with : delimeter", () => {
const key = { type: 0x12345678, group: 0x87654321, instance: 0x1234n };
expect(formatting.formatResourceKey(key)).to.equal("12345678:87654321:0000000000001234");
});
it("should format given values with the given delimeter", () => {
const key = { type: 0x12345678, group: 0x87654321, instance: 0x1234n };
expect(formatting.formatResourceKey(key, '-')).to.equal("12345678-87654321-0000000000001234");
});
});
// all code paths for formatAsHexString() are used by the other functions,
// so if they pass, this is working as intended