import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:jj_mkvmaker/app/transfer_plan.dart'; import 'package:jj_mkvmaker/core/file_clipboard.dart'; import 'package:path/path.dart' as p; /// E5b 약속 시험: lib/app/transfer_plan.dart · lib/core/file_clipboard.dart 맨 위 약속 (시험 폴더의 실제 파일). void main() { late Directory tmp; late String src, dst, a, b, sub, inner; setUp(() { tmp = Directory.systemTemp.createTempSync('jj_plan_'); src = p.join(tmp.path, 'src'); dst = p.join(tmp.path, 'dst'); sub = p.join(src, 'sub'); Directory(sub).createSync(recursive: true); Directory(dst).createSync(); a = p.join(src, 'a.txt'); b = p.join(src, 'b.txt'); inner = p.join(sub, 'in.txt'); for (final f in [a, b, inner]) { File(f).writeAsStringSync('x'); } File(p.join(dst, 'a.txt')).writeAsStringSync('older and longer'); }); tearDown(() => tmp.deleteSync(recursive: true)); test('보통: 바깥 것만 보냄 · 문제 없음', () { final plan = planTransfer([sub, inner, a], dst, move: false); expect(plan.sources, [sub, a], reason: '고른 폴더 안의 것은 한 번만'); expect([plan.askCopyHere, plan.nothingToMove, plan.problem], [false, false, null]); }); test('같은 폴더로: 이동 일부 = 그것만 건너뜀 · 이동 전부 = 할 것 없음 · 복사 전부 = 사본을 물음', () { final some = planTransfer([a, p.join(dst, 'a.txt')], dst, move: true); expect(some.skippedHere, [p.join(dst, 'a.txt')]); expect(some.sources, [a]); final allMove = planTransfer([a, b], src, move: true); expect([allMove.nothingToMove, allMove.problem], [true, null]); final allCopy = planTransfer([a, b], src, move: false); expect(allCopy.askCopyHere, isTrue); expect(allCopy.sources, [a, b]); }); test('막는 문제: 없는 원본 · 폴더를 자기 안으로', () { expect(planTransfer([p.join(src, 'none.txt')], dst, move: false).problem, isNotNull); expect(planTransfer([src], sub, move: true).problem, isNotNull); }); test('같은 이름: 대상에 있는 것만, 크기 · 바뀐 날 함께 · 이름 줄임', () async { final clashes = await findClashes([a, b], dst); expect([for (final c in clashes) c.src], [a]); expect(clashes.single.there.size, greaterThan(clashes.single.here!.size)); expect(namesOf(['x/1', 'x/2', 'x/3', 'x/4', 'x/5']), contains('1, 2, 3')); }); test('담기: 빈 것은 담지 않음 · 이동은 붙여넣은 뒤 비움 · 복사는 남김', () { final clip = FileClipboard(); expect(clip.put([], move: false), isFalse); expect(clip.put([a], move: false), isTrue); clip.pasted(done: true); expect(clip.items, [a], reason: '복사는 여러 곳에'); clip.put([b], move: true); clip.pasted(done: false); expect(clip.isNotEmpty, isTrue, reason: '못 옮겼으면 남음'); clip.pasted(done: true); expect(clip.isEmpty, isTrue); }); }