2019-11-27 15:04:02 -08:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2016-04-20 09:29:01 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
2016-10-19 22:04:56 -07:00
|
|
|
import 'dart:typed_data';
|
2016-04-20 09:29:01 -07:00
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
2016-05-09 11:00:54 -07:00
|
|
|
import 'package:flutter_gallery/gallery/example_code_parser.dart';
|
2018-08-14 20:33:58 -07:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2016-04-20 09:29:01 -07:00
|
|
|
|
|
|
|
|
void main() {
|
2016-05-09 11:00:54 -07:00
|
|
|
test('Flutter gallery example code parser test', () async {
|
2018-09-12 08:29:29 +02:00
|
|
|
final TestAssetBundle bundle = TestAssetBundle();
|
2016-04-20 09:29:01 -07:00
|
|
|
|
2017-03-03 17:51:21 -08:00
|
|
|
final String codeSnippet0 = await getExampleCode('test_0', bundle);
|
2016-04-20 09:29:01 -07:00
|
|
|
expect(codeSnippet0, 'test 0 0\ntest 0 1');
|
|
|
|
|
|
2017-03-03 17:51:21 -08:00
|
|
|
final String codeSnippet1 = await getExampleCode('test_1', bundle);
|
2016-04-20 09:29:01 -07:00
|
|
|
expect(codeSnippet1, 'test 1 0\ntest 1 1');
|
2018-02-28 20:39:48 +00:00
|
|
|
|
|
|
|
|
final String codeSnippet3 = await getExampleCode('test_2_windows_breaks', bundle);
|
|
|
|
|
expect(codeSnippet3, 'windows test 2 0\nwindows test 2 1');
|
2016-04-20 09:29:01 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 18:11:36 +02:00
|
|
|
const String testCodeFile = '''// A fake test file
|
2016-04-20 09:29:01 -07:00
|
|
|
// START test_0
|
|
|
|
|
test 0 0
|
|
|
|
|
test 0 1
|
|
|
|
|
// END
|
|
|
|
|
|
|
|
|
|
// Some comments
|
|
|
|
|
// START test_1
|
|
|
|
|
test 1 0
|
|
|
|
|
test 1 1
|
|
|
|
|
// END
|
2018-02-28 20:39:48 +00:00
|
|
|
|
|
|
|
|
// START test_2_windows_breaks\r\nwindows test 2 0\r\nwindows test 2 1\r\n// END
|
2017-10-22 18:11:36 +02:00
|
|
|
''';
|
2016-04-20 09:29:01 -07:00
|
|
|
|
|
|
|
|
class TestAssetBundle extends AssetBundle {
|
|
|
|
|
@override
|
2018-11-05 16:38:23 +01:00
|
|
|
Future<ByteData> load(String key) async => null;
|
2016-04-20 09:29:01 -07:00
|
|
|
|
|
|
|
|
@override
|
2018-11-05 16:38:23 +01:00
|
|
|
Future<String> loadString(String key, { bool cache = true }) async {
|
2016-04-20 12:45:54 -07:00
|
|
|
if (key == 'lib/gallery/example_code.dart')
|
2018-11-05 16:38:23 +01:00
|
|
|
return testCodeFile;
|
2016-04-20 09:29:01 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2017-02-03 13:55:07 -08:00
|
|
|
Future<T> loadStructuredData<T>(String key, Future<T> parser(String value)) async {
|
2016-06-16 09:49:48 -07:00
|
|
|
return parser(await loadString(key));
|
|
|
|
|
}
|
2016-04-20 09:29:01 -07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() => '$runtimeType@$hashCode()';
|
|
|
|
|
}
|