From a6fc4c216b084bf3cac928d7801589bce82629af Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 2 May 2022 16:39:57 +0100 Subject: [PATCH] [TEM #2] - Change default arg syntax to `{{$ ... }}` --- src/links.rs | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/links.rs b/src/links.rs index 63ea4c7..d780f38 100644 --- a/src/links.rs +++ b/src/links.rs @@ -39,20 +39,20 @@ lazy_static! { r"(?x) # enable insignificant whitespace mode \\\{\{ # escaped link opening parens - \#.* # match any character + \$.* # match any character \}\} # escaped link closing parens | # or \{\{\s* # link opening parens and whitespace(s) - \#([\S]+) # arg name + \$([\S]+) # arg name \s* # optional separating whitespace(s) \}\} # link closing parens | # or \{\{\s* # link opening parens and whitespace(s) - \#([\S]+) # arg name + \$([\S]+) # arg name \s+ # optional separating whitespace(s) ([^}]+) # match everything after space \}\} # link closing parens" @@ -497,25 +497,25 @@ year=2022 #[test] fn test_extract_args_partial_match() { - let s = "Some random text with {{#height..."; + let s = "Some random text with {{$height..."; assert_eq!(extract_args(s).collect::>(), vec![]); - let s = "Some random text with {{#image ferris.png..."; + let s = "Some random text with {{$image ferris.png..."; assert_eq!(extract_args(s).collect::>(), vec![]); - let s = "Some random text with {{#width 550..."; + let s = "Some random text with {{$width 550..."; assert_eq!(extract_args(s).collect::>(), vec![]); - let s = "Some random text with \\{{#title..."; + let s = "Some random text with \\{{$title..."; assert_eq!(extract_args(s).collect::>(), vec![]); } #[test] fn test_extract_args_empty() { - let s = "Some random text with {{}} {{#}}..."; + let s = "Some random text with {{}} {{$}}..."; assert_eq!(extract_args(s).collect::>(), vec![]); } #[test] fn test_extract_args_simple() { - let s = "This is some random text with {{#path}} and then some more random text"; + let s = "This is some random text with {{$path}} and then some more random text"; let res = extract_args(s).collect::>(); @@ -525,7 +525,7 @@ year=2022 start_index: 30, end_index: 39, args_type: ArgsType::Plain("path"), - args_text: "{{#path}}" + args_text: "{{$path}}" }] ); } @@ -534,20 +534,20 @@ year=2022 fn test_extract_args_escaped() { let start = r" Example Text - \{{#height 200px}} << an escaped argument! + \{{$height 200px}} << an escaped argument! "; let end = r" Example Text - {{#height 200px}} << an escaped argument! + {{$height 200px}} << an escaped argument! "; assert_eq!(Args::replace(start, &HashMap::<&str, &str>::new()), end); } #[test] fn test_extract_args_with_spaces() { - let s1 = "This is some random text with {{ #path }}"; - let s2 = "This is some random text with {{#path }}"; - let s3 = "This is some random text with {{ #path}}"; + let s1 = "This is some random text with {{ $path }}"; + let s2 = "This is some random text with {{$path }}"; + let s3 = "This is some random text with {{ $path}}"; let res1 = extract_args(s1).collect::>(); let res2 = extract_args(s2).collect::>(); @@ -559,7 +559,7 @@ year=2022 start_index: 30, end_index: 51, args_type: ArgsType::Plain("path"), - args_text: "{{ #path }}" + args_text: "{{ $path }}" }] ); @@ -569,7 +569,7 @@ year=2022 start_index: 30, end_index: 46, args_type: ArgsType::Plain("path"), - args_text: "{{#path }}" + args_text: "{{$path }}" }] ); @@ -579,14 +579,14 @@ year=2022 start_index: 30, end_index: 44, args_type: ArgsType::Plain("path"), - args_text: "{{ #path}}" + args_text: "{{ $path}}" }] ); } #[test] fn test_extract_args_with_default_value() { - let s = "This is some random text with {{#path 200px}} and then some more random text"; + let s = "This is some random text with {{$path 200px}} and then some more random text"; let res = extract_args(s).collect::>(); @@ -596,7 +596,7 @@ year=2022 start_index: 30, end_index: 45, args_type: ArgsType::Default("path", "200px"), - args_text: "{{#path 200px}}" + args_text: "{{$path 200px}}" }] ); } @@ -604,7 +604,7 @@ year=2022 #[test] fn test_extract_args_with_default_value_and_spaces() { let s = - "This is some random text with {{ #path 400px }} and then some more random text"; + "This is some random text with {{ $path 400px }} and then some more random text"; let res = extract_args(s).collect::>(); @@ -614,14 +614,14 @@ year=2022 start_index: 30, end_index: 52, args_type: ArgsType::Default("path", "400px "), - args_text: "{{ #path 400px }}" + args_text: "{{ $path 400px }}" }] ); } #[test] fn test_extract_args_with_multiple_spaced_default_value() { - let s = "{{#title An Amazing Title}}"; + let s = "{{$title An Amazing Title}}"; let res = extract_args(s).collect::>(); @@ -631,7 +631,7 @@ year=2022 start_index: 0, end_index: 27, args_type: ArgsType::Default("title", "An Amazing Title"), - args_text: "{{#title An Amazing Title}}" + args_text: "{{$title An Amazing Title}}" }] ); } @@ -640,7 +640,7 @@ year=2022 fn test_replace_args_simple() { let start = r" Example Text - {{#height}} << an argument! + {{$height}} << an argument! "; let end = r" Example Text @@ -656,7 +656,7 @@ year=2022 fn test_replace_args_with_default() { let start = r" Example Text - {{#height 300px}} << an argument! + {{$height 300px}} << an argument! "; let end = r" Example Text @@ -669,7 +669,7 @@ year=2022 fn test_replace_args_overriding_default() { let start = r" Example Text - {{#height 300px}} << an argument! + {{$height 300px}} << an argument! "; let end = r" Example Text