Skip to content

Commit

Permalink
fix: Fix broken tuple test, now works Float2 or Float3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 7, 2024
1 parent 790def8 commit cf82da4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
15 changes: 8 additions & 7 deletions example/src/getTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-nitro-image/cpp/HybridTestObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ HybridTestObject::getVariantHybrid(const std::variant<std::shared_ptr<margelo::n
return variant;
}

std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>>
std::variant<std::tuple<double, double>, std::tuple<double, double, double>>
HybridTestObject::getVariantTuple(
const std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>>& variant) {
const std::variant<std::tuple<double, double>, std::tuple<double, double, double>>& variant) {
return variant;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-nitro-image/cpp/HybridTestObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class HybridTestObject : public HybridTestObjectSpec {
std::variant<Person, Car> getVariantObjects(const std::variant<Person, Car>& variant) override;
std::variant<std::shared_ptr<margelo::nitro::image::HybridTestObjectSpec>, Person>
getVariantHybrid(const std::variant<std::shared_ptr<margelo::nitro::image::HybridTestObjectSpec>, Person>& variant) override;
std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>> getVariantTuple(
const std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>>& variant) override;
std::variant<std::tuple<double, double>, std::tuple<double, double, double>> getVariantTuple(
const std::variant<std::tuple<double, double>, std::tuple<double, double, double>>& variant) override;

std::tuple<double, double, double> flip(const std::tuple<double, double, double>& tuple) override;
std::tuple<double, std::string, bool> passTuple(const std::tuple<double, std::string, bool>& tuple) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace margelo::nitro::image {
virtual std::variant<bool, OldEnum> getVariantEnum(const std::variant<bool, OldEnum>& variant) = 0;
virtual std::variant<Person, Car> getVariantObjects(const std::variant<Person, Car>& variant) = 0;
virtual std::variant<std::shared_ptr<margelo::nitro::image::HybridTestObjectSpec>, Person> getVariantHybrid(const std::variant<std::shared_ptr<margelo::nitro::image::HybridTestObjectSpec>, Person>& variant) = 0;
virtual std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>> getVariantTuple(const std::variant<std::vector<double>, std::tuple<double, std::string, bool>, std::tuple<double, double, double>>& variant) = 0;
virtual std::variant<std::tuple<double, double>, std::tuple<double, double, double>> getVariantTuple(const std::variant<std::tuple<double, double>, std::tuple<double, double, double>>& variant) = 0;
virtual std::tuple<double, double, double> flip(const std::tuple<double, double, double>& tuple) = 0;
virtual std::tuple<double, std::string, bool> passTuple(const std::tuple<double, std::string, bool>& tuple) = 0;
virtual int64_t calculateFibonacciSync(double value) = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit cf82da4

Please sign in to comment.