This commit is contained in:
JT 2021-09-13 20:19:05 +12:00
parent 4dfde7393b
commit d7a3c7522b

View File

@ -2,10 +2,43 @@ use nu_parser::ParseError;
use nu_parser::*; use nu_parser::*;
use nu_protocol::{ use nu_protocol::{
ast::{Expr, Expression, Pipeline, Statement}, ast::{Expr, Expression, Pipeline, Statement},
engine::{EngineState, StateWorkingSet}, engine::{Command, EngineState, StateWorkingSet},
Signature, SyntaxShape, Signature, SyntaxShape,
}; };
#[cfg(test)]
pub struct Let;
#[cfg(test)]
impl Command for Let {
fn name(&self) -> &str {
"let"
}
fn usage(&self) -> &str {
"Create a variable and give it a value."
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("let")
.required("var_name", SyntaxShape::VarWithOptType, "variable name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
"equals sign followed by value",
)
}
fn run(
&self,
_context: &nu_protocol::engine::EvaluationContext,
_call: &nu_protocol::ast::Call,
_input: nu_protocol::Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
todo!()
}
}
#[test] #[test]
pub fn parse_int() { pub fn parse_int() {
let engine_state = EngineState::new(); let engine_state = EngineState::new();
@ -280,6 +313,8 @@ mod range {
let engine_state = EngineState::new(); let engine_state = EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state); let mut working_set = StateWorkingSet::new(&engine_state);
working_set.add_decl(Box::new(Let));
let (block, err) = parse(&mut working_set, None, b"let a = 2; $a..10", true); let (block, err) = parse(&mut working_set, None, b"let a = 2; $a..10", true);
assert!(err.is_none()); assert!(err.is_none());
@ -312,6 +347,8 @@ mod range {
let engine_state = EngineState::new(); let engine_state = EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state); let mut working_set = StateWorkingSet::new(&engine_state);
working_set.add_decl(Box::new(Let));
let (block, err) = parse(&mut working_set, None, b"let a = 2; $a..<($a + 10)", true); let (block, err) = parse(&mut working_set, None, b"let a = 2; $a..<($a + 10)", true);
assert!(err.is_none()); assert!(err.is_none());