Skip to content

Commit

Permalink
feat: Port first Obj-C file to Swift (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
einsteinx2 committed Apr 24, 2023
1 parent e2bb3bc commit 18b1e1c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 48 deletions.
65 changes: 65 additions & 0 deletions UnitTests/NSNumber+MPFormatterTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// NSNumber+MPFormatterTests.m
// mParticle-Apple-SDK
//
// Created by Ben Baron on 3/9/23.
// Copyright © 2023 mParticle, Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "MPBaseTestCase.h"
#import <mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>

@interface NSNumber_MPFormatterTests : MPBaseTestCase

@end

@implementation NSNumber_MPFormatterTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testFormatZero {
NSNumber *number = @(0);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(0));
}

- (void)testFormatCloseToZero {
NSNumber *number = @(1.0E-6);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(0));
}

- (void)testFormatOneDecimalPlace {
NSNumber *number = @(0.1);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(0.1));
}

- (void)testFormatTwoDecimalPlaces {
NSNumber *number = @(0.01);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(0.01));
}

- (void)testFormatRoundUp {
NSNumber *number = @(10.01534634);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(10.02));
}

- (void)testFormatRoundDown {
NSNumber *number = @(10.01434634);
NSNumber *formattedNumber = [number formatWithNonScientificNotation];
XCTAssertEqualObjects(formattedNumber, @(10.01));
}

@end
9 changes: 5 additions & 4 deletions mParticle-Apple-SDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ Pod::Spec.new do |s|
s.prefix_header_contents = pch_mParticle
s.ios.deployment_target = "9.0"
s.tvos.deployment_target = "9.0"
s.swift_versions = ["5.0"]

s.subspec 'mParticle' do |ss|
ss.public_header_files = `./Scripts/find_headers.rb --public`.split("\n")

ss.preserve_paths = 'mParticle-Apple-SDK', 'mParticle-Apple-SDK/**', 'mParticle-Apple-SDK/**/*'
ss.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp}'
ss.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp,swift}'
ss.libraries = 'c++', 'sqlite3', 'z'
ss.ios.frameworks = 'AdSupport', 'CoreGraphics', 'CoreLocation', 'CoreTelephony', 'Foundation', 'Security', 'SystemConfiguration', 'UIKit'
ss.ios.weak_frameworks = 'iAd', 'UserNotifications'
Expand All @@ -59,7 +60,7 @@ Pod::Spec.new do |s|
ss.public_header_files = `./Scripts/find_headers.rb --public`.split("\n")

ss.preserve_paths = 'mParticle-Apple-SDK', 'mParticle-Apple-SDK/**', 'mParticle-Apple-SDK/**/*'
ss.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp}'
ss.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp,swift}'
ss.libraries = 'c++', 'sqlite3', 'z'
ss.ios.frameworks = 'AdSupport', 'CoreGraphics', 'CoreTelephony', 'Foundation', 'Security', 'SystemConfiguration', 'UIKit'
ss.ios.weak_frameworks = 'iAd', 'UserNotifications'
Expand All @@ -76,7 +77,7 @@ Pod::Spec.new do |s|
ext.public_header_files = `./Scripts/find_headers.rb --public`.split("\n")

ext.preserve_paths = 'mParticle-Apple-SDK', 'mParticle-Apple-SDK/**', 'mParticle-Apple-SDK/**/*'
ext.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp}'
ext.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp,swift}'
ext.libraries = 'c++', 'sqlite3', 'z'
ext.ios.frameworks = 'AdSupport', 'CoreGraphics', 'CoreLocation', 'CoreTelephony', 'Foundation', 'Security', 'SystemConfiguration', 'UIKit'
ext.ios.weak_frameworks = 'iAd', 'UserNotifications'
Expand All @@ -88,7 +89,7 @@ Pod::Spec.new do |s|
ext.public_header_files = `./Scripts/find_headers.rb --public`.split("\n")

ext.preserve_paths = 'mParticle-Apple-SDK', 'mParticle-Apple-SDK/**', 'mParticle-Apple-SDK/**/*'
ext.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp}'
ext.source_files = 'mParticle-Apple-SDK/**/*.{h,m,mm,cpp,swift}'
ext.libraries = 'c++', 'sqlite3', 'z'
ext.ios.frameworks = 'AdSupport', 'CoreGraphics', 'CoreTelephony', 'Foundation', 'Security', 'SystemConfiguration', 'UIKit'
ext.ios.weak_frameworks = 'iAd', 'UserNotifications'
Expand Down
Loading

0 comments on commit 18b1e1c

Please sign in to comment.