forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPILeanTest.cpp
More file actions
42 lines (33 loc) · 1.12 KB
/
APILeanTest.cpp
File metadata and controls
42 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <hermes/hermes.h>
#include <jsi/jsi.h>
using namespace facebook::jsi;
using namespace facebook::hermes;
namespace {
class HermesLeanRuntimeTest : public ::testing::Test {
public:
HermesLeanRuntimeTest() : rt(makeHermesRuntime()) {}
protected:
std::unique_ptr<HermesRuntime> rt;
};
TEST_F(HermesLeanRuntimeTest, PropertyTest) {
rt->global().setProperty(*rt, "answer", Value(42));
EXPECT_EQ(rt->global().getProperty(*rt, "answer").getNumber(), 42);
}
TEST_F(HermesLeanRuntimeTest, EvalTest) {
auto evalFn = rt->global().getPropertyAsFunction(*rt, "eval");
ASSERT_THROW(evalFn.call(*rt, "var x = 0;"), JSIException);
}
TEST_F(HermesLeanRuntimeTest, ArrayTest) {
auto array = Array::createWithElements(*rt, 5, 3, 1, 0, 2, 4);
array.getPropertyAsFunction(*rt, "sort").callWithThis(*rt, array);
for (size_t i = 0; i < 6; ++i)
EXPECT_EQ(array.getValueAtIndex(*rt, i).asNumber(), i);
}
} // namespace