1 /**
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "common.h"
17 #include "util/arktsconfig.h"
18
19 namespace {
20
21 // NOTE(morlovsky): change to non-sideeffect ones (without opening the file)
22 // This will help with this nonsense of file opening on every parse
EmptyIncludeNeg()23 common::Params EmptyIncludeNeg()
24 {
25 return common::Params {
26 R"({
27 "include": []
28 })",
29 ark::es2panda::JoinPaths(common::CurrentSourceFileDir(), "arktsconfig_include_empty.json"), false};
30 }
31
IncludeStringNeg()32 common::Params IncludeStringNeg()
33 {
34 return common::Params {
35 R"({
36 "include": "abc"
37 })",
38 ark::es2panda::JoinPaths(common::CurrentSourceFileDir(), "arktsconfig_include_string.json"), false};
39 }
40
IncludeSomethingNeg()41 common::Params IncludeSomethingNeg()
42 {
43 return common::Params {
44 R"({
45 "include": null
46 })",
47 ark::es2panda::JoinPaths(common::CurrentSourceFileDir(), "arktsconfig_include_something.json"), false};
48 }
49
IncludeCorrect()50 common::Params IncludeCorrect()
51 {
52 return common::Params {
53 R"({
54 "include": [
55 "foo",
56 "bar"
57 ]
58 })",
59 ark::es2panda::JoinPaths(common::CurrentSourceFileDir(), "arktsconfig_include_correct.json"), true};
60 }
61
62 class ArkTsConfigInclude : public ::testing::TestWithParam<common::Params> {};
63
TEST_P(ArkTsConfigInclude,CheckInclude)64 TEST_P(ArkTsConfigInclude, CheckInclude)
65 {
66 auto param = GetParam();
67 auto config = ark::es2panda::ArkTsConfig {*param.path};
68 ASSERT_EQ(config.Parse(), param.expected);
69 }
70
71 INSTANTIATE_TEST_SUITE_P(ArkTsConfigIncludeSuite, ArkTsConfigInclude,
72 ::testing::Values(EmptyIncludeNeg(), IncludeStringNeg(), IncludeSomethingNeg(),
73 IncludeCorrect()));
74
75 } // namespace
76