Files
purchases-ios/RulesEngineInternal/Operators/EqualityOperators.swift
T
Antonio PallaresandCursor 0ff0e3dafe Merge branch 'pallares/rules-engine-enforce-internal-api' into pallares/json-logic-evaluator
Brings in:
- The `RulesEngine` → `RulesEngineInternal` module rename from #6787.
- The `no_leaking_rules_engine_internal_import` SwiftLint rule update from #6788.
- Plus the `main`-merge cascade carried by #6788.

Conflicts resolved:

- `RulesEngineInternal/RulesEngineInternal.swift`: kept this branch's
  `Rules.logger` / `LoggerStorage` storage, dropped the
  `@_spi(Internal)` marker on `public enum Rules` (since #6787 dropped
  those markers; the new SwiftLint rule replaces that gate).
- `RevenueCat.xcodeproj/project.pbxproj`: kept this branch's full file
  list (Evaluator, Logger, Value, RuleError, Operators/*, plus the new
  test files and helpers), then applied the producer-side rename to
  every `RulesEngine\b` / `RulesEngineTests\b` token (target name,
  group name, path, productName, bundle IDs `com.revenuecat.RulesEngineInternal[Tests]`,
  framework / xctest output names, and the `RulesEngine.swift` → `RulesEngineInternal.swift`
  file ref).

Other rename follow-ups in this branch's added files:

- `Tests/RulesEngineInternalTests/*.swift` (8 files) — every
  `[@_spi(Internal) ]@testable import RulesEngine` updated to
  `@testable import RulesEngineInternal`. The `@_spi(Internal)`
  attribute is no longer needed because the producer no longer uses
  SPI markers.
- `Projects/RulesEngineInternal/`, `RulesEngineInternal/`, and
  `Tests/RulesEngineInternalTests/` directories were moved
  automatically by git's directory-rename detection (15 file renames).

Left intentionally unchanged:

- `RulesEngineInternal/Logger.swift` — the development-only
  `PrintLogger` keeps its `[RulesEngine]` log prefix because that
  string identifies the subsystem (the rules engine) for log readers,
  not the producer-side module name. The injected production logger
  replaces this struct entirely once the engine is wired into the SDK,
  so the prefix is throwaway.
- `RulesEngineLogger` protocol name — internal type name within the
  module, not part of the import-site signal that motivated the
  module rename.
- The `Rules` namespace name — separate identifier from the module
  name, kept stable so call sites still write `Rules.something`.

Verified locally:
- `swift build --target RulesEngineInternal` ✔
- `swift test --filter RulesEngineInternalTests` ✔ — 75 tests passed
- `xcodebuild -scheme RulesEngineInternal -destination 'generic/platform=iOS' build` ✔
- `swiftlint --no-cache` ✔ — 0 violations across 1332 files
- `git ls-files | xargs perl -ne 'if (/\bRulesEngine\b/ && !/RulesEngineInternal/) { ... }'` returns only the `[RulesEngine]` log prefix mentioned above.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 17:51:26 +02:00

39 lines
1.4 KiB
Swift

//
// EqualityOperators.swift
//
// Created by Antonio Pallares.
//
import Foundation
/// Equality operators: `==`, `!=`, `===`, `!==`.
enum EqualityOperators {
/// `{"==": [a, b]}` — JSON Logic loose equality. Coerces across primitive
/// types (e.g. `1 == "1"` is true). Full coercion table in `looseEq`.
static func opLooseEq(args: Value, vars: Value) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars, opName: "==")
return .bool(looseEq(lhs, rhs))
}
/// `{"!=": [a, b]}` — JSON Logic loose inequality. Negation of `==`.
static func opLooseNe(args: Value, vars: Value) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars, opName: "!=")
return .bool(!looseEq(lhs, rhs))
}
/// `{"===": [a, b]}` — JSON Logic strict equality. Same type, same value
/// (`1 === "1"` is false). See `strictEq` for the numeric subtlety
/// around `int` vs `float`.
static func opStrictEq(args: Value, vars: Value) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars, opName: "===")
return .bool(strictEq(lhs, rhs))
}
/// `{"!==": [a, b]}` — JSON Logic strict inequality. Negation of `===`.
static func opStrictNe(args: Value, vars: Value) throws -> Value {
let (lhs, rhs) = try Operators.evalTwo(args, vars: vars, opName: "!==")
return .bool(!strictEq(lhs, rhs))
}
}