import 'package:flutter_test/flutter_test.dart'; import 'package:pad_scanner/services/code_parser.dart'; void main() { group('CodeParser.parse', () { test('identifies zongpaiNo type B', () { final result = CodeParser.parse('26B1'); expect(result.type, CodeType.zongpaiNo); expect(result.value, '26B1'); }); test('identifies zongpaiNo type C', () { final result = CodeParser.parse('26C12'); expect(result.type, CodeType.zongpaiNo); }); test('identifies zongpaiNo type T', () { final result = CodeParser.parse('26T3'); expect(result.type, CodeType.zongpaiNo); }); test('identifies zongpaiNo type BW (4 digits)', () { final result = CodeParser.parse('26BW0001'); expect(result.type, CodeType.zongpaiNo); }); test('identifies zongpaiNo type CW (4 digits)', () { final result = CodeParser.parse('26CW0015'); expect(result.type, CodeType.zongpaiNo); }); test('rejects BW with non-4-digit serial', () { expect(CodeParser.parse('26BW01').type, CodeType.invalid); }); test('rejects CW with non-4-digit serial', () { expect(CodeParser.parse('26CW15').type, CodeType.invalid); }); test('identifies normal location code', () { final result = CodeParser.parse('A01-02-03'); expect(result.type, CodeType.locationNormal); expect(result.value, 'A01-02-03'); }); test('identifies transit location code', () { final result = CodeParser.parse('TRANS-01'); expect(result.type, CodeType.locationTransit); }); test('normalizes lowercase zongpaiNo to uppercase', () { final result = CodeParser.parse('26b1'); expect(result.type, CodeType.zongpaiNo); expect(result.value, '26B1'); }); test('normalizes lowercase location code to uppercase', () { final result = CodeParser.parse('a01-02-03'); expect(result.type, CodeType.locationNormal); expect(result.value, 'A01-02-03'); }); test('rejects invalid code', () { expect(CodeParser.parse('HELLO123').type, CodeType.invalid); }); test('rejects empty string', () { expect(CodeParser.parse('').type, CodeType.invalid); }); test('isLocation helper', () { expect(CodeParser.isLocation(CodeType.locationNormal), true); expect(CodeParser.isLocation(CodeType.locationTransit), true); expect(CodeParser.isLocation(CodeType.zongpaiNo), false); expect(CodeParser.isLocation(CodeType.invalid), false); }); }); group('CodeParser.parse attachmentCode (FJ-)', () { test('identifies FJ- with zongpai B type', () { final result = CodeParser.parse('FJ-26B1'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26B1'); }); test('identifies FJ- with zongpai C type', () { final result = CodeParser.parse('FJ-26C12'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26C12'); }); test('identifies FJ- with zongpai T type', () { final result = CodeParser.parse('FJ-26T3'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26T3'); }); test('identifies FJ- with zongpai BW 4-digit', () { final result = CodeParser.parse('FJ-26BW0001'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26BW0001'); }); test('identifies FJ- with zongpai CW 4-digit', () { final result = CodeParser.parse('FJ-26CW0015'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26CW0015'); }); test('normalizes lowercase fj- to uppercase', () { final result = CodeParser.parse('fj-26b1'); expect(result.type, CodeType.attachmentCode); expect(result.value, '26B1'); }); test('rejects FJ without hyphen', () { expect(CodeParser.parse('FJ26B1').type, CodeType.invalid); }); test('rejects FJ- with invalid zongpai', () { expect(CodeParser.parse('FJ-HELLO').type, CodeType.invalid); }); test('rejects FJ- with BW short serial', () { expect(CodeParser.parse('FJ-26BW01').type, CodeType.invalid); }); test('attaches original raw code with FJ- prefix for display', () { final result = CodeParser.parse('FJ-26B42360'); expect(result.value, '26B42360'); }); }); }