blob: 2a3ef176bb6f74a77d832b4f84d7c7cae3df8757 [file] [log] [blame]
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:web_components/build/import_inliner.dart';
import 'package:unittest/compact_vm_config.dart';
import 'package:unittest/unittest.dart';
import 'package:html5lib/parser.dart';
import 'package:html5lib/dom.dart' show Document, Element;
main() {
testInline('basic inlining', '''
<link rel="import" href="foo.html">
</html>''', {
'foo.html': '<div>bar</div>'
}, '''
<div style="display:none;">
class MapImportReader implements ImportReader {
Map<String, Document> _imports;
Future<Document> readImport(Element import) {
return new Future.value(_imports[import.attributes['href']]);
void testInline(String name, String input, Map<String, String> dependencies,
String expectedOutput, {String reason}) {
var inputDoc = parse(input);
var dependencyDocs = new Map<String, Document>();
dependencies.forEach((k, v) => dependencyDocs[k] = parse(v));
var importReader = new MapImportReader(dependencyDocs);
var importInliner = new ImportInliner(importReader);
test(name, () {
inputDoc.outerHtml.replaceAll(' ', '').replaceAll('\n', ''),
expectedOutput.replaceAll(' ', '').replaceAll('\n', ''),
reason: reason);