Switch to single quotes for template strings

This commit is contained in:
Gregory Schier
2024-08-22 12:48:14 -07:00
parent adda44e861
commit 6766bc8f59
3 changed files with 15 additions and 15 deletions

View File

@@ -48,7 +48,7 @@ pub enum Val {
impl Display for Val { impl Display for Val {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self { let str = match self {
Val::Str { text } => format!(r#""{}""#, text.to_string().replace(r#"""#, r#"\""#)), Val::Str { text } => format!("'{}'", text.to_string().replace("'", "\'")),
Val::Var { name } => name.to_string(), Val::Var { name } => name.to_string(),
Val::Bool { value } => value.to_string(), Val::Bool { value } => value.to_string(),
Val::Fn { name, args } => { Val::Fn { name, args } => {
@@ -297,7 +297,7 @@ impl Parser {
let start_pos = self.pos; let start_pos = self.pos;
let mut text = String::new(); let mut text = String::new();
if !self.match_str("\"") { if !self.match_str("'") {
return None; return None;
} }
@@ -308,7 +308,7 @@ impl Parser {
'\\' => { '\\' => {
text.push(self.next_char()); text.push(self.next_char());
} }
'"' => { '\'' => {
found_closing = true; found_closing = true;
break; break;
} }
@@ -436,13 +436,13 @@ mod tests {
#[test] #[test]
fn tag_string() { fn tag_string() {
let mut p = Parser::new(r#"${[ "foo \"bar\" baz" ]}"#); let mut p = Parser::new(r#"${[ 'foo \'bar\' baz' ]}"#);
assert_eq!( assert_eq!(
p.parse().tokens, p.parse().tokens,
vec![ vec![
Token::Tag { Token::Tag {
val: Val::Str { val: Val::Str {
text: r#"foo "bar" baz"#.into() text: r#"foo 'bar' baz"#.into()
} }
}, },
Token::Eof Token::Eof
@@ -539,7 +539,7 @@ mod tests {
#[test] #[test]
fn fn_mixed_args() { fn fn_mixed_args() {
let mut p = Parser::new(r#"${[ foo(aaa=bar,bb="baz \"hi\"", c=qux, z=true ) ]}"#); let mut p = Parser::new(r#"${[ foo(aaa=bar,bb='baz \'hi\'', c=qux, z=true ) ]}"#);
assert_eq!( assert_eq!(
p.parse().tokens, p.parse().tokens,
vec![ vec![
@@ -554,7 +554,7 @@ mod tests {
FnArg { FnArg {
name: "bb".into(), name: "bb".into(),
value: Val::Str { value: Val::Str {
text: r#"baz "hi""#.into() text: r#"baz 'hi'"#.into()
} }
}, },
FnArg { FnArg {
@@ -598,7 +598,7 @@ mod tests {
#[test] #[test]
fn fn_nested_args() { fn fn_nested_args() {
let mut p = Parser::new(r#"${[ outer(a=inner(a=foo, b="i"), c="o") ]}"#); let mut p = Parser::new(r#"${[ outer(a=inner(a=foo, b='i'), c='o') ]}"#);
assert_eq!( assert_eq!(
p.parse().tokens, p.parse().tokens,
vec![ vec![
@@ -649,10 +649,10 @@ mod tests {
fn token_display_str() { fn token_display_str() {
assert_eq!( assert_eq!(
Val::Str { Val::Str {
text: r#"Hello "You""#.to_string() text: "Hello 'You'".to_string()
} }
.to_string(), .to_string(),
r#""Hello \"You\"""# "'Hello \'You\''"
); );
} }
@@ -675,7 +675,7 @@ mod tests {
] ]
} }
.to_string(), .to_string(),
r#"fn(a="aaa")"# r#"fn(a='aaa')"#
); );
} }
@@ -702,7 +702,7 @@ mod tests {
} }
} }
.to_string(), .to_string(),
r#"${[ foo(arg="v", arg2=my_var) ]}"# r#"${[ foo(arg='v', arg2=my_var) ]}"#
); );
} }
@@ -727,7 +727,7 @@ mod tests {
] ]
} }
.to_string(), .to_string(),
r#"${[ my_var ]} Some cool text ${[ "Hello World" ]}"# r#"${[ my_var ]} Some cool text ${[ 'Hello World' ]}"#
); );
} }
} }

View File

@@ -158,7 +158,7 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn render_valid_fn() { async fn render_valid_fn() {
let vars = HashMap::new(); let vars = HashMap::new();
let template = r#"${[ say_hello(a="John", b="Kate") ]}"#; let template = r#"${[ say_hello(a='John', b='Kate') ]}"#;
let result = r#"say_hello: 2, Some("John") Some("Kate")"#; let result = r#"say_hello: 2, Some("John") Some("Kate")"#;
struct CB {} struct CB {}

View File

@@ -136,7 +136,7 @@ export function TemplateFunctionDialog({ templateFunction, hide, initialTokens,
} }
})} })}
</VStack> </VStack>
<InlineCode className="select-text cursor-text">{rendered.data}</InlineCode> <InlineCode className="select-text cursor-text">{rendered.data || <>&nbsp;</>}</InlineCode>
<Button color="primary" onClick={handleDone}> <Button color="primary" onClick={handleDone}>
Done Done
</Button> </Button>