Touchups to external values

This commit is contained in:
Jonathan Turner 2019-06-19 17:51:24 +12:00
parent bec9fd2d2b
commit b4eb32f1db
6 changed files with 34 additions and 19 deletions

View File

@ -240,15 +240,11 @@ impl ExternalCommand {
span = Some(arg.span); span = Some(arg.span);
} }
} }
if let Some(span) = span { return Err(ShellError::maybe_labeled_error(
return Err(ShellError::labeled_error(
"External $it needs string data", "External $it needs string data",
"given object instead of string data", "given object instead of string data",
span, span,
)); ));
} else {
return Err(ShellError::string("Error: $it needs string data"));
}
} }
if !first { if !first {
new_arg_string.push_str("&&"); new_arg_string.push_str("&&");

View File

@ -291,7 +291,12 @@ impl Value {
crate fn as_string(&self) -> Result<String, ShellError> { crate fn as_string(&self) -> Result<String, ShellError> {
match self { match self {
Value::Primitive(Primitive::String(s)) => Ok(s.clone()), Value::Primitive(Primitive::String(x)) => Ok(format!("{}", x)),
Value::Primitive(Primitive::Boolean(x)) => Ok(format!("{}", x)),
Value::Primitive(Primitive::Float(x)) => Ok(format!("{}", x.into_inner())),
Value::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)),
Value::Primitive(Primitive::Bytes(x)) => Ok(format!("{}", x)),
//Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
// TODO: this should definitely be more general with better errors // TODO: this should definitely be more general with better errors
other => Err(ShellError::string(format!( other => Err(ShellError::string(format!(
"Expected string, got {:?}", "Expected string, got {:?}",

1
tests/external_num.out Normal file
View File

@ -0,0 +1 @@
10

3
tests/external_num.txt Normal file
View File

@ -0,0 +1,3 @@
cd tests
open test.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it
exit

View File

@ -10,9 +10,13 @@
"GlossTerm": "Standard Generalized Markup Language", "GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML", "Acronym": "SGML",
"Abbrev": "ISO 8879:1986", "Abbrev": "ISO 8879:1986",
"Height": 10,
"GlossDef": { "GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.", "para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"] "GlossSeeAlso": [
"GML",
"XML"
]
}, },
"GlossSee": "markup" "GlossSee": "markup"
} }

View File

@ -101,4 +101,10 @@ mod tests {
fn lines() { fn lines() {
test_helper("lines"); test_helper("lines");
} }
#[test]
fn external_num() {
test_helper("external_num");
}
} }