-
Notifications
You must be signed in to change notification settings - Fork 26
Run clj file as script & evaluate expression #45
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
Run clj file as script & evaluate expression #45
Conversation
Nice work! |
src/user_action.rs
Outdated
} | ||
} | ||
|
||
pub fn parse_args() -> Action{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this fn so that it takes the Vec env variables as input
src/main.rs
Outdated
// | ||
// Start repl | ||
// | ||
let cli_args: user_action::Action = user_action::parse_args(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to user_action::parse_args( env::args().collect() );
src/user_action.rs
Outdated
|
||
pub fn parse_args() -> Action{ | ||
|
||
let arguments: Vec<String> = env::args().collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this can be removed,
So you can write trivial unit tests for the cases (Runscript, Evaluate and Nothing) to check that parse_args return correct enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made changes in d848959
src/user_action.rs
Outdated
use crate::user_action; | ||
|
||
#[test] | ||
fn parse_args_test() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could group these test under a
mod parse_args_tests
, and under that mod have one test per assertion, ie.
fn parses_args_given_path
just asserts what it describes
you can see examples in other files, this makes nice and organized and descriptive test output and it’s also easy to run certain tests
Hardcoding based on arguments.len() == 3 for now Examples: --init/-i for script or --eval/-e for evaluate expression cargo run -- --init examples/hello_world.clj cargo run -- --eval "(println \"eh\")" cargo run -- --eval "(+ 1 2)"
Changing output of cargo run -- --eval "(+ 1 2)" from I32(3) to 3
…le (and fixed some formatting)
ee6b46c
to
ee27d1a
Compare
Hardcoding based on arguments.len() == 3 for now
Examples:
--init/-i for script or --eval/-e for evaluate expression
cargo run -- --init examples/hello_world.clj
cargo run -- --eval "(println \"eh\")"
cargo run -- --eval "(+ 1 2)"