-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseerrortest.cpp
106 lines (86 loc) · 3.48 KB
/
parseerrortest.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/****************************************************************************
**
** Copyright (C) 2022 Dinu SV.
**
** This file is part of Livekeys Application.
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
****************************************************************************/
#include "catch_library.h"
#include "live/fileio.h"
#include "live/visuallog.h"
#include "live/datetime.h"
#include "live/applicationcontext.h"
#include "live/elements/compiler/languageparser.h"
#include "live/elements/compiler/compiler.h"
using namespace lv;
using namespace lv::el;
FileIO& fileIO(){
static FileIO fileio;
return fileio;
}
const std::string& scriptPath(){
static std::string scriptPath = Path::join(Path::parent(lv::ApplicationContext::instance().applicationFilePath()), "data");;
return scriptPath;
}
TEST_CASE( "Parse Error Test", "[ParseError]" ) {
SECTION("Program Body Extra Elements"){
std::string name = "ParserErrorTest01";
std::string filePath = scriptPath() + "/" + name + ".lv";
std::string contents = fileIO().readFromFile(filePath);
Compiler::Ptr compiler = Compiler::create();
compiler->configureImplicitType("console");
compiler->configureImplicitType("vlog");
bool hadException = false;
try {
compiler->compileToJs(filePath, contents);
} catch (lv::el::SyntaxException& e) {
REQUIRE(e.code() == lv::Exception::toCode("~Language"));
hadException = true;
}
REQUIRE(hadException);
}
SECTION("Identifier Not Found"){
std::string name = "ParserErrorTest02";
std::string filePath = scriptPath() + "/" + name + ".lv";
std::string contents = fileIO().readFromFile(scriptPath() + "/" + name + ".lv");
Compiler::Config compilerConfig;
compilerConfig.allowUnresolvedTypes(false);
Compiler::Ptr compiler = Compiler::create(compilerConfig);
compiler->configureImplicitType("console");
compiler->configureImplicitType("vlog");
bool hadException = false;
try {
compiler->compileToJs(filePath, contents);
} catch (lv::Exception& e) {
REQUIRE(e.code() == lv::Exception::toCode("~Identifier"));
hadException = true;
}
REQUIRE(hadException);
}
SECTION("Return in assignment expression"){
std::string name = "ParserErrorTest03";
std::string filePath = scriptPath() + "/" + name + ".lv";
std::string contents = fileIO().readFromFile(scriptPath() + "/" + name + ".lv");
Compiler::Config compilerConfig;
compilerConfig.allowUnresolvedTypes(false);
Compiler::Ptr compiler = Compiler::create(compilerConfig);
compiler->configureImplicitType("console");
compiler->configureImplicitType("vlog");
bool hadException = false;
try {
compiler->compileToJs(filePath, contents);
} catch (lv::Exception& e) {
REQUIRE(e.code() == lv::Exception::toCode("~Language"));
hadException = true;
}
REQUIRE(hadException);
}
}