difftreelog
Merge remote-tracking branch 'origin/master' into gcmodule
in: master
7 files changed
crates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -19,6 +19,8 @@
pub struct ManifestJsonOptions<'s> {
pub padding: &'s str,
pub mtype: ManifestType,
+ pub newline: &'s str,
+ pub key_val_sep: &'s str,
}
pub fn manifest_json_ex(val: &Val, options: &ManifestJsonOptions<'_>) -> Result<String> {
@@ -49,7 +51,7 @@
buf.push('[');
if !items.is_empty() {
if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
}
let old_len = cur_padding.len();
@@ -60,7 +62,7 @@
if mtype == ManifestType::ToString {
buf.push(' ');
} else if mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
}
}
buf.push_str(cur_padding);
@@ -69,7 +71,7 @@
cur_padding.truncate(old_len);
if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
buf.push_str(cur_padding);
}
} else if mtype == ManifestType::Std {
@@ -86,7 +88,7 @@
let fields = obj.fields();
if !fields.is_empty() {
if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
}
let old_len = cur_padding.len();
@@ -97,12 +99,12 @@
if mtype == ManifestType::ToString {
buf.push(' ');
} else if mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
}
}
buf.push_str(cur_padding);
escape_string_json_buf(&field, buf);
- buf.push_str(": ");
+ buf.push_str(options.key_val_sep);
push_description_frame(
|| format!("field <{}> manifestification", field.clone()),
|| {
@@ -115,7 +117,7 @@
cur_padding.truncate(old_len);
if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
- buf.push('\n');
+ buf.push_str(options.newline);
buf.push_str(cur_padding);
}
} else if mtype == ManifestType::Std {
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth1use crate::function::StaticBuiltin;1use crate::function::StaticBuiltin;2use crate::typed::{Any, Null, PositiveF64, VecVal, M1};2use crate::typed::{Any, PositiveF64, VecVal, M1};3use crate::{self as jrsonnet_evaluator, Either, ObjValue};4use crate::{3use crate::{5 builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},4 builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},6 equals,5 equals,10 typed::{Either2, Either4},9 typed::{Either2, Either4},11 with_state, ArrValue, Context, FuncVal, IndexableVal, Val,10 with_state, ArrValue, Context, FuncVal, IndexableVal, Val,12};11};12use crate::{Either, ObjValue};13use format::{format_arr, format_obj};13use format::{format_arr, format_obj};14use gcmodule::Cc;14use gcmodule::Cc;15use jrsonnet_interner::IStr;15use jrsonnet_interner::IStr;145fn builtin_length(x: Either![IStr, VecVal, ObjValue, Cc<FuncVal>]) -> Result<usize> {145fn builtin_length(x: Either![IStr, VecVal, ObjValue, Cc<FuncVal>]) -> Result<usize> {146 use Either4::*;146 use Either4::*;147 Ok(match x {147 Ok(match x {148 A(x) => x.len(),148 A(x) => x.chars().count(),149 B(x) => x.0.len(),149 B(x) => x.0.len(),150 C(x) => x150 C(x) => x151 .fields_visibility()151 .fields_visibility()568#[jrsonnet_macros::builtin]568#[jrsonnet_macros::builtin]569fn builtin_manifest_json_ex(value: Any, indent: IStr) -> Result<String> {569fn builtin_manifest_json_ex(570 value: Any,571 indent: IStr,572 newline: Option<IStr>,573 key_val_sep: Option<IStr>,574) -> Result<String> {575 let newline = newline.as_deref().unwrap_or("\n");576 let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");570 manifest_json_ex(577 manifest_json_ex(571 &value.0,578 &value.0,572 &ManifestJsonOptions {579 &ManifestJsonOptions {573 padding: &indent,580 padding: &indent,574 mtype: ManifestType::Std,581 mtype: ManifestType::Std,582 newline,583 key_val_sep,575 },584 },576 )585 )577}586}crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -5,6 +5,9 @@
clippy::ptr_arg
)]
+// For jrsonnet-macros
+extern crate self as jrsonnet_evaluator;
+
mod builtin;
mod ctx;
mod dynamic;
@@ -976,6 +979,14 @@
}
#[test]
+ fn json_minified() {
+ assert_json!(
+ r#"std.manifestJsonMinified({a:3, b:4, c:6})"#,
+ r#""{\"a\":3,\"b\":4,\"c\":6}""#
+ );
+ }
+
+ #[test]
fn parse_json() {
assert_json!(
r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#,
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -19,7 +19,7 @@
($($ty:ty)*) => {$(
impl Typed for $ty {
const TYPE: &'static ComplexValType =
- &ComplexValType::BoundedNumber(Some(<$ty>::MIN as f64), Some(<$ty>::MAX as f64));
+ &ComplexValType::BoundedNumber(Some(Self::MIN as f64), Some(Self::MAX as f64));
}
impl TryFrom<Val> for $ty {
type Error = LocError;
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -400,6 +400,8 @@
&ManifestJsonOptions {
padding: "",
mtype: ManifestType::ToString,
+ newline: "\n",
+ key_val_sep: ": ",
},
)?
.into(),
@@ -484,6 +486,8 @@
} else {
ManifestType::Manifest
},
+ newline: "\n",
+ key_val_sep: ": ",
},
)
.map(|s| s.into())
@@ -496,6 +500,8 @@
&ManifestJsonOptions {
padding: &" ".repeat(padding),
mtype: ManifestType::Std,
+ newline: "\n",
+ key_val_sep: ": ",
},
)
.map(|s| s.into())
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -105,7 +105,7 @@
if let Some(opt_ty) = extract_type_from_option(&t.ty) {
quote! {{
if let Some(value) = parsed.get(#ident) {
- Some(jrsonnet_evaluator::push_description_frame(
+ Some(::jrsonnet_evaluator::push_description_frame(
|| format!("argument <{}> evaluation", #ident),
|| <#opt_ty>::try_from(value.evaluate()?),
)?)
@@ -117,7 +117,7 @@
quote! {{
let value = parsed.get(#ident).unwrap();
- jrsonnet_evaluator::push_description_frame(
+ ::jrsonnet_evaluator::push_description_frame(
|| format!("argument <{}> evaluation", #ident),
|| <#ty>::try_from(value.evaluate()?),
)?
@@ -136,7 +136,7 @@
#[derive(Clone, Copy, gcmodule::Trace)]
#vis struct #name {}
const _: () = {
- use jrsonnet_evaluator::function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike};
+ use ::jrsonnet_evaluator::function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike};
const PARAMS: &'static [BuiltinParam] = &[
#(#params),*
];
@@ -156,7 +156,7 @@
PARAMS
}
fn call(&self, context: Context, loc: Option<&ExprLocation>, args: &dyn ArgsLike) -> Result<Val> {
- let parsed = jrsonnet_evaluator::function::parse_builtin_call(context, &PARAMS, args, false)?;
+ let parsed = ::jrsonnet_evaluator::function::parse_builtin_call(context, &PARAMS, args, false)?;
let result: #result = #name(#(#args),*);
let result = result?;
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -373,6 +373,8 @@
manifestJson(value):: std.manifestJsonEx(value, ' ') tailstrict,
+ manifestJsonMinified(value):: std.manifestJsonEx(value, '', '', ':'),
+
manifestJsonEx:: $intrinsic(manifestJsonEx),
manifestYamlDoc:: $intrinsic(manifestYamlDoc),
@@ -530,6 +532,9 @@
else
patch,
+ get(o, f, default = null, inc_hidden = true)::
+ if std.objectHasEx(o, f, inc_hidden) then o[f] else default,
+
objectFields(o)::
std.objectFieldsEx(o, false),