public void testMapLiteralAsRecord_duplicateKeys() {
   SoyFileSetNode soyTree =
       SoyFileSetParserBuilder.forFileContents(
               constructTemplateSource("{let $map: ['a': 1, 'a': 2]/}"))
           .declaredSyntaxVersion(SyntaxVersion.V2_0)
           .doRunInitialParsingPasses(false)
           .typeRegistry(typeRegistry)
           .parse();
   createResolveNamesVisitorForMaxSyntaxVersion().exec(soyTree);
   FormattingErrorReporter reporter = new FormattingErrorReporter();
   new ResolveExpressionTypesVisitor(typeRegistry, SyntaxVersion.V9_9, reporter).exec(soyTree);
   assertThat(Iterables.getOnlyElement(reporter.getErrorMessages()))
       .isEqualTo("Record literals with duplicate keys are not allowed.  Duplicate key: 'a'");
 }
コード例 #2
0
 /**
  * Checks that the given Soy expression causes a SoySyntaxException during translation, optionally
  * checking the exception's error message.
  *
  * @param soyExpr The Soy expression to test.
  * @param expectedErrorMsgSubstrings An expected substring of the expected exception's message.
  * @param jsSrcOptions The JsSrc compiler options.
  */
 private void assertSoyErrors(
     String soyExpr, SoyJsSrcOptions jsSrcOptions, String... expectedErrorMsgSubstrings) {
   ExprNode exprNode =
       new ExpressionParser(soyExpr, SourceLocation.UNKNOWN, ExplodingErrorReporter.get())
           .parseExpression();
   FormattingErrorReporter errorReporter = new FormattingErrorReporter();
   new TranslateToJsExprVisitor(
           SOY_JS_SRC_FUNCTIONS_MAP, jsSrcOptions, LOCAL_VAR_TRANSLATIONS, errorReporter)
       .exec(exprNode);
   ImmutableList<String> errorMessages = errorReporter.getErrorMessages();
   assertThat(errorMessages).hasSize(expectedErrorMsgSubstrings.length);
   for (int i = 0; i < expectedErrorMsgSubstrings.length; ++i) {
     assertThat(errorMessages.get(i)).contains(expectedErrorMsgSubstrings[i]);
   }
 }