@@ -4,7 +4,8 @@ import scala.collection.mutable
44import utest ._
55import Expr ._
66import fastparse .Parsed
7- import Val .{True , Num }
7+ import Val .{Num , True }
8+ import sjsonnet .Expr .FieldName .Fixed
89object ParserTests extends TestSuite {
910 def parse (s : String , strictImportSyntax : Boolean = false ) = fastparse.parse(s, new Parser (null , strictImportSyntax, mutable.HashMap .empty, mutable.HashMap .empty).document(_)).get.value._1
1011 def parseErr (s : String , strictImportSyntax : Boolean = false ) = fastparse.parse(s, new Parser (null , strictImportSyntax, mutable.HashMap .empty, mutable.HashMap .empty).document(_), verboseFailures = true ).asInstanceOf [Parsed .Failure ].msg
@@ -26,6 +27,18 @@ object ParserTests extends TestSuite{
2627 test(" duplicateFields" ) {
2728 parseErr(" { a: 1, a: 2 }" ) ==> """ Expected no duplicate field: a:1:14, found "}""""
2829 }
30+ test(" localInObj" ) {
31+ parse(""" {
32+ |local x = 1,
33+ |a: x,
34+ |}""" .stripMargin).toString ==> (ObjBody .MemberList (pos(2 ), Array (Bind (pos(8 ), " x" , null , Num (pos(12 ), 1 ))),
35+ Array (Member .Field (pos(15 ), Fixed (" a" ), false , null , Member .Visibility .Normal , Id (pos(18 ), " x" ))), null )).toString
36+ parseErr(""" {
37+ |local x = 1,
38+ |local x = x + 1,
39+ |a: x,
40+ |}""" .stripMargin) ==> """ Expected no duplicate local: x:5:1, found "}""""
41+ }
2942 test(" givenDuplicateFieldsInListComprehension_expectError" ) {
3043 parseErr(""" { ["bar"]: x for x in [1, 2]}""" ) ==> """ Expected no duplicate field: "bar" :1:29, found "}""""
3144 }
0 commit comments