|
| 1 | +{% if 'dart' in language.params.packageName %} |
| 2 | +import 'package:test/test.dart'; |
| 3 | +{% else %} |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | +{% endif %} |
| 6 | +import 'package:{{language.params.packageName}}/src/exception.dart'; |
| 7 | +import 'package:{{language.params.packageName}}/src/input_file.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('InputFile', () { |
| 11 | + test('throws exception when neither path nor bytes are provided', () { |
| 12 | + expect( |
| 13 | + () => InputFile(), |
| 14 | + throwsA(isA<{{spec.title | caseUcfirst}}Exception>().having( |
| 15 | + (e) => e.message, |
| 16 | + 'message', |
| 17 | + 'One of `path` or `bytes` is required', |
| 18 | + )), |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + test('throws exception when path and bytes are both null', () { |
| 23 | + expect( |
| 24 | + () => InputFile(path: null, bytes: null), |
| 25 | + throwsA(isA<{{spec.title | caseUcfirst}}Exception>().having( |
| 26 | + (e) => e.message, |
| 27 | + 'message', |
| 28 | + 'One of `path` or `bytes` is required', |
| 29 | + )), |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + test('creates InputFile from path', () { |
| 34 | + final inputFile = InputFile.fromPath(path: '/path/to/file'); |
| 35 | + |
| 36 | + expect(inputFile.path, '/path/to/file'); |
| 37 | + expect(inputFile.filename, isNull); |
| 38 | + expect(inputFile.contentType, isNull); |
| 39 | + expect(inputFile.bytes, isNull); |
| 40 | + }); |
| 41 | + |
| 42 | + test('creates InputFile from bytes', () { |
| 43 | + final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt'); |
| 44 | + |
| 45 | + expect(inputFile.path, isNull); |
| 46 | + expect(inputFile.filename, 'file.txt'); |
| 47 | + expect(inputFile.contentType, isNull); |
| 48 | + expect(inputFile.bytes, [1, 2, 3]); |
| 49 | + }); |
| 50 | + }); |
| 51 | +} |
0 commit comments