-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Crystal::Repl#parse_and_interpret (#14138)
* Add Crystal::Repl#parse_and_interpret * Use single EvalResult type * skip if without_interpreter
- Loading branch information
Showing
2 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% skip_file if flag?(:without_interpreter) %} | ||
|
||
require "../../../spec_helper" | ||
|
||
private def success_value(result : Crystal::Repl::EvalResult) : Crystal::Repl::Value | ||
result.warnings.infos.should be_empty | ||
result.value.should_not be_nil | ||
end | ||
|
||
describe Crystal::Repl do | ||
it "can parse and evaluate snippets" do | ||
repl = Crystal::Repl.new | ||
repl.prelude = "primitives" | ||
repl.load_prelude | ||
|
||
success_value(repl.parse_and_interpret("1 + 2")).value.should eq(3) | ||
success_value(repl.parse_and_interpret("def foo; 1 + 2; end")).value.should eq(nil) | ||
success_value(repl.parse_and_interpret("foo")).value.should eq(3) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters