difftreelog
Merge commit 'd93ca83fe3668f134c0a705b972e2b52072ebf3d'
in: master
3 files changed
.github/workflows/release.ymldiffbeforeafterboth53 needs: [test]53 needs: [test]54 strategy:54 strategy:55 matrix:55 matrix:56 os: [ubuntu-latest, macOS-latest, windows-latest]56 target:57 # Tier 158 - aarch64-unknown-linux-gnu59 - i686-pc-windows-gnu60 - i686-pc-windows-msvc61 - i686-unknown-linux-gnu62 - x86_64-apple-darwin63 - x86_64-pc-windows-gnu64 - x86_64-pc-windows-msvc65 - x86_64-unknown-linux-gnu6667 # Other68 - x86_64-unknown-linux-musl57 include:69 include:58 - os: ubuntu-latest70 - target: aarch64-unknown-linux-gnu59 rust: stable71 os: ubuntu-latest60 target: x86_64-unknown-linux-musl61 bin: jrsonnet72 bin: jrsonnet62 name: jrsonnet-linux-amd6473 name: jrsonnet-linux-gnu-aarch6463 - os: windows-latest74 - target: i686-pc-windows-gnu64 rust: stable75 os: windows-latest65 target: x86_64-pc-windows-msvc66 bin: jrsonnet.exe76 bin: jrsonnet.exe67 name: jrsonnet-windows-amd64.exe77 name: jrsonnet-windows-gnu-i686.exe78 - target: i686-pc-windows-msvc79 os: windows-latest80 bin: jrsonnet.exe81 name: jrsonnet-windows-msvc-i686.exe82 - target: i686-unknown-linux-gnu83 os: ubuntu-latest84 bin: jrsonnet85 name: jrsonnet-linux-gnu-i68668 - os: macOS-latest86 - target: x86_64-apple-darwin69 rust: stable87 os: macOS-latest70 target: x86_64-apple-darwin71 bin: jrsonnet88 bin: jrsonnet72 name: jrsonnet-darwin-amd6489 name: jrsonnet-darwin-amd6490 - target: x86_64-pc-windows-gnu91 os: windows-latest92 bin: jrsonnet.exe93 name: jrsonnet-windows-gnu-amd64.exe94 - target: x86_64-pc-windows-msvc95 os: windows-latest96 bin: jrsonnet.exe97 name: jrsonnet-windows-msvc-amd64.exe98 - target: x86_64-unknown-linux-gnu99 os: ubuntu-latest100 bin: jrsonnet101 name: jrsonnet-linux-gnu-amd64102103 - target: x86_64-unknown-linux-musl104 os: ubuntu-latest105 bin: jrsonnet106 name: jrsonnet-linux-musl-amd6473 runs-on: ${{ matrix.os }}107 runs-on: ${{ matrix.os }}74 steps:108 steps:75 - name: Install stable toolchain109 - name: Install stable toolchain76 uses: actions-rs/toolchain@v1110 uses: actions-rs/toolchain@v177 with:111 with:78 toolchain: ${{ matrix.rust }}112 toolchain: stable79 override: true113 override: true80 target: ${{ matrix.target }}114 target: ${{ matrix.target }}11581 - name: Checkout116 - name: Checkout82 uses: actions/checkout@v2117 uses: actions/checkout@v2118119 - name: Linux x86 cross compiler120 if: ${{ matrix.target == 'i686-unknown-linux-gnu' }}121 run: sudo apt install gcc-multilib122123 - name: Windows x86 cross compiler124 if: ${{ matrix.target == 'i686-pc-windows-gnu' }}125 uses: egor-tensin/setup-mingw@v2126 with:127 platform: x86128129 - name: ARM cross compiler130 if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}131 uses: actions-rs/cargo@v1132 with:133 command: install134 args: cross135136 - name: Run ARM build137 if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}138 shell: bash139 run: cross --bin=jrsonnet --release --target ${{ matrix.target }}14083 - name: Run build141 - name: Run build142 if: ${{ matrix.target != 'aarch64-unknown-linux-gnu' }}84 uses: actions-rs/cargo@v1143 uses: actions-rs/cargo@v185 with:144 with:86 command: build145 command: buildcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,8 +1,8 @@
use crate::{
equals,
error::{Error::*, Result},
- parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, FuncVal, LazyVal,
- Val,
+ parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, EvaluationState,
+ FuncVal, LazyVal, Val,
};
use format::{format_arr, format_obj};
use jrsonnet_interner::IStr;
@@ -74,6 +74,7 @@
("reverse".into(), builtin_reverse),
("id".into(), builtin_id),
("strReplace".into(), builtin_str_replace),
+ ("parseJson".into(), builtin_parse_json),
].iter().cloned().collect()
};
}
@@ -164,6 +165,20 @@
})
}
+fn builtin_parse_json(
+ context: Context,
+ _loc: Option<&ExprLocation>,
+ args: &ArgsDesc,
+) -> Result<Val> {
+ parse_args!(context, "parseJson", args, 1, [
+ 0, s: ty!(string) => Val::Str;
+ ], {
+ let state = EvaluationState::default();
+ let path = Rc::new(PathBuf::from("std.parseJson"));
+ state.evaluate_snippet_raw(path ,s)
+ })
+}
+
// faster
fn builtin_slice(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "slice", args, 4, [
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -809,6 +809,21 @@
}
#[test]
+ fn parse_json() {
+ assert_json!(
+ r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#,
+ r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"#
+ );
+ // TODO: this should in fact fail as is no proper JSON syntax
+ assert_json!(
+ r#"std.parseJson("{a:-1, b:1, c:3.141, d:[]}")"#,
+ r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"#
+ );
+ // TODO: this is also no valid JSON
+ assert_json!(r#"std.parseJson('local x = 2; x * x')"#, r#"4"#);
+ }
+
+ #[test]
fn test() {
assert_json!(
r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,