Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
73 lines (59 loc) · 1.94 KB

File metadata and controls

73 lines (59 loc) · 1.94 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* 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 "llvh/Support/Casting.h"
#include "llvh/Support/SourceMgr.h"
#include "llvh/Support/YAMLParser.h"
#include "hermes/AST/ASTBuilder.h"
#include "hermes/AST/ESTreeVisitors.h"
#include "hermes/Parser/JSONParser.h"
#include "gtest/gtest.h"
using llvh::cast;
using llvh::dyn_cast;
using namespace hermes;
namespace {
const char *SimpleESTreeProgram =
" {"
" \"type\": \"Program\","
" \"body\": ["
" { "
" \"type\": \"FunctionDeclaration\","
" \"id\": {"
" \"type\": \"Identifier\","
" \"name\": \"my_name_is_foo\""
" }, "
" \"params\": [], "
" \"body\": {"
" \"type\": \"BlockStatement\","
" \"body\": [], "
" }, "
" \"generator\": false,"
" \"async\": false"
" } "
" ], "
" }";
TEST(ESTreeTest, EmptyTest) {
Context context;
parser::JSONFactory factory(context.getAllocator());
parser::JSONParser parser(
factory, SimpleESTreeProgram, context.getSourceErrorManager());
auto parsed = parser.parse();
ASSERT_TRUE(parsed.hasValue());
auto ast = ESTree::buildAST(context, parsed.getValue());
ASSERT_TRUE(ast.hasValue());
auto Node = ast.getValue();
/// Collect some information about the graph traits.
ESTree::TreeTrait TT;
Node->visit(TT);
EXPECT_EQ((int)TT.CurrDepth, 0);
EXPECT_EQ((int)TT.MaxDepth, 3);
EXPECT_EQ((int)TT.Count, 4);
auto &ProgramBody = cast<ESTree::ProgramNode>(Node)->_body;
auto FuncDecl = cast<ESTree::FunctionDeclarationNode>(&ProgramBody.front());
auto Name = cast<ESTree::IdentifierNode>(FuncDecl->_id)->_name;
EXPECT_STREQ("my_name_is_foo", Name->c_str());
}
} // end anonymous namespace
Morty Proxy This is a proxified and sanitized view of the page, visit original site.