2026-06-02 14:38:34 +02:00
|
|
|
//
|
|
|
|
|
// StringArrayOperatorsTests.swift
|
|
|
|
|
//
|
|
|
|
|
// Created by Antonio Pallares.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
|
2026-07-27 16:28:21 +02:00
|
|
|
@testable import RevenueCat
|
2026-06-02 14:38:34 +02:00
|
|
|
|
2026-07-27 18:26:46 +02:00
|
|
|
private typealias Value = RulesEngine.Value
|
|
|
|
|
private typealias StringArrayOperators = RulesEngine.StringArrayOperators
|
|
|
|
|
|
2026-06-02 14:38:34 +02:00
|
|
|
final class StringArrayOperatorsTests: XCTestCase {
|
|
|
|
|
|
|
|
|
|
// MARK: - merge
|
|
|
|
|
|
2026-06-08 10:15:19 +02:00
|
|
|
/// Kept as a Swift test (not migrated to a JSON fixture): `merge`
|
|
|
|
|
/// returns an array, and this engine's loose `==` string-coerces
|
|
|
|
|
/// `[[1], 2]` and `[1, 2]` to the same `"1,2"`, so no predicate can
|
|
|
|
|
/// verify that nested arrays are NOT recursively flattened. Only a
|
|
|
|
|
/// structural `Value` comparison can.
|
2026-06-02 14:38:34 +02:00
|
|
|
func testMergeDoesNotRecurseOnNestedArrays() throws {
|
|
|
|
|
// Only one level of flattening — inner arrays remain.
|
|
|
|
|
let out = try StringArrayOperators.opMerge(
|
|
|
|
|
args: arr(arr(arr(.int(1)), .int(2))),
|
2026-08-19 10:04:21 +02:00
|
|
|
vars: RulesEngine.Scope(root: Value.null)
|
2026-06-02 14:38:34 +02:00
|
|
|
)
|
|
|
|
|
XCTAssertEqual(out, arr(arr(.int(1)), .int(2)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Helpers
|
|
|
|
|
|
|
|
|
|
private func arr(_ items: Value...) -> Value {
|
|
|
|
|
.array(items)
|
|
|
|
|
}
|
|
|
|
|
}
|