@@ -211,6 +211,24 @@ describe('include-code-extension', () => {
211
211
expect ( actual . getBlocks ( ) [ 0 ] . getTitle ( ) ) . to . equal ( 'Describe This' )
212
212
} )
213
213
214
+ it ( 'should pass attribute on block macro for single include through to resulting source block' , ( ) => {
215
+ const inputSource = heredoc `
216
+ package org.example
217
+
218
+ fun main(args : Array<String>) {
219
+ println("Hello, World!")
220
+ }
221
+ `
222
+ addExample ( 'kotlin/hello.kt' , inputSource )
223
+ const input = heredoc `
224
+ [some-attribute=alpha]
225
+ include-code::hello[]
226
+ `
227
+ const actual = run ( input , { attributes : { 'include-kotlin' : 'example$kotlin' } } )
228
+ expect ( actual . getBlocks ( ) ) . to . have . lengthOf ( 1 )
229
+ expect ( actual . getBlocks ( ) [ 0 ] . getAttribute ( 'some-attribute' ) ) . to . equal ( 'alpha' )
230
+ } )
231
+
214
232
it ( 'should report correct line number in warning for block title' , ( ) => {
215
233
const inputSource = heredoc `
216
234
fun main(args : Array<String>) {
@@ -263,6 +281,35 @@ describe('include-code-extension', () => {
263
281
expect ( actual . getBlocks ( ) [ 1 ] . getTitle ( ) ) . to . equal ( 'Describe This - Kotlin' )
264
282
} )
265
283
284
+ it ( 'should pass attribute on block macro for multiple includes through to resulting source block' , ( ) => {
285
+ addExample (
286
+ 'kotlin/hello.kt' ,
287
+ heredoc `
288
+ fun main(args : Array<String>) {
289
+ println("Hello, World!")
290
+ }
291
+ `
292
+ )
293
+ addExample (
294
+ 'java/hello.java' ,
295
+ heredoc `
296
+ public class Hello {
297
+ public static void main (String[] args) {
298
+ System.out.println("Hello, World!");
299
+ }
300
+ }
301
+ `
302
+ )
303
+ const input = heredoc `
304
+ [some-attribute=alpha]
305
+ include-code::hello[]
306
+ `
307
+ const actual = run ( input )
308
+ expect ( actual . getBlocks ( ) ) . to . have . lengthOf ( 2 )
309
+ expect ( actual . getBlocks ( ) [ 0 ] . getAttribute ( 'some-attribute' ) ) . to . equal ( 'alpha' )
310
+ expect ( actual . getBlocks ( ) [ 1 ] . getAttribute ( 'some-attribute' ) ) . to . equal ( 'alpha' )
311
+ } )
312
+
266
313
it ( 'should support attributes on include directive of included file' , ( ) => {
267
314
const inputSource = heredoc `
268
315
fun main(args : Array<String>) {
@@ -418,6 +465,54 @@ describe('include-code-extension', () => {
418
465
expect ( actualProperties ) . to . eql ( expected )
419
466
} )
420
467
468
+ it ( 'should pass attribute on block macro to each tabbed block if @asciidoctor/tabs extension is registered' , ( ) => {
469
+ const expected = [
470
+ { style : 'source' , language : 'java' , title : undefined , someAttribute : 'alpha' } ,
471
+ { style : 'source' , language : 'kotlin' , title : undefined , someAttribute : 'alpha' } ,
472
+ { style : 'source' , language : 'groovy' , title : undefined , someAttribute : 'alpha' } ,
473
+ { style : 'source' , language : 'xml' , title : undefined , someAttribute : 'alpha' } ,
474
+ ]
475
+ addExample (
476
+ 'kotlin/hello.kt' ,
477
+ heredoc `
478
+ fun main(args : Array<String>) {
479
+ println("Hello, World!")
480
+ }
481
+ `
482
+ )
483
+ addExample (
484
+ 'java/hello.java' ,
485
+ heredoc `
486
+ public class Hello {
487
+ public static void main (String[] args) {
488
+ System.out.println("Hello, World!");
489
+ }
490
+ }
491
+ `
492
+ )
493
+ addExample ( 'groovy/hello.groovy' , 'println "Hello, World!"' )
494
+ addExample ( 'xml/hello.xml' , 'println "<hello />"' )
495
+ const input = heredoc `
496
+ [some-attribute=alpha]
497
+ include-code::hello[]`
498
+ const doc = run ( input , { registerAsciidoctorTabs : true } )
499
+ const tabs = doc . getBlocks ( ) [ 0 ]
500
+ console . log ( tabs )
501
+ expect ( tabs ) . to . exist ( )
502
+ expect ( tabs . hasRole ( 'tabs' ) ) . to . be . true ( )
503
+ expect ( tabs . getTitle ( ) ) . to . be . undefined ( )
504
+ const tablist = tabs . findBy ( { context : 'ulist' } ) [ 0 ]
505
+ expect ( tablist ) . to . exist ( )
506
+ expect ( tablist . getItems ( ) ) . to . have . lengthOf ( 4 )
507
+ const codeBlocks = tabs . findBy ( { context : 'listing' } )
508
+ expect ( codeBlocks ) . to . have . lengthOf ( 4 )
509
+ const actualProperties = codeBlocks . map ( ( block ) => {
510
+ return { style : block . getStyle ( ) , language : block . getAttributes ( ) . language , title : block . getTitle ( ) , someAttribute : block . getAttribute ( 'some-attribute' ) }
511
+ } )
512
+ console . log ( actualProperties )
513
+ expect ( actualProperties ) . to . eql ( expected )
514
+ } )
515
+
421
516
it ( 'should apply title to tabs when @asciidoctor/tabs extension is registered' , ( ) => {
422
517
addExample (
423
518
'kotlin/hello.kt' ,
0 commit comments