Skip to content

Commit a58da4d

Browse files
committed
Change unit test format
1 parent 1d4f04f commit a58da4d

9 files changed

Lines changed: 118 additions & 107 deletions

File tree

Tests/ATCryptographyTests/BaseRadix/Base16Suite.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,51 @@
88
import Testing
99
@testable import ATCryptography
1010

11-
struct Base16Suite {
11+
@Suite
12+
struct `Base 16 Encoding and Decoding` {
1213

13-
@Test("Encodes a single byte to lowercase Base16.")
14-
func encode() {
14+
@Test
15+
func `Encodes a single byte to lowercase Base16`() {
1516
let input: [UInt8] = [0x12, 0xAB, 0xCD, 0xEF]
1617
let expectedOutput = "12abcdef"
1718
#expect(Base16.encode(input) == expectedOutput)
1819
}
1920

20-
@Test("Encodes a single byte to uppercase Base16.")
21-
func encodeUpper() {
21+
@Test
22+
func `Encodes a single byte to uppercase Base16`() {
2223
let input: [UInt8] = [0x12, 0xAB, 0xCD, 0xEF]
2324
let expectedOutput = "12ABCDEF"
2425
#expect(Base16.encodeUpper(input) == expectedOutput)
2526
}
2627

27-
@Test("Decodes a valid lowercase Base16 string.")
28-
func decodeLowercase() {
28+
@Test
29+
func `Decodes a valid lowercase Base16 string`() {
2930
let input = "12abcdef"
3031
let expectedOutput: [UInt8] = [0x12, 0xAB, 0xCD, 0xEF]
3132
#expect(Base16.decode(input) == expectedOutput)
3233
}
3334

34-
@Test("Decodes a valid uppercase Base16 string.")
35-
func decodeUppercase() {
35+
@Test
36+
func `Decodes a valid uppercase Base16 string`() {
3637
let input = "12ABCDEF"
3738
let expectedOutput: [UInt8] = [0x12, 0xAB, 0xCD, 0xEF]
3839
#expect(Base16.decode(input) == expectedOutput)
3940
}
4041

41-
@Test("Decodes an invalid odd length Base16 string.")
42-
func decodeInvalidOddLength() {
42+
@Test
43+
func `Decodes an invalid odd length Base16 string`() {
4344
let input = "123"
4445
#expect(Base16.decode(input) == nil)
4546
}
4647

47-
@Test("Decodes an invalid Base16 string (non-hex characters).")
48-
func decodeInvalidCharacters() {
48+
@Test
49+
func `Decodes an invalid Base16 string (non-hex characters)`() {
4950
let input = "12GZ"
5051
#expect(Base16.decode(input) == nil)
5152
}
5253

53-
/// Test decoding an empty string.
54-
@Test("Decodes an empty string.")
55-
func decodeEmptyString() {
54+
@Test
55+
func `Decodes an empty string`() {
5656
let input = ""
5757
let expectedOutput: [UInt8] = []
5858
#expect(Base16.decode(input) == expectedOutput)

Tests/ATCryptographyTests/BaseRadix/Base32Suite.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,45 @@
88
import Testing
99
@testable import ATCryptography
1010

11-
struct Base32Suite {
11+
@Suite
12+
struct `Base32 Encoding and Decoding` {
1213

13-
@Test("Encodes a single byte to lowercase Base32.")
14-
func encode() {
14+
@Test
15+
func `Encodes a single byte to lowercase Base32`() {
1516
let input: [UInt8] = [0x12, 0x34, 0x56, 0x78]
1617
let expectedOutput = "ci2fm6a="
1718
#expect(Base32.encode(input) == expectedOutput)
1819
}
1920

20-
@Test("Encodes a single byte to uppercase Base32.")
21-
func encodeUpper() {
21+
@Test
22+
func `Encodes a single byte to uppercase Base32`() {
2223
let input: [UInt8] = [0x12, 0x34, 0x56, 0x78]
2324
let expectedOutput = "CI2FM6A="
2425
#expect(Base32.encodeUpper(input) == expectedOutput)
2526
}
2627

27-
@Test("Decodes a valid lowercase Base32 string.")
28-
func decodeLowercase() {
28+
@Test
29+
func `Decodes a valid lowercase Base32 string`() {
2930
let input = "ci2fm6=="
3031
let expectedOutput: [UInt8] = [0x12, 0x34, 0x56]
3132
#expect(Base32.decode(input) == expectedOutput)
3233
}
3334

34-
@Test("Decodes a valid uppercase Base32 string.")
35-
func decodeUppercase() {
35+
@Test
36+
func `Decodes a valid uppercase Base32 string`() {
3637
let input = "CI2FM6=="
3738
let expectedOutput: [UInt8] = [0x12, 0x34, 0x56]
3839
#expect(Base32.decode(input) == expectedOutput)
3940
}
4041

41-
@Test("Decodes an invalid Base32 string (contains illegal characters).")
42-
func decodeInvalidCharacters() {
42+
@Test
43+
func `Decodes an invalid Base32 string (contains illegal characters)`() {
4344
let input = "CI@FM6=="
4445
#expect(Base32.decode(input) == nil)
4546
}
4647

47-
@Test("Decodes an empty string.")
48-
func decodeEmptyString() {
48+
@Test
49+
func `Decodes an empty string`() {
4950
let input = ""
5051
#expect(Base32.decode(input) == nil)
5152
}

Tests/ATCryptographyTests/BaseRadix/Base58Suite.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ import Foundation
99
import Testing
1010
@testable import ATCryptography
1111

12-
struct Base58Suite {
12+
@Suite
13+
struct `Base58 Encoding and Decoding` {
1314

14-
@Test("Encodes a Data object to a Base58-encoded string")
15-
func encode() {
15+
@Test
16+
func `Encodes a Data object to a Base58-encoded string`() {
1617
let input: [UInt8] = [0x02, 0x6f, 0x55, 0x60, 0x84, 0xa5, 0x75, 0x5e, 0x9c, 0x8b, 0x8f, 0x0b]
1718
let expectedOutput = "3fa85f6457174562"
1819
#expect(Base58.encode(Data(input)) == expectedOutput)
1920
}
2021

21-
@Test("Decodes a Base58-encoded string to a Data object.")
22-
func decode() throws {
22+
@Test
23+
func `Decodes a Base58-encoded string to a Data object`() throws {
2324
let input = "3fa85f6457174562"
2425
let expectedOutput: [UInt8] = [0x02, 0x6F, 0x55, 0x60, 0x84, 0xA5, 0x75, 0x5E, 0x9C, 0x8B, 0x8F, 0x0B]
2526

@@ -28,17 +29,17 @@ struct Base58Suite {
2829
#expect(base58 == Data(expectedOutput))
2930
}
3031

31-
@Test("Fails from an invalid character.")
32-
func decodeInvalidCharacter() async throws {
32+
@Test
33+
func `Fails from an invalid character`() throws {
3334
let input = "3fa85f645717456&"
3435

3536
#expect(throws: Base58Error.self) {
3637
try Base58.decode(input)
3738
}
3839
}
3940

40-
@Test("Decodes an empty string.")
41-
func decodeEmptyString() async throws {
41+
@Test
42+
func `Decodes an empty string`() throws {
4243
let input = ""
4344
let base58 = try Base58.decode(input)
4445
#expect(base58 == Data())

Tests/ATCryptographyTests/BaseRadix/Base64URLSuite.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import Foundation
99
import Testing
1010
@testable import ATCryptography
1111

12-
struct Base64URLSuite {
12+
@Suite
13+
struct `Base64URL Encoding and Decoding` {
1314

14-
@Test("Encodes bytes to a Base64URL string.")
15-
func encodeURL() {
15+
@Test
16+
func `Encodes bytes to a Base64URL string`() {
1617
let input: [UInt8] = [0x8f, 0x2b, 0x7b, 0x4b, 0x9e, 0xa3, 0x38, 0x99, 0x63, 0x49, 0x05, 0x91, 0x10]
1718
let expectedOutput = "jyt7S56jOJljSQWREA"
1819

@@ -21,8 +22,8 @@ struct Base64URLSuite {
2122
#expect(Base64URL.encodeURL(data) == expectedOutput)
2223
}
2324

24-
@Test("Encodes bytes to a Base64URLPad string.")
25-
func encodeURLPad() {
25+
@Test
26+
func `Encodes bytes to a Base64URLPad string`() {
2627
let input: [UInt8] = [0x8f, 0x2b, 0x7b, 0x4b, 0x9e, 0xa3, 0x38, 0x99, 0x63, 0x49, 0x05, 0x91, 0x10, 0x0f, 0xfe]
2728
let expectedOutput = "jyt7S56jOJljSQWREA_-"
2829

@@ -31,8 +32,8 @@ struct Base64URLSuite {
3132
#expect(Base64URL.encodeURLPad(data) == expectedOutput)
3233
}
3334

34-
@Test("Decodes a Base64URL string to an array of bytes.")
35-
func decodeURL() {
35+
@Test
36+
func `Decodes a Base64URL string to an array of bytes`() {
3637
let input = "jyt7S56jOJljSQWREA"
3738
let expectedOutput: [UInt8] = [0x8f, 0x2b, 0x7b, 0x4b, 0x9e, 0xa3, 0x38, 0x99, 0x63, 0x49, 0x05, 0x91, 0x10]
3839

@@ -41,8 +42,8 @@ struct Base64URLSuite {
4142
#expect(base64URL == Data(expectedOutput))
4243
}
4344

44-
@Test("Decodes a BaseURLPad string to an array of bytes.")
45-
func decodeURLPad() {
45+
@Test
46+
func `Decodes a BaseURLPad string to an array of bytes`() {
4647
let input = "jyt7S56jOJljSQWREA_-"
4748
let expectOutput: [UInt8] = [0x8f, 0x2b, 0x7b, 0x4b, 0x9e, 0xa3, 0x38, 0x99, 0x63, 0x49, 0x05, 0x91, 0x10, 0x0f, 0xfe]
4849

@@ -51,35 +52,35 @@ struct Base64URLSuite {
5152
#expect(base64URLPad == Data(expectOutput))
5253
}
5354

54-
@Test("Decodes an invalid Base64URL (contains illegal character).")
55-
func decodeInvalidCharacter() {
55+
@Test
56+
func `Decodes an invalid Base64URL (contains illegal character)`() {
5657
let input = "jyt7S56jOJljSQ#REA_-"
5758

5859
let base64URL = Base64URL.decodeURL(input)
5960

6061
#expect(base64URL == nil)
6162
}
6263

63-
@Test("Decodes an invalid Base64URLPad (contains illegal character).")
64-
func decodeInvalidCharacterPad() {
64+
@Test
65+
func `Decodes an invalid Base64URLPad (contains illegal character)`() {
6566
let input = "jyt7S56jOJljSQ#REA_-"
6667

6768
let base64URLPad = Base64URL.decodeURLPad(input)
6869

6970
#expect(base64URLPad == nil)
7071
}
7172

72-
@Test("Decodes an empty string (Base64URL)")
73-
func decodeEmptyBase64URLString() async throws {
73+
@Test
74+
func `Decodes an empty string (Base64URL)`() {
7475
let input = ""
7576

7677
let base64URL = Base64URL.decodeURL(input)
7778

7879
#expect(base64URL == Data())
7980
}
8081

81-
@Test("Decodes an empty string (Base64URLPad)")
82-
func decodeEmptyBase64URLPadString() async throws {
82+
@Test
83+
func `Decodes an empty string (Base64URLPad)`() {
8384
let input = ""
8485

8586
let base64URLPad = Base64URL.decodeURLPad(input)

Tests/ATCryptographyTests/DIDKeySuite.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ import Foundation
99
import Testing
1010
@testable import ATCryptography
1111

12-
@Suite("did:keys") struct didKeyTests {
12+
@Suite
13+
struct `did:keys` {
1314

14-
@Suite("k256 did:key") struct k256DIDKeyTests {
15+
@Suite
16+
struct `k256 did:key` {
1517

16-
@Test("Validate whether a private key correctly derives a did:key (in k256).",
17-
arguments: zip(
18-
EllipticalCurveTestVectors.k256Seeds,
19-
EllipticalCurveTestVectors.k256IDs))
20-
func validateKeyDerivesDID(seed: String, didKey: String) throws {
18+
@Test(arguments: zip(
19+
EllipticalCurveTestVectors.k256Seeds,
20+
EllipticalCurveTestVectors.k256IDs))
21+
func `Validate whether a private key correctly derives a did:key (in k256)`(seed: String, didKey: String) throws {
2122
let keypair = try K256Keypair.import(privateKey: seed.hexBytes)
2223
let keypairDIDKey = try keypair.did()
2324

2425
#expect(keypairDIDKey == didKey,
2526
"The k256 did:key generated from the seed should match the hard-coded did:key.")
2627
}
2728

28-
@Test("Converts between bytes to did:key (in k256).",
29-
arguments: zip(
30-
EllipticalCurveTestVectors.k256Seeds,
31-
EllipticalCurveTestVectors.k256IDs))
32-
func convertBytesToDIDKey(seed: String, didKey: String) throws {
29+
@Test(arguments: zip(
30+
EllipticalCurveTestVectors.k256Seeds,
31+
EllipticalCurveTestVectors.k256IDs))
32+
func `Converts between bytes to did:key (in k256)`(seed: String, didKey: String) throws {
3333
let keypair = try K256Keypair.import(privateKey: seed.hexBytes)
3434
let formattedDIDKey = try DIDKey.formatDIDKey(
3535
jwtAlgorithm: k256JWTAlgorithm,
@@ -47,13 +47,13 @@ import Testing
4747
}
4848
}
4949

50-
@Suite("p256 did:key") struct p256DIDKeyTests {
50+
@Suite
51+
struct `p256 did:key` {
5152

52-
@Test("Derives the correct did:key from the JWK algorithm (in p256).",
53-
arguments: zip(
54-
EllipticalCurveTestVectors.p256PrivateKeys,
55-
EllipticalCurveTestVectors.p256TestVectorsIDs))
56-
func validateKeyDerivesDID(privateKey: String, didKey: String) throws {
53+
@Test(arguments: zip(
54+
EllipticalCurveTestVectors.p256PrivateKeys,
55+
EllipticalCurveTestVectors.p256TestVectorsIDs))
56+
func `Derives the correct did:key from the JWK algorithm (in p256)`(privateKey: String, didKey: String) throws {
5757
let bytes: [UInt8] = [UInt8](try Base58.decode(privateKey))
5858
let keypair = try P256Keypair.import(privateKey: bytes)
5959
let keypairDIDKey = try keypair.did()
@@ -62,11 +62,10 @@ import Testing
6262
"The k256 did:key generated from the seed should match the hard-coded did:key.")
6363
}
6464

65-
@Test("Converts between bytes to did:key (in p256).",
66-
arguments: zip(
67-
EllipticalCurveTestVectors.p256PrivateKeys,
68-
EllipticalCurveTestVectors.p256TestVectorsIDs))
69-
func convertBytesToDIDKey(privateKey: String, didKey: String) throws {
65+
@Test(arguments: zip(
66+
EllipticalCurveTestVectors.p256PrivateKeys,
67+
EllipticalCurveTestVectors.p256TestVectorsIDs))
68+
func `Converts between bytes to did:key (in p256)`(privateKey: String, didKey: String) throws {
7069
let bytes: [UInt8] = [UInt8](try Base58.decode(privateKey))
7170
let keypair = try P256Keypair.import(privateKey: bytes)
7271
let formattedDIDKey = try DIDKey.formatDIDKey(

Tests/ATCryptographyTests/KeyCompressionSuite.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import Foundation
99
import Testing
1010
@testable import ATCryptography
1111

12-
@Suite("Public Key Compression") struct PublicKeyCompressionTests {
12+
@Suite
13+
struct `Public Key Compression` {
1314

14-
@Suite("k256 Compression") struct k256Tests {
15+
@Suite
16+
struct `k256 Compression` {
1517

16-
@Test("Compresses a k256 keypair to its appropriate length, then to its original length.")
17-
func compressAndDecompressKeypair() throws {
18+
@Test
19+
func `Compresses a k256 keypair to its appropriate length, then to its original length`() throws {
1820
var keyBytes: [UInt8] = []
1921
var compressedKeys: [UInt8] = []
2022

@@ -33,8 +35,8 @@ import Testing
3335
"The decompressed public key should have 65 bytes.")
3436
}
3537

36-
@Test("Creates, compresses, and decompresses 100 k256 keypairs to make sure the compression works consistently.")
37-
func compressionLoop() throws {
38+
@Test
39+
func `Creates, compresses, and decompresses 100 k256 keypairs to make sure the compression works consistently`() throws {
3840
var publicKeys: [[UInt8]] = []
3941
var compressedKeys: [[UInt8]] = []
4042
var decompressedKeys: [[UInt8]] = []
@@ -52,10 +54,11 @@ import Testing
5254
}
5355
}
5456

55-
@Suite("p256 Compression") struct p256Tests {
57+
@Suite
58+
struct `p256 Compression` {
5659

57-
@Test("Compresses a p256 keypair to its appropriate length, then to its original length.")
58-
func compressAndDecompressKeypair() throws {
60+
@Test
61+
func `Compresses a p256 keypair to its appropriate length, then to its original length`() throws {
5962
var keyBytes: [UInt8] = []
6063
var compressedKeys: [UInt8] = []
6164

@@ -74,8 +77,8 @@ import Testing
7477
"The decompressed public key should have 65 bytes.")
7578
}
7679

77-
@Test("Creates, compresses, and decompresses 100 p256 keypairs to make sure the compression works consistently.")
78-
func compressionLoop() throws {
80+
@Test
81+
func `Creates, compresses, and decompresses 100 p256 keypairs to make sure the compression works consistently`() throws {
7982
var publicKeys: [[UInt8]] = []
8083
var compressedKeys: [[UInt8]] = []
8184
var decompressedKeys: [[UInt8]] = []

0 commit comments

Comments
 (0)