JJ_MKVMaker/test/nav_history_contract_test.dart

55 lines
1.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:jj_mkvmaker/core/file_ops.dart' show samePath;
import 'package:jj_mkvmaker/core/nav_history.dart';
/// E5a 약속 시험 (모듈 하나에 한 장): lib/core/nav_history.dart 맨 위 약속.
void main() {
test('다른 곳으로 가면 떠난 곳이 뒤로, 앞으로는 비움 · 같은 곳 · 빈 경로는 넣지 않음 (대소문자 무시)', () {
final h = NavHistory(same: samePath);
h.visit('', r'C:\A');
h.visit(r'C:\A', r'c:\a');
expect(h.canBack, isFalse);
h.visit(r'C:\A', r'C:\B');
h.visit(r'C:\B', r'C:\C');
expect(h.back, [r'C:\A', r'C:\B']);
expect(h.canForward, isFalse);
});
test('뒤로 → 앞으로 · 새로 가면 앞으로를 비움 · 움직이는 중에는 넣지도 꺼내지도 않음', () {
final h = NavHistory(same: samePath)
..visit('a', 'b')
..visit('b', 'c');
final to = h.take(forward: false);
expect(to, 'b');
expect(h.take(forward: false), isNull, reason: '앞의 뒤로가 끝나기 전');
h.visit('c', 'b'); // 이동하는 동안 지금 폴더가 바뀜 - 넣지 않음
h.arrive('c', forward: false);
h.finish();
expect([h.back, h.forward], [
['a'],
['c']
]);
expect(h.take(forward: true), 'c');
h
..arrive('b', forward: true)
..finish();
expect(h.back, ['a', 'b']);
h.visit('c', 'd');
expect(h.forward, isEmpty);
});
test('갈 수 없으면 그 항목만 버리고 지금 자리 그대로 · 상한', () {
final h = NavHistory(same: samePath, limit: 3);
for (var i = 0; i < 5; i++) {
h.visit('$i', '${i + 1}');
}
expect(h.back, ['2', '3', '4']);
expect(h.take(forward: false), '4');
h.finish();
expect([h.back, h.forward], [
['2', '3'],
<String>[]
]);
});
}