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);
}
}
if let Some(span) = span {
return Err(ShellError::labeled_error(
"External $it needs string data",
"given object instead of string data",
span,
));
} else {
return Err(ShellError::string("Error: $it needs string data"));
}
return Err(ShellError::maybe_labeled_error(
"External $it needs string data",
"given object instead of string data",
span,
));
}
if !first {
new_arg_string.push_str("&&");

View File

@ -291,7 +291,12 @@ impl Value {
crate fn as_string(&self) -> Result<String, ShellError> {
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
other => Err(ShellError::string(format!(
"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

@ -1,20 +1,24 @@
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"Height": 10,
"GlossDef": {
"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() {
test_helper("lines");
}
#[test]
fn external_num() {
test_helper("external_num");
}
}