From cf82da433977d68093b65a2d9c9d2beac5c14cec Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Wed, 7 Aug 2024 14:29:23 +0200 Subject: [PATCH] fix: Fix broken tuple test, now works Float2 or Float3 --- example/src/getTests.ts | 15 ++++++++------- .../cpp/HybridTestObject.cpp | 4 ++-- .../cpp/HybridTestObject.hpp | 4 ++-- .../generated/shared/c++/HybridTestObjectSpec.hpp | 2 +- .../src/specs/TestObject.nitro.ts | 5 ++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/example/src/getTests.ts b/example/src/getTests.ts index 99e47d722..8d99a92b5 100644 --- a/example/src/getTests.ts +++ b/example/src/getTests.ts @@ -335,20 +335,21 @@ export function getTests(): TestRunner[] { HybridTestObject.getVariantHybrid({ someValue: 55 }) ).didThrow() ), - createTest('getVariantTuple(...) converts TestTuple', () => - it(() => HybridTestObject.getVariantTuple([532, 'hello', false])) + createTest('getVariantTuple(...) converts Float2', () => + it(() => HybridTestObject.getVariantTuple([10, 20])) .didNotThrow() - .equals([532, 'hello', false]) + .equals([10, 20]) ), createTest('getVariantTuple(...) converts Float3', () => it(() => HybridTestObject.getVariantTuple([10, 20, 30])) .didNotThrow() .equals([10, 20, 30]) ), - createTest('getVariantTuple(...) converts number[]', () => - it(() => HybridTestObject.getVariantTuple([10, 20, 30, 40, 50])) - .didNotThrow() - .equals([10, 20, 30, 40, 50]) + createTest('getVariantTuple(...) throws at wrong size (4 items)', () => + it(() => + // @ts-expect-error + HybridTestObject.getVariantTuple([10, 20, 30, 40, 50]) + ).didThrow() ), createTest('getVariantTuple(...) throws at wrong type (string)', () => // @ts-expect-error diff --git a/packages/react-native-nitro-image/cpp/HybridTestObject.cpp b/packages/react-native-nitro-image/cpp/HybridTestObject.cpp index 0e3bf03d4..5dcb8414a 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObject.cpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObject.cpp @@ -169,9 +169,9 @@ HybridTestObject::getVariantHybrid(const std::variant, std::tuple, std::tuple> +std::variant, std::tuple> HybridTestObject::getVariantTuple( - const std::variant, std::tuple, std::tuple>& variant) { + const std::variant, std::tuple>& variant) { return variant; } diff --git a/packages/react-native-nitro-image/cpp/HybridTestObject.hpp b/packages/react-native-nitro-image/cpp/HybridTestObject.hpp index 15f534b57..3dc249b87 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObject.hpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObject.hpp @@ -71,8 +71,8 @@ class HybridTestObject : public HybridTestObjectSpec { std::variant getVariantObjects(const std::variant& variant) override; std::variant, Person> getVariantHybrid(const std::variant, Person>& variant) override; - std::variant, std::tuple, std::tuple> getVariantTuple( - const std::variant, std::tuple, std::tuple>& variant) override; + std::variant, std::tuple> getVariantTuple( + const std::variant, std::tuple>& variant) override; std::tuple flip(const std::tuple& tuple) override; std::tuple passTuple(const std::tuple& tuple) override; diff --git a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSpec.hpp b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSpec.hpp index 62fbbdf89..b6afce8b8 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSpec.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSpec.hpp @@ -97,7 +97,7 @@ namespace margelo::nitro::image { virtual std::variant getVariantEnum(const std::variant& variant) = 0; virtual std::variant getVariantObjects(const std::variant& variant) = 0; virtual std::variant, Person> getVariantHybrid(const std::variant, Person>& variant) = 0; - virtual std::variant, std::tuple, std::tuple> getVariantTuple(const std::variant, std::tuple, std::tuple>& variant) = 0; + virtual std::variant, std::tuple> getVariantTuple(const std::variant, std::tuple>& variant) = 0; virtual std::tuple flip(const std::tuple& tuple) = 0; virtual std::tuple passTuple(const std::tuple& tuple) = 0; virtual int64_t calculateFibonacciSync(double value) = 0; diff --git a/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts b/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts index 521fa5ea0..7f011a052 100644 --- a/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts +++ b/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts @@ -1,5 +1,6 @@ import { type HybridObject, type AnyMap } from 'react-native-nitro-modules' +export type Float2 = [number, number] export type Float3 = [number, number, number] export type TestTuple = [number, string, boolean] @@ -61,9 +62,7 @@ export interface TestObject extends HybridObject<{ ios: 'c++' }> { getVariantEnum(variant: OldEnum | boolean): OldEnum | boolean getVariantObjects(variant: Person | Car): Person | Car getVariantHybrid(variant: TestObject | Person): TestObject | Person - getVariantTuple( - variant: TestTuple | Float3 | number[] - ): TestTuple | Float3 | number[] + getVariantTuple(variant: Float2 | Float3): Float2 | Float3 // Tuples someTuple: [number, string]