Files
Rick 62902da52c fix(remote-config): align edge-case handling with Android implementation (#7173)
* Prefetch item-level remote config blobs

* Match workflow duplicate offering behavior

* Require complete remote UI config

* Update workflow UI config test fixtures

* refactor(remote-config): treat prefetch refs as unordered

* fix(remote-config): preserve prefetch blob order

* chore(remote-config): clean up UI config review notes

* fix(remote-config): default UI custom variables in decoder

* fix(remote-config): ignore embedded workflow UI config

* test(remote-config): update UI config fixtures

* refactor(remote-config): pass workflow ui config separately

* test(remote-config): wait for inline blob write attempt

* fix(remote-config): surface unavailable workflow ui config
2026-07-10 10:40:49 +02:00

107 lines
2.4 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ArrayExtensionsTests.swift
//
// Created by Nacho Soto on 2/17/22.
import Nimble
import XCTest
@testable import RevenueCat
class ArrayExtensionsTests: TestCase {
// MARK: - popFirst
func testPopFirstWithEmptyArray() {
var array: [Int] = []
expect(array.popFirst()).to(beNil())
expect(array) == []
}
func testPopFirstWithOneElement() {
var array: [Int] = [1]
let element = array.popFirst()
expect(element) == 1
expect(array) == []
}
func testPopFirstWithMultipleElements() {
var array: [Int] = [3, 2, 1]
let element = array.popFirst()
expect(element) == 3
expect(array) == [2, 1]
}
// MARK: - onlyElement
func testOnlyElementWithEmptyArray() {
expect([Any]().onlyElement).to(beNil())
}
func testOnlyElementWithMultipleElements() {
expect([1, 2].onlyElement).to(beNil())
}
func testOnlyElementWithSingleElement() {
expect([1].onlyElement) == 1
}
// MARK: - safeIndex
func testSafeIndexWithEmptyArray() {
expect([Any]()[safe: 0]).to(beNil())
expect([Any]()[safe: 1]).to(beNil())
}
func testSafeIndexWithMultipleElements() {
expect([1, 2][safe: 0]) == 1
expect([1, 2][safe: 1]) == 2
expect([1, 2][safe: 3]).to(beNil())
}
func testSafeIndexWithSingleElement() {
expect([1][safe: 0]) == 1
expect([1][safe: 1]).to(beNil())
}
// MARK: - sum
func testSumEmptyArray() {
expect([Int]().sum()) == 0
}
func testSumSingleElementArray() {
expect([5].sum()) == 5
}
func testSumArrayWithMultipleElements() {
expect([1, 2, 3].sum()) == 6
}
// MARK: - deduplicated
func testDeduplicatedWithEmptyArray() {
expect([Int]().deduplicated()) == []
}
func testDeduplicatedPreservesFirstOccurrenceOrder() {
expect([3, 1, 2, 3, 2, 4, 1].deduplicated()) == [3, 1, 2, 4]
}
func testDeduplicatedWithStrings() {
expect(["a", "b", "a", "c", "b"].deduplicated()) == ["a", "b", "c"]
}
}