Skip to content

Commit 5936b15

Browse files
Added byte encoding tests
1 parent 82b6846 commit 5936b15

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Tests/WebPushTests/BytesTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// BytesTests.swift
3+
// swift-webpush
4+
//
5+
// Created by Dimitri Bouniol on 2024-12-22.
6+
// Copyright © 2024 Mochi Development, Inc. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Testing
11+
@testable import WebPush
12+
13+
@Suite struct BytesTests {
14+
@Test func stringBytes() {
15+
#expect("hello".utf8Bytes == [0x68, 0x65, 0x6c, 0x6c, 0x6f])
16+
#expect("hello"[...].utf8Bytes == [0x68, 0x65, 0x6c, 0x6c, 0x6f])
17+
}
18+
19+
@Test func integerBytes() {
20+
#expect(UInt8(0b11110000).bigEndianBytes == [0b11110000])
21+
#expect(UInt16(0b1111000010100101).bigEndianBytes == [0b11110000, 0b10100101])
22+
#expect(UInt32(0b11110000101001010000111101011010).bigEndianBytes == [0b11110000, 0b10100101, 0b000001111, 0b01011010])
23+
#expect(UInt64(0b1111000010100101000011110101101011001100100011110011001101110000).bigEndianBytes == [0b11110000, 0b10100101, 0b000001111, 0b01011010, 0b11001100, 0b10001111, 0b00110011, 0b01110000])
24+
}
25+
}

0 commit comments

Comments
 (0)