-
Notifications
You must be signed in to change notification settings - Fork 0
[FME-10450] - OF - Mapping #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
.swiftpm/xcode/xcshareddata/xcschemes/SplitProvider.xcscheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Scheme | ||
| LastUpgradeVersion = "1640" | ||
| version = "1.7"> | ||
| <BuildAction | ||
| parallelizeBuildables = "YES" | ||
| buildImplicitDependencies = "YES" | ||
| buildArchitectures = "Automatic"> | ||
| <BuildActionEntries> | ||
| <BuildActionEntry | ||
| buildForTesting = "YES" | ||
| buildForRunning = "YES" | ||
| buildForProfiling = "YES" | ||
| buildForArchiving = "YES" | ||
| buildForAnalyzing = "YES"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "SplitProvider" | ||
| BuildableName = "SplitProvider" | ||
| BlueprintName = "SplitProvider" | ||
| ReferencedContainer = "container:"> | ||
| </BuildableReference> | ||
| </BuildActionEntry> | ||
| </BuildActionEntries> | ||
| </BuildAction> | ||
| <TestAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| shouldUseLaunchSchemeArgsEnv = "YES" | ||
| shouldAutocreateTestPlan = "YES"> | ||
| <Testables> | ||
| <TestableReference | ||
| skipped = "NO"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "SplitProviderTests" | ||
| BuildableName = "SplitProviderTests" | ||
| BlueprintName = "SplitProviderTests" | ||
| ReferencedContainer = "container:"> | ||
| </BuildableReference> | ||
| </TestableReference> | ||
| </Testables> | ||
| </TestAction> | ||
| <LaunchAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| launchStyle = "0" | ||
| useCustomWorkingDirectory = "NO" | ||
| ignoresPersistentStateOnLaunch = "NO" | ||
| debugDocumentVersioning = "YES" | ||
| debugServiceExtension = "internal" | ||
| allowLocationSimulation = "YES"> | ||
| </LaunchAction> | ||
| <ProfileAction | ||
| buildConfiguration = "Release" | ||
| shouldUseLaunchSchemeArgsEnv = "YES" | ||
| savedToolIdentifier = "" | ||
| useCustomWorkingDirectory = "NO" | ||
| debugDocumentVersioning = "YES"> | ||
| <MacroExpansion> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "SplitProvider" | ||
| BuildableName = "SplitProvider" | ||
| BlueprintName = "SplitProvider" | ||
| ReferencedContainer = "container:"> | ||
| </BuildableReference> | ||
| </MacroExpansion> | ||
| </ProfileAction> | ||
| <AnalyzeAction | ||
| buildConfiguration = "Debug"> | ||
| </AnalyzeAction> | ||
| <ArchiveAction | ||
| buildConfiguration = "Release" | ||
| revealArchiveInOrganizer = "YES"> | ||
| </ArchiveAction> | ||
| </Scheme> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Created by Martin Cardozo on 24/10/2025. | ||
|
|
||
| import Split | ||
| import OpenFeature | ||
|
|
||
| final class Evaluator { | ||
|
|
||
| private let splitClient: SplitClient? | ||
|
|
||
| init(splitClient: SplitClient?) { | ||
| self.splitClient = splitClient | ||
| } | ||
|
|
||
| private func parseValue<T>(_ value: String, as type: T.Type) -> T? { | ||
| switch type { | ||
| case is Bool.Type: | ||
| return (value.lowercased() == "true") as? T | ||
| case is Int64.Type: | ||
| return Int64(value) as? T | ||
| case is Double.Type: | ||
| return Double(value) as? T | ||
| case is String.Type: | ||
| return value as? T | ||
| case is OpenFeature.Value.Type: | ||
| return OpenFeature.Value.string(value) as? T | ||
|
MartinCardozo-SDK marked this conversation as resolved.
|
||
| default: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| internal func evaluate<T>(key: String, defaultValue: T, context: (any EvaluationContext)?) -> ProviderEvaluation<T> { | ||
| let treatment = splitClient?.getTreatment(key) ?? Constants.CONTROL.rawValue | ||
| let value = parseValue(treatment, as: T.self) ?? defaultValue | ||
| return ProviderEvaluation(value: value) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Created by Martin Cardozo on 24/10/2025. | ||
|
|
||
| import XCTest | ||
| import OpenFeature | ||
| @testable import SplitProvider | ||
|
|
||
| final class EvaluatorTests: XCTestCase { | ||
|
|
||
| private func makeEvaluator(with treatment: String) -> Evaluator { | ||
| let client = ClientMock() | ||
| client.treatment = treatment | ||
| return Evaluator(splitClient: client) | ||
| } | ||
|
|
||
| func testBoolTrue() { | ||
| let SUT = makeEvaluator(with: "true") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: false, context: nil) | ||
| XCTAssertEqual(result.value, true) | ||
| } | ||
|
|
||
| func testBoolFalse() { | ||
| let SUT = makeEvaluator(with: "FA LSE") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: true, context: nil) | ||
| XCTAssertEqual(result.value, false) | ||
| } | ||
|
|
||
| func testInt64() { | ||
| let SUT = makeEvaluator(with: "123") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: Int64(0), context: nil) | ||
| XCTAssertEqual(result.value, 123) | ||
| } | ||
|
|
||
| func testDouble() { | ||
| let SUT = makeEvaluator(with: "3.14") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: 0.0, context: nil) | ||
| XCTAssertEqual(result.value, 3.14, accuracy: 0.0001) | ||
| } | ||
|
|
||
| func testString() { | ||
| let SUT = makeEvaluator(with: "banana") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: "default", context: nil) | ||
| XCTAssertEqual(result.value, "banana") | ||
| } | ||
|
|
||
| func testValue() { | ||
| let SUT = makeEvaluator(with: "json_string") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: OpenFeature.Value.string("default"), context: nil) | ||
| XCTAssertEqual(result.value, .string("json_string")) | ||
| } | ||
|
|
||
| func testInvalidTypeFallsBackToDefault() { | ||
| let SUT = makeEvaluator(with: "notAnInt") | ||
| let result = SUT.evaluate(key: "flag", defaultValue: Int64(42), context: nil) | ||
| XCTAssertEqual(result.value, 42, "Should return default when conversion fails") | ||
| } | ||
|
|
||
| func testWhenSplitClientIsNilReturnsControl() { | ||
| let SUT = Evaluator(splitClient: nil) | ||
| let result = SUT.evaluate(key: "flag", defaultValue: "default", context: nil) | ||
| XCTAssertEqual(result.value, Constants.CONTROL.rawValue) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.