From 00784d39ad9a990c77f5facae58f7db108328876 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 5 Apr 2021 14:51:26 +0800 Subject: [PATCH] PropertyExpected for map literal with interpolated key. --- src/parser.rs | 1 + tests/maps.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 83f5df33..1ba1b130 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -710,6 +710,7 @@ fn parse_map_literal( } (s, pos) } + (Token::InterpolatedString(_), pos) => return Err(PERR::PropertyExpected.into_err(pos)), (Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => { return Err(PERR::Reserved(s).into_err(pos)); } diff --git a/tests/maps.rs b/tests/maps.rs index 895c7310..30dcf985 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -35,8 +35,21 @@ fn test_map_indexing() -> Result<(), Box> { engine.eval::("let y = #{a: 1, b: 2, c: 3}; y.a = 5; y.a")?, 5 ); + engine.eval::<()>("let y = #{a: 1, b: 2, c: 3}; y.z")?; + assert_eq!( + engine.eval::(r#"let y = #{`a\nb`: 1}; y["a\\nb"]"#)?, + 1 + ); + + assert!(matches!( + *engine + .eval::("let y = #{`a${1}`: 1}; y.a1") + .expect_err("should error"), + EvalAltResult::ErrorParsing(ParseErrorType::PropertyExpected, _) + )); + assert!(engine.eval::(r#"let y = #{a: 1, b: 2, c: 3}; "c" in y"#)?); assert!(engine.eval::(r#"let y = #{a: 1, b: 2, c: 3}; "b" in y"#)?); assert!(!engine.eval::(r#"let y = #{a: 1, b: 2, c: 3}; "z" in y"#)?);