1717package  com .google .template .soy .jbcsrc ;
1818
1919import  static  com .google .common .truth .Truth .assertThat ;
20+ import  static  com .google .template .soy .testing .VeMetadataExample .veMetadataExampleExtension ;
2021import  static  org .junit .Assert .assertThrows ;
2122import  static  org .junit .Assert .fail ;
2223
3334import  com .google .template .soy .jbcsrc .shared .CompiledTemplates ;
3435import  com .google .template .soy .jbcsrc .shared .RenderContext ;
3536import  com .google .template .soy .jbcsrc .shared .StackFrame ;
37+ import  com .google .template .soy .logging .LoggableElementMetadata ;
3638import  com .google .template .soy .logging .LoggingFunction ;
3739import  com .google .template .soy .logging .SoyLogger ;
3840import  com .google .template .soy .logging .SoyLogger .LoggingAttrs ;
@@ -107,7 +109,10 @@ public void testBasicLogging_treeStructure() throws Exception {
107109    assertThat (sb .toString ())
108110        .isEqualTo ("<div data-id=1><div data-id=2></div><div data-id=3></div></div>" );
109111    assertThat (testLogger .builder .toString ())
110-         .isEqualTo ("velog{id=1}\n "  + "  velog{id=2}\n "  + "  velog{id=3}" );
112+         .isEqualTo (
113+             "velog{id=1, loggableElementMetadata=}\n " 
114+                 + "  velog{id=2, loggableElementMetadata=}\n " 
115+                 + "  velog{id=3, loggableElementMetadata=}" );
111116  }
112117
113118  @ Test 
@@ -119,7 +124,7 @@ public void testBasicLogging_withData() throws Exception {
119124        "{velog ve_data(FooVe, Foo(intField: 123))}<div data-id=1></div>{/velog}" );
120125    assertThat (sb .toString ()).isEqualTo ("<div data-id=1></div>" );
121126    assertThat (testLogger .builder .toString ())
122-         .isEqualTo ("velog{id=1, data=soy.test.Foo{int_field: 123}}" );
127+         .isEqualTo ("velog{id=1, data=soy.test.Foo{int_field: 123}, loggableElementMetadata= }" );
123128  }
124129
125130  @ Test 
@@ -131,7 +136,8 @@ public void testBasicLogging_logonly() throws Exception {
131136        "{velog FooVe logonly=\" true\" }<div data-id=1></div>{/velog}" );
132137    // logonly ve's disable content generation 
133138    assertThat (sb .toString ()).isEmpty ();
134-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, logonly}" );
139+     assertThat (testLogger .builder .toString ())
140+         .isEqualTo ("velog{id=1, logonly, loggableElementMetadata=}" );
135141  }
136142
137143  @ Test 
@@ -152,7 +158,10 @@ public void testBasicLogging_logonly_dynamic() throws Exception {
152158        "{velog Bar logonly=\" $f\" }<div data-id=2></div>{/velog}" );
153159    // logonly ve's disable content generation 
154160    assertThat (sb .toString ()).isEqualTo ("<div data-id=2></div>" );
155-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, logonly}\n velog{id=2}" );
161+     assertThat (testLogger .builder .toString ())
162+         .isEqualTo (
163+             "velog{id=1, logonly, loggableElementMetadata=}\n " 
164+                 + "velog{id=2, loggableElementMetadata=}" );
156165  }
157166
158167  @ Test 
@@ -183,14 +192,30 @@ public void testBasicLogging_logonly_true_noLogger() throws Exception {
183192    }
184193  }
185194
195+   @ Test 
196+   public  void  testBasicLogging_loggableElementMetadata () throws  Exception  {
197+     StringBuilder  sb  = new  StringBuilder ();
198+     TestLogger  testLogger  = new  TestLogger ();
199+     renderTemplate (
200+         OutputAppendable .create (sb , testLogger ),
201+         "{velog ve_data(VeWithLoggableElementMetadata)}<div data-id=1></div>{/velog}" );
202+     assertThat (sb .toString ()).isEqualTo ("<div data-id=1></div>" );
203+     assertThat (testLogger .builder .toString ())
204+         .isEqualTo (
205+             "velog{id=5, loggableElementMetadata=[soy.test.ve_metadata_example_extension]:" 
206+                 + " \" foo\" \n " 
207+                 + "}" );
208+   }
209+ 
186210  @ Test 
187211  public  void  testLogging_letVariables () throws  Exception  {
188212    StringBuilder  sb  = new  StringBuilder ();
189213    TestLogger  testLogger  = new  TestLogger ();
190214    renderTemplate (
191215        OutputAppendable .create (sb , testLogger ),
192216        "{let $foo kind=\" html\" }{velog FooVe}<div data-id=1></div>{/velog}{/let}{$foo}{$foo}" );
193-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}\n velog{id=1}" );
217+     assertThat (testLogger .builder .toString ())
218+         .isEqualTo ("velog{id=1, loggableElementMetadata=}\n velog{id=1, loggableElementMetadata=}" );
194219    assertThat (sb .toString ()).isEqualTo ("<div data-id=1></div><div data-id=1></div>" );
195220  }
196221
@@ -205,7 +230,7 @@ public void testLogging_msg() throws Exception {
205230            + "  Greetings, {velog FooVe}<a href='./wiki?human'>Human</a>{/velog}\n " 
206231            + "{/msg}" );
207232    assertThat (sb .toString ()).isEqualTo ("Greetings, <a href='./wiki?human'>Human</a>" );
208-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
233+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
209234  }
210235
211236  // Regression test for a bug where logging would get dropped if there was a velog, in a msg around 
@@ -221,7 +246,7 @@ public void testLogging_msg_void_element() throws Exception {
221246            + "  Greetings, {velog FooVe}<input type=text>{/velog}\n " 
222247            + "{/msg}" );
223248    assertThat (sb .toString ()).isEqualTo ("Greetings, <input type=text>" );
224-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
249+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
225250  }
226251
227252  @ Test 
@@ -237,10 +262,10 @@ public void testLogging_nestedLogOnly() throws IOException {
237262    assertThat (sb .toString ()).isEmpty ();
238263    assertThat (testLogger .builder .toString ())
239264        .isEqualTo (
240-             "velog{id=1, logonly}\n " 
241-                 + "  velog{id=1}\n " 
242-                 + "    velog{id=1, logonly}\n " 
243-                 + "      velog{id=1, logonly}" );
265+             "velog{id=1, logonly, loggableElementMetadata= }\n " 
266+                 + "  velog{id=1, loggableElementMetadata= }\n " 
267+                 + "    velog{id=1, logonly, loggableElementMetadata= }\n " 
268+                 + "      velog{id=1, logonly, loggableElementMetadata= }" );
244269  }
245270
246271  @ Test 
@@ -252,7 +277,7 @@ public void testLogging_loggingFunction_basic() throws Exception {
252277        "<div data-depth={depth()}></div>" 
253278            + "{velog FooVe}<div data-depth={depth()}></div>{/velog}" 
254279            + "<div data-depth={depth()}></div>" );
255-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
280+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
256281    assertThat (sb .toString ())
257282        .isEqualTo ("<div data-depth=0></div><div data-depth=1></div><div data-depth=0></div>" );
258283  }
@@ -283,7 +308,7 @@ public void testLogging_elvis() throws Exception {
283308        "  {/velog}" ,
284309        "{/let}" ,
285310        "{$log ?? ''}" );
286-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
311+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
287312    assertThat (sb .toString ()).isEqualTo ("<div>hello</div>" );
288313  }
289314
@@ -294,7 +319,7 @@ public void testLoggingAttributes_basic() throws Exception {
294319    testLogger .attrsMap .put (1L , LoggingAttrs .builder ().addDataAttribute ("data-foo" , "bar" ).build ());
295320    renderTemplate (
296321        OutputAppendable .create (sb , testLogger ), "{velog FooVe}<div>hello</div>{/velog}" );
297-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
322+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
298323    assertThat (sb .toString ()).isEqualTo ("<div data-foo=\" bar\" >hello</div>" );
299324  }
300325
@@ -305,7 +330,7 @@ public void testLoggingAttributes_withCall() throws Exception {
305330    testLogger .attrsMap .put (1L , LoggingAttrs .builder ().addDataAttribute ("data-foo" , "bar" ).build ());
306331    renderTemplate (
307332        OutputAppendable .create (sb , testLogger ), "{velog FooVe}{call another /}{/velog}" );
308-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
333+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
309334    assertThat (sb .toString ()).isEqualTo ("<div data-foo=\" bar\" >called</div>" );
310335  }
311336
@@ -318,7 +343,7 @@ public void testLoggingAttributes_withLet() throws Exception {
318343        OutputAppendable .create (sb , testLogger ),
319344        "{let $div kind='html'}<div>hello</div>{/let}" ,
320345        "{velog FooVe}{$div}{/velog}" );
321-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
346+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
322347    assertThat (sb .toString ()).isEqualTo ("<div data-foo=\" bar\" >hello</div>" );
323348  }
324349
@@ -329,7 +354,7 @@ public void testLoggingAttributes_anchor() throws Exception {
329354    testLogger .attrsMap .put (
330355        1L , LoggingAttrs .builder ().addAnchorHref (SafeUrls .fromConstant ("./go" )).build ());
331356    renderTemplate (OutputAppendable .create (sb , testLogger ), "{velog FooVe}<a>hello</a>{/velog}" );
332-     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1}" );
357+     assertThat (testLogger .builder .toString ()).isEqualTo ("velog{id=1, loggableElementMetadata= }" );
333358    assertThat (sb .toString ()).isEqualTo ("<a href=\" ./go\" >hello</a>" );
334359  }
335360
@@ -361,15 +386,24 @@ private void renderTemplate(
361386      throws  IOException  {
362387    SoyFileSetParserBuilder  builder  =
363388        SoyFileSetParserBuilder .forTemplateAndImports (
364-                 "{const FooVe = ve_def('FooVe', 1, Foo) /}" 
365-                     + "{const Bar = ve_def('Bar', 2, Foo) /}" 
366-                     + "{const Baz = ve_def('Baz', 3, Foo) /}" 
367-                     + "{const Quux = ve_def('Quux', 4, Foo) /}" 
389+                 // End of the line comments are to force the formatter to keep each line on its own 
390+                 // line. 
391+                 "{const FooVe = ve_def('FooVe', 1, Foo) /}"  // 
392+                     + "{const Bar = ve_def('Bar', 2, Foo) /}"  // 
393+                     + "{const Baz = ve_def('Baz', 3, Foo) /}"  // 
394+                     + "{const Quux = ve_def('Quux', 4, Foo) /}"  // 
395+                     + "{const VeWithLoggableElementMetadata = ve_def("  // 
396+                     + " 'VeWithLoggableElementMetadata',"  // 
397+                     + " 5,"  // 
398+                     + " Foo,"  // 
399+                     + " LoggableElementMetadata(veMetadataExampleExtension: 'foo')) /}"  // 
368400                    + "{template foo}\n " 
369401                    + Joiner .on ("\n " ).join (templateBodyLines )
370-                     + "\n {/template}" 
371-                     + "{template another}<div>called</div>{/template}\n " ,
372-                 Foo .getDescriptor ())
402+                     + "\n {/template}"  // 
403+                     + "{template another}<div>called</div>{/template}\n " , // 
404+                 Foo .getDescriptor (),
405+                 LoggableElementMetadata .getDescriptor (),
406+                 veMetadataExampleExtension .getDescriptor ())
373407            .addSoySourceFunction (new  DepthFunction ())
374408            .addHtmlAttributesForLogging (true )
375409            .runAutoescaper (true );
0 commit comments