Files
Schnappix/node_modules/expo-modules-core/ios/Tests/EnumerableSpec.swift
T

49 lines
1.3 KiB
Swift

// Copyright 2022-present 650 Industries. All rights reserved.
import ExpoModulesTestCore
@testable import ExpoModulesCore
final class EnumerableSpec: ExpoSpec {
override class func spec() {
describe("static createFromRawValue") {
it("succeeds") {
expect(try Position.create(fromRawValue: "top")) == .top
expect(try Position.create(fromRawValue: "right")) == .right
}
it("throws EnumNoSuchValueException") {
expect { try Position.create(fromRawValue: "top-right") }.to(
throwError(errorType: EnumNoSuchValueException.self)
)
}
it("throws EnumCastingException") {
expect { try Position.create(fromRawValue: 4729) }.to(
throwError(errorType: EnumCastingException.self)
)
expect { try Position.create(fromRawValue: ["left"]) }.to(
throwError(errorType: EnumCastingException.self)
)
}
}
describe("anyRawValue") {
it("returns type-erased raw value") {
expect(Position.left.anyRawValue as? String) == Position.left.rawValue
}
}
describe("allRawValues") {
it("returns all raw values") {
expect(Position.allRawValues as? [String]) == ["top", "right", "bottom", "left"]
}
}
}
}
private enum Position: String, Enumerable {
case top
case right
case bottom
case left
}