Skip to content

Commit aac089b

Browse files
committed
Rename and update tests
1 parent 5c6c828 commit aac089b

8 files changed

+16
-13
lines changed

src/shell/AST.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ struct BuiltinSetStmt final: public Statement
169169
};
170170

171171

172-
struct BuiltinGetStmt final: public Statement
172+
struct VariableSubstExpr final: public Statement
173173
{
174174
std::reference_wrapper<CoreVM::NativeCallback const> callback;
175175
std::unique_ptr<Expr> name;
176176

177-
BuiltinGetStmt(std::reference_wrapper<CoreVM::NativeCallback const> callback,
177+
VariableSubstExpr(std::reference_wrapper<CoreVM::NativeCallback const> callback,
178178
std::unique_ptr<Expr> name):
179179
callback { callback }, name {std::move( name )}
180180
{

src/shell/ASTPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ export class ASTPrinter: public Visitor
9090
}
9191
}
9292

93-
void visit(BuiltinGetStmt const& node) override
93+
void visit(VariableSubstExpr const& node) override
9494
{
95-
_result += "get";
95+
_result += "substitute";
9696

9797
if (node.name)
9898
{

src/shell/IRGenerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class IRGenerator final: public CoreVM::IRBuilder, public ast::Visitor
104104
_result = createCallFunction(getBuiltinFunction(node.callback.get()), callArguments, "set");
105105
}
106106

107-
void visit(ast::BuiltinGetStmt const& node) override
107+
void visit(ast::VariableSubstExpr const& node) override
108108
{
109109
auto callArguments = std::vector<CoreVM::Value*> {};
110110
if (node.name )

src/shell/Lexer_test.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Lexer;
55

66
TEST_CASE("Lexer.basic")
77
{
8-
auto lexer = endo::Lexer(std::make_unique<endo::StringSource>("echo hello world $PATH"));
8+
auto lexer = endo::Lexer(std::make_unique<endo::StringSource>("echo hello world $PATH ${PATH}"));
99
CHECK(lexer.currentToken() == endo::Token::Identifier);
1010
CHECK(lexer.currentLiteral() == "echo");
1111

@@ -21,6 +21,10 @@ TEST_CASE("Lexer.basic")
2121
CHECK(lexer.currentToken() == endo::Token::DollarName);
2222
CHECK(lexer.currentLiteral() == "PATH");
2323

24+
lexer.nextToken();
25+
CHECK(lexer.currentToken() == endo::Token::DollarName);
26+
CHECK(lexer.currentLiteral() == "PATH");
27+
2428
lexer.nextToken();
2529
CHECK(lexer.currentToken() == endo::Token::EndOfInput);
2630
}

src/shell/Parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class Parser
9999
case Token::DollarName: {
100100
auto name = std::make_unique<ast::LiteralExpr>(_lexer.currentLiteral());
101101
_lexer.nextToken();
102-
return std::make_unique<ast::BuiltinGetStmt>(*_runtime.find("get(S)S"), std::move(name));
102+
return std::make_unique<ast::VariableSubstExpr>(*_runtime.find("substitute(S)S"), std::move(name));
103103
}
104104
case Token::String:
105105
case Token::Identifier:

src/shell/Shell.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ export class Shell final: public CoreVM::Runtime
340340
.returnType(CoreVM::LiteralType::Boolean)
341341
.bind(&Shell::builtinSet, this);
342342

343-
registerFunction("get")
343+
registerFunction("substitute")
344344
.param<std::string>("name")
345345
.returnType(CoreVM::LiteralType::String)
346-
.bind(&Shell::builtinGet, this);
346+
.bind(&Shell::builtinVariableSubst, this);
347347

348348

349349
registerFunction("callproc")
@@ -549,7 +549,7 @@ export class Shell final: public CoreVM::Runtime
549549
_env.set(context.getString(1), context.getString(2));
550550
context.setResult(true);
551551
}
552-
void builtinGet(CoreVM::Params& context)
552+
void builtinVariableSubst(CoreVM::Params& context)
553553
{
554554
auto res = _env.get(context.getString(1));
555555
if(res.has_value())

src/shell/Shell_test.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ TEST_CASE("shell.builtin.get_variable_inside_curl_brackets")
9292
TestShell shell;
9393
shell("set BRU hello");
9494
CHECK(shell.env.get("BRU").value_or("NONE") == "hello");
95-
fmt::print("=======================================\n");
9695
shell("${BRU}");
9796
}
9897

src/shell/Visitor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace endo::ast
66

77
struct BuiltinChDirStmt;
88
struct BuiltinSetStmt;
9-
struct BuiltinGetStmt;
9+
struct VariableSubstExpr;
1010
struct BuiltinExportStmt;
1111
struct BuiltinFalseStmt;
1212
struct BuiltinExitStmt;
@@ -49,7 +49,7 @@ struct Visitor
4949
virtual void visit(BuiltinReadStmt const&) = 0;
5050
virtual void visit(BuiltinChDirStmt const&) = 0;
5151
virtual void visit(BuiltinSetStmt const&) = 0;
52-
virtual void visit(BuiltinGetStmt const&) = 0;
52+
virtual void visit(VariableSubstExpr const&) = 0;
5353

5454
// epxressions
5555
virtual void visit(LiteralExpr const&) = 0;

0 commit comments

Comments
 (0)