Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unittest #74

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix unittest
  • Loading branch information
ShigekiKarita committed Nov 26, 2018
commit 3701c2a1f11d0893f5aabc667a520073ceb9a37b
47 changes: 28 additions & 19 deletions src/drepl/interpreter.d
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,29 @@ private:
return !hasErr;
}

unittest
static if (is(Engine == EchoEngine))
{
auto intp = interpreter(echoEngine());
assert(intp.classify("3+2") == Kind.Expr);
// only single expressions
assert(intp.classify("3+2 foo()") == Kind.Error);
assert(intp.classify("3+2;") == Kind.Stmt);
// multiple statements
assert(intp.classify("3+2; foo();") == Kind.Stmt);
assert(intp.classify("struct Foo {}") == Kind.Decl);
// multiple declarations
assert(intp.classify("void foo() {} void bar() {}") == Kind.Decl);
// can't currently mix declarations and statements
assert(intp.classify("void foo() {} foo();") == Kind.Error);
// or declarations and expressions
assert(intp.classify("void foo() {} foo()") == Kind.Error);
// or statments and expressions
assert(intp.classify("foo(); foo()") == Kind.Error);

assert(intp.classify("import std.stdio;") == Kind.Decl);
unittest
{
auto intp = interpreter(echoEngine());
assert(intp.classify("3+2") == Kind.Expr);
// only single expressions
assert(intp.classify("3+2 foo()") == Kind.Error);
assert(intp.classify("3+2;") == Kind.Stmt);
// multiple statements
assert(intp.classify("3+2; foo();") == Kind.Stmt);
assert(intp.classify("struct Foo {}") == Kind.Decl);
// multiple declarations
assert(intp.classify("void foo() {} void bar() {}") == Kind.Decl);
// can't currently mix declarations and statements
assert(intp.classify("void foo() {} foo();") == Kind.Error);
// or declarations and expressions
assert(intp.classify("void foo() {} foo()") == Kind.Error);
// or statments and expressions
assert(intp.classify("foo(); foo()") == Kind.Error);

assert(intp.classify("import std.stdio;") == Kind.Decl);
}
}

Engine _engine;
Expand All @@ -154,6 +157,12 @@ Interpreter!Engine interpreter(Engine)(return scope Engine e) if (isEngine!Engin
return Interpreter!Engine(() @trusted { return move(e); }());
}

unittest
{
// test instantiated
auto i = interpreter(dmdEngine());
}

unittest
{
alias IR = InterpreterResult;
Expand Down