Skip to content

Commit

Permalink
Sync 0.6.0-dev.15
Browse files Browse the repository at this point in the history
  • Loading branch information
ykmnkmi committed Mar 6, 2024
1 parent a1fbb32 commit be035c5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.6.0-dev.14
## 0.6.0-dev.15
- bump SDK version to 3.3.0.
- update dependencies.
- internal changes.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: jinja
version: 0.6.0-dev.14
version: 0.6.0-dev.15
description: >-
Jinja2 template engine for Dart.
Variables, expressions, control structures and template inheritance.
Expand Down
41 changes: 38 additions & 3 deletions test/statements/include_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void main() {
expect(error.name, contains('missing2'));
expect(error.names, contains('missing'));
expect(error.names, contains('missing2'));
} catch (error) {
expect(error, isA<TemplatesNotFound>());
}

void testIncludes(Template tmpl, [Map<String, Object?>? context]) {
Expand All @@ -68,7 +70,17 @@ void main() {

test('include ignore missing', () {
var tmpl = env.fromString('{% include "missing" %}');
expect(() => tmpl.render(), throwsA(isA<TemplateNotFound>()));

try {
expect(tmpl.render(), isA<Never>());
} catch (error) {
expect(error, isA<TemplateNotFound>());
}

for (var extra in ['', 'with context', 'without context']) {
tmpl = env.fromString('{% include "missing" ignore missing $extra %}');
expect(tmpl.render(), equals(''));
}
});

test('context include with overrides', () {
Expand All @@ -83,7 +95,30 @@ void main() {
expect(tmpl.render(), equals('123'));
});

// TODO: add test: unoptimized_scopes
// TODO: add test: import_from_with_context
test('unoptimized scopes', () {
var tmpl = env.fromString('''
{% macro outer(o) %}
{% macro inner() %}
{% include "o_printer" %}
{% endmacro %}
{{ inner() }}
{% endmacro %}
{{ outer("FOO") }}
''');

expect(tmpl.render().trim(), equals('(FOO)'));
});

test('import from with context', () {
var env = Environment(
loader: MapLoader({
'a': '{% macro x() %}{{ foobar }}{% endmacro %}',
}),
);

var tmpl = env.fromString(
"{% set foobar = 42 %}{% from 'a' import x with context %}{{ x() }}");
expect(tmpl.render(), equals('42'));
});
});
}

0 comments on commit be035c5

Please sign in to comment.