72 lines
1.8 KiB
Dart
72 lines
1.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fuel_tax_tracker/services/receipt_parser.dart';
|
|
|
|
void main() {
|
|
group('ReceiptParser', () {
|
|
test('parses a typical gas station receipt', () {
|
|
const receipt = '''
|
|
SHELL OIL 12345
|
|
123 MAIN ST
|
|
PUMP 04
|
|
GALLONS 12.345
|
|
PRICE/GAL \$3.599
|
|
FUEL TOTAL \$44.44
|
|
THANK YOU
|
|
''';
|
|
|
|
final result = ReceiptParser.parse(receipt);
|
|
|
|
expect(result.gallons, 12.345);
|
|
expect(result.pricePerGallon, 3.599);
|
|
expect(result.totalCost, 44.44);
|
|
});
|
|
|
|
test('does not confuse SUBTOTAL with TOTAL', () {
|
|
const receipt = '''
|
|
SUBTOTAL 10.00
|
|
TAX 0.50
|
|
TOTAL 10.50
|
|
''';
|
|
|
|
final result = ReceiptParser.parse(receipt);
|
|
|
|
expect(result.totalCost, 10.50);
|
|
});
|
|
|
|
test('derives total when gallons and price per gallon are known', () {
|
|
const receipt = '''
|
|
GALLONS 10.000
|
|
PPG 3.500
|
|
''';
|
|
|
|
final result = ReceiptParser.parse(receipt);
|
|
|
|
expect(result.gallons, 10.0);
|
|
expect(result.pricePerGallon, 3.5);
|
|
expect(result.totalCost, 35.0);
|
|
});
|
|
|
|
test('derives gallons when total and price per gallon are known', () {
|
|
const receipt = '''
|
|
PRICE PER GALLON \$4.000
|
|
TOTAL \$20.00
|
|
''';
|
|
|
|
final result = ReceiptParser.parse(receipt);
|
|
|
|
expect(result.pricePerGallon, 4.0);
|
|
expect(result.totalCost, 20.0);
|
|
expect(result.gallons, 5.0);
|
|
});
|
|
|
|
test('returns nulls when nothing recognizable is present', () {
|
|
const receipt = 'THANK YOU FOR YOUR PURCHASE';
|
|
|
|
final result = ReceiptParser.parse(receipt);
|
|
|
|
expect(result.gallons, isNull);
|
|
expect(result.pricePerGallon, isNull);
|
|
expect(result.totalCost, isNull);
|
|
});
|
|
});
|
|
}
|