1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import sync
import test.framework
proc main()
let runner = new framework.TestRunner()
// Basic: no flags
let a1: [string] = sync.build_rsync_args("/src/", "/dst/", false, false, false, new [string](0))
runner.assert_eq_bool(contains_str(a1, "-aHAX"), true, "has -aHAX")
runner.assert_eq_bool(contains_str(a1, "--info=stats2"), true, "has --info=stats2")
runner.assert_eq_bool(contains_str(a1, "--delete"), true, "delete on by default")
runner.assert_eq_bool(contains_str(a1, "--exclude=node_modules/"), true, "node_modules excluded")
runner.assert_eq_bool(contains_str(a1, "--exclude=.cache/"), true, ".cache excluded")
runner.assert_eq_bool(last_two(a1, "/src/", "/dst/"), true, "src and dst end positional")
// Dry run: --dry-run + --itemize-changes + --info=stats2 (NOT progress2)
let a2: [string] = sync.build_rsync_args("/src/", "/dst/", true, false, true, new [string](0))
runner.assert_eq_bool(contains_str(a2, "--dry-run"), true, "dry-run flag")
runner.assert_eq_bool(contains_str(a2, "--itemize-changes"), true, "itemize-changes flag")
runner.assert_eq_bool(contains_str(a2, "--info=stats2"), true, "info stats2")
runner.assert_eq_bool(contains_str(a2, "--info=stats2,progress2"), false, "no progress in dry-run")
// No delete
let a3: [string] = sync.build_rsync_args("/src/", "/dst/", false, true, false, new [string](0))
runner.assert_eq_bool(contains_str(a3, "--delete"), false, "no --delete with no_delete")
// TTY interactive: stats2,progress2
let a4: [string] = sync.build_rsync_args("/src/", "/dst/", false, false, true, new [string](0))
runner.assert_eq_bool(contains_str(a4, "--info=stats2,progress2"), true, "tty progress")
// Excluded repos in whole-tree mode
let a5: [string] = sync.build_rsync_args("/src/", "/dst/", false, false, false, ["repo-A", "repo-B"])
runner.assert_eq_bool(contains_str(a5, "--exclude=repo-A/"), true, "excluded repo A")
runner.assert_eq_bool(contains_str(a5, "--exclude=repo-B/"), true, "excluded repo B")
runner.report()
end main
fn contains_str(arr: [string], target: string): bool
let n: int = arr.length()
mut i: int = 0
while i < n
if arr[i] == target
return true
end if
i = i + 1
end while
return false
end contains_str
fn last_two(arr: [string], a: string, b: string): bool
let n: int = arr.length()
if n < 2
return false
end if
return arr[n - 2] == a and arr[n - 1] == b
end last_two
|