From 9872fc296cecbb50c6f4762f00d4891e2a03fbcf Mon Sep 17 00:00:00 2001 From: expelledboy <102334+expelledboy@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:13:28 +0000 Subject: [PATCH] test: for = character in tla body --- --- a/crates/jrsonnet-cli/src/stdlib.rs +++ b/crates/jrsonnet-cli/src/stdlib.rs @@ -10,8 +10,33 @@ pub value: String, } +/// Parses a string like `name=`, or `name` and reads value from env variable. +/// With no value it will be read from env variable. +/// If env variable is not found then it will be an error. +/// Value can contain `=` symbol. +/// +/// ``` +/// use std::str::FromStr; +/// use jrsonnet_cli::ExtStr; +/// +/// let ext = ExtStr::from_str("name=value").unwrap(); +/// assert_eq!(ext.name, "name"); +/// assert_eq!(ext.value, "value"); +/// +/// std::env::set_var("name", "value"); +/// +/// let ext = ExtStr::from_str("name").unwrap(); +/// assert_eq!(ext.name, "name"); +/// assert_eq!(ext.value, "value"); +/// +/// let ext = ExtStr::from_str("name=value=with=equals").unwrap(); +/// assert_eq!(ext.name, "name"); +/// assert_eq!(ext.value, "value=with=equals"); +/// ``` +/// impl FromStr for ExtStr { type Err = &'static str; + fn from_str(s: &str) -> std::result::Result { match s.find('=') { Some(idx) => Ok(ExtStr { -- gitstuff