Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
move signal core kit tests from ios app repo to signal core kit
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrenkret-signal committed Apr 27, 2024
1 parent 44d9256 commit b6640fd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions SignalCoreKitTests/src/NSObjectTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//

import Foundation
import XCTest

@testable import SignalCoreKit

class NSObjectTest: XCTestCase {
func testObjectComparison() {
let yes: NSNumber = true
let no: NSNumber = false
XCTAssertTrue(NSObject.isNullableObject(nil, equalTo: nil))
XCTAssertFalse(NSObject.isNullableObject(yes, equalTo: nil))
XCTAssertFalse(NSObject.isNullableObject(nil, equalTo: yes))
XCTAssertFalse(NSObject.isNullableObject(yes, equalTo: no))
XCTAssertTrue(NSObject.isNullableObject(yes, equalTo: yes))
}
}
36 changes: 36 additions & 0 deletions SignalCoreKitTests/src/SCKStringTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

NS_ASSUME_NONNULL_BEGIN

#pragma mark - private interface in NSString+OWS.h

@interface NSString (OWS_Test)
- (NSString *)removeAllCharactersIn:(NSCharacterSet *)characterSet;
- (NSString *)filterUnsafeFilenameCharacters;
@end

#pragma mark -

@interface SCKStringTests : XCTestCase

@end
Expand Down Expand Up @@ -106,6 +115,33 @@ - (void)testBalancedBidiControlCharacters
stringByPrependingCharacter:bidiLeftToRightEmbedding]);
}

- (void)testRemoveAllCharactersIn
{
XCTAssert([[@"" removeAllCharactersIn:NSCharacterSet.letterCharacterSet] isEqual:@""]);
XCTAssert([[@"1" removeAllCharactersIn:NSCharacterSet.letterCharacterSet] isEqual:@"1"]);
XCTAssert([[@"a" removeAllCharactersIn:NSCharacterSet.letterCharacterSet] isEqual:@""]);
XCTAssert([[@"A" removeAllCharactersIn:NSCharacterSet.letterCharacterSet] isEqual:@""]);
XCTAssert([[@"abc123%^&" removeAllCharactersIn:NSCharacterSet.letterCharacterSet] isEqual:@"123%^&"]);

XCTAssert([[@"" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@""]);
XCTAssert([[@"1" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@""]);
XCTAssert([[@"a" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@"a"]);
XCTAssert([[@"A" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@"A"]);
XCTAssert([[@"abc123%^&" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@"abc%^&"]);
}

- (void)testfilterUnsafeFilenameCharacters
{
XCTAssertEqualObjects(@"1".filterUnsafeFilenameCharacters, @"1");
XCTAssertEqualObjects(@"alice\u202Dbob".filterUnsafeFilenameCharacters, @"alice\uFFFDbob");
XCTAssertEqualObjects(@"\u202Dalicebob".filterUnsafeFilenameCharacters, @"\uFFFDalicebob");
XCTAssertEqualObjects(@"alicebob\u202D".filterUnsafeFilenameCharacters, @"alicebob\uFFFD");
XCTAssertEqualObjects(@"alice\u202Ebob".filterUnsafeFilenameCharacters, @"alice\uFFFDbob");
XCTAssertEqualObjects(@"\u202Ealicebob".filterUnsafeFilenameCharacters, @"\uFFFDalicebob");
XCTAssertEqualObjects(@"alicebob\u202E".filterUnsafeFilenameCharacters, @"alicebob\uFFFD");
XCTAssertEqualObjects(@"alice\u202Dbobalice\u202Ebob".filterUnsafeFilenameCharacters, @"alice\uFFFDbobalice\uFFFDbob");
}

@end

NS_ASSUME_NONNULL_END
Expand Down

0 comments on commit b6640fd

Please sign in to comment.