Make sure all tests are passing
diff --git a/check.sh b/check.sh
index 28d4e40..04d5741 100755
--- a/check.sh
+++ b/check.sh
@@ -1,2 +1,4 @@
dart_analyzer --type-checks-for-inferred-types lib/mustache.dart
+dart --checked test/mustache_test.dart
+
diff --git a/lib/template.dart b/lib/template.dart
index 843c9b8..9967273 100644
--- a/lib/template.dart
+++ b/lib/template.dart
@@ -127,11 +127,16 @@
}
_renderInvSection(node) {
- final val = stack.last[node.value];
- if ((val is List && val.isEmpty)
- || val == null
- || val == false) {
+ final value = stack.last[node.value];
+ if ((value is List && value.isEmpty)
+ || value == null
+ || value == false) {
+ // FIXME in strict mode, log an error if value is null.
_renderSectionWithValue(node, {});
+ } else if (value == true || value is Map || value is List) {
+ // Do nothing.
+ } else {
+ throw new FormatException("Invalid value type for inverse section: '${node.value}', type: ${value.runtimeType}.");
}
}
diff --git a/test/mustache_test.dart b/test/mustache_test.dart
index 5176a48..e2848c2 100644
--- a/test/mustache_test.dart
+++ b/test/mustache_test.dart
@@ -6,6 +6,7 @@
const MISMATCHED_TAG = 'Mismatched tag';
const UNEXPECTED_EOF = 'Unexpected end of input';
const INVALID_VALUE_SECTION = 'Invalid value type for section';
+const INVALID_VALUE_INV_SECTION = 'Invalid value type for inverse section';
main() {
group('Section', () {
@@ -79,7 +80,7 @@
'{{^section}}_{{var}}_{{/section}}',
{"section": 42});
expect(ex is FormatException, isTrue);
- expect(ex.message, startsWith(INVALID_VALUE_SECTION));
+ expect(ex.message, startsWith(INVALID_VALUE_INV_SECTION));
});
test('True', () {
var output = parse('{{^section}}_ok_{{/section}}')