// Test context expressions. // Ref: false --- // Test that context body is parsed as atomic expression. #let c = [#context "hello".] #test(c.children.first().func(), (context none).func()) #test(c.children.last(), [.]) --- // Test that manual construction is forbidden. // Error: 2-25 cannot be constructed manually #(context none).func()() --- // Test that `here()` yields the context element's location. #context test(query(here()).first().func(), (context none).func()) --- // Test whether context is retained in nested function. #let translate(..args) = args.named().at(text.lang) #set text(lang: "de") #context test(translate(de: "Inhalt", en: "Contents"), "Inhalt") --- // Test whether context is retained in built-in callback. #set text(lang: "de") #context test( ("en", "de", "fr").sorted(key: v => v != text.lang), ("de", "en", "fr"), ) --- // Test `locate` + `here`. #context test(here().position().y, 10pt) --- // Test `locate`. #v(10pt) = Introduction #context test(locate().position().y, 20pt) --- // Error: 10-25 label `` does not exist in the document #context locate() --- = Introduction = Introduction // Error: 10-25 label `` occurs multiple times in the document #context locate() --- #v(10pt) = Introduction #context test(locate(heading).position().y, 20pt) --- // Error: 10-25 selector does not match any element #context locate(heading) --- = Introduction = Introduction // Error: 10-25 selector matches multiple elements #context locate(heading) --- // Test `counter`. #let c = counter("heading") #c.update(2) #c.update(n => n + 2) #context test(c.get(), (4,)) #c.update(n => n - 3) #context test(c.at(here()), (1,)) --- // Test `state.at` outside of context. // Error: 2-26 can only be used when context is known // Hint: 2-26 try wrapping this in a `context` expression // Hint: 2-26 the `context` expression should wrap everything that depends on this function #state("key").at(