Convert FBSDKReferralCodeTests to Swift

Reviewed By: samodom

Differential Revision: D32629233

fbshipit-source-id: 84c141a0c3a09fba577a191a34d1559997945655
This commit is contained in:
Jawwad Ahmad
2021-11-23 16:18:07 -08:00
committed by Facebook GitHub Bot
parent deb8c444f8
commit 0a7c0f2af6
3 changed files with 51 additions and 69 deletions

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBSDKReferralCode.h"
static NSString *const _validReferralCode1 = @"abcd";
static NSString *const _validReferralCode2 = @"123";
static NSString *const _validReferralCode3 = @"123abc";
static NSString *const _invalidReferralCode1 = @"abd?";
static NSString *const _invalidReferralCode2 = @"a b1";
static NSString *const _invalidReferralCode3 = @" ";
static NSString *const _invalidReferralCode4 = @"\n\n";
static NSString *const _emptyReferralCode = @"";
@interface FBSDKReferralCodeTests : XCTestCase
@end
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@implementation FBSDKReferralCodeTests
- (void)testCreateValidReferralCodeShouldSucceed
{
[self assertCreationSucceedWithString:_validReferralCode1];
[self assertCreationSucceedWithString:_validReferralCode2];
}
- (void)testCreateInvalidReferralCodeShoudFail
{
[self assertCreationFailWithString:_invalidReferralCode1];
[self assertCreationFailWithString:_invalidReferralCode2];
[self assertCreationFailWithString:_invalidReferralCode3];
[self assertCreationFailWithString:_invalidReferralCode4];
}
- (void)testCreateEmptyReferralCodeShoudFail
{
[self assertCreationFailWithString:_emptyReferralCode];
}
- (void)assertCreationFailWithString:(NSString *)string
{
FBSDKReferralCode *referralCode = [FBSDKReferralCode initWithString:string];
XCTAssertNil(referralCode);
}
- (void)assertCreationSucceedWithString:(NSString *)string
{
FBSDKReferralCode *referralCode = [FBSDKReferralCode initWithString:string];
XCTAssertNotNil(referralCode);
XCTAssertEqual(referralCode.value, string);
}
@end
#pragma clange diagnostic pop

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
import XCTest
let validReferralCode1 = "abcd"
let validReferralCode2 = "123"
let validReferralCode3 = "123abc"
let invalidReferralCode1 = "abd?"
let invalidReferralCode2 = "a b1"
let invalidReferralCode3 = " "
let invalidReferralCode4 = "\n\n"
let emptyReferralCode = ""
final class ReferralCodeTests: XCTestCase {
func testCreateValidReferralCodeShouldSucceed() {
self.assertCreationSucceedWithString(validReferralCode1)
self.assertCreationSucceedWithString(validReferralCode2)
}
func testCreateInvalidReferralCodeShoudFail() {
self.assertCreationFailWithString(invalidReferralCode1)
self.assertCreationFailWithString(invalidReferralCode2)
self.assertCreationFailWithString(invalidReferralCode3)
self.assertCreationFailWithString(invalidReferralCode4)
}
func testCreateEmptyReferralCodeShoudFail() {
self.assertCreationFailWithString(emptyReferralCode)
}
func assertCreationFailWithString(_ string: String, file: StaticString = #file, line: UInt = #line) {
let referralCode = ReferralCode.initWith(string)
XCTAssertNil(referralCode, file: file, line: line)
}
func assertCreationSucceedWithString(_ string: String, file: StaticString = #file, line: UInt = #line) {
let referralCode = ReferralCode.initWith(string)
XCTAssertNotNil(referralCode)
XCTAssertEqual(referralCode?.value, string)
}
}

View File

@@ -11,6 +11,6 @@ XCODEBUILD_WARNINGS_ALLOWLIST = [
# "warning: failed to load toolchain: could not find Info.plist in /Users/facebook/Library/Developer/Toolchains/pika-13-macos-noasserts.xctoolchain",
"warning: failed to load toolchain: could not find Info.plist in /Users/facebook/Library/Developer/Toolchains/pika-",
# Deprecation Warnings:
"warning: 'AppLinkResolverRequestBuilder' is deprecated: `FBSDKAppLinkResolverRequestBuilder` is deprecated and will be removed in the next major release",
"is deprecated and will be removed in the next major release",
"warning: Building targets in manual order is deprecated",
]