Debian Codegraph @

tests/sort.rs

raw symbols SCIP
1 mod sort {
2 use rust_apt::cache::*;
3 use rust_apt::new_cache;
4
5 #[test]
6 fn defaults() {
7 let cache = new_cache!().unwrap();
8 let mut installed = false;
9 let mut auto_installed = false;
10
11 // Test defaults and ensure there are no virtual packages.
12 // And that we have any packages at all.
13 let mut real_pkgs = Vec::new();
14 let mut virtual_pkgs = Vec::new();
15
16 let sort = PackageSort::default();
17
18 for pkg in cache.packages(&sort) {
19 if pkg.is_auto_installed() {
20 auto_installed = true;
21 }
22 if pkg.is_installed() {
23 installed = true;
24 }
25
26 if pkg.has_versions() {
27 real_pkgs.push(pkg);
28 continue;
29 }
30 virtual_pkgs.push(pkg);
31 }
32 assert!(!real_pkgs.is_empty());
33 assert!(virtual_pkgs.is_empty());
34 assert!(auto_installed);
35 assert!(installed)
36 }
37
38 #[test]
39 fn include_virtual() {
40 let cache = new_cache!().unwrap();
41
42 // Check that we have virtual and real packages after sorting.
43 let mut real_pkgs = Vec::new();
44 let mut virtual_pkgs = Vec::new();
45
46 let sort = PackageSort::default().include_virtual().names();
47
48 for pkg in cache.packages(&sort) {
49 if pkg.has_versions() {
50 real_pkgs.push(pkg);
51 continue;
52 }
53 virtual_pkgs.push(pkg);
54 }
55 assert!(!real_pkgs.is_empty());
56 assert!(!virtual_pkgs.is_empty());
57 }
58
59 #[test]
60 fn only_virtual() {
61 let cache = new_cache!().unwrap();
62
63 // Check that we have only virtual packages.
64 let mut real_pkgs = Vec::new();
65 let mut virtual_pkgs = Vec::new();
66
67 let sort = PackageSort::default().only_virtual();
68
69 for pkg in cache.packages(&sort) {
70 if pkg.has_versions() {
71 real_pkgs.push(pkg);
72 continue;
73 }
74 virtual_pkgs.push(pkg);
75 }
76 assert!(real_pkgs.is_empty());
77 assert!(!virtual_pkgs.is_empty());
78 }
79
80 #[test]
81 fn upgradable() {
82 let cache = new_cache!().unwrap();
83
84 let sort = PackageSort::default().upgradable();
85 for pkg in cache.packages(&sort) {
86 assert!(pkg.is_upgradable())
87 }
88
89 let sort = PackageSort::default().not_upgradable();
90 for pkg in cache.packages(&sort) {
91 assert!(!pkg.is_upgradable())
92 }
93 }
94
95 #[test]
96 fn installed() {
97 let cache = new_cache!().unwrap();
98
99 let sort = PackageSort::default().installed();
100 for pkg in cache.packages(&sort) {
101 assert!(pkg.is_installed())
102 }
103
104 let sort = PackageSort::default().not_installed();
105 for pkg in cache.packages(&sort) {
106 assert!(!pkg.is_installed())
107 }
108 }
109
110 #[test]
111 fn auto_installed() {
112 let cache = new_cache!().unwrap();
113
114 let sort = PackageSort::default().auto_installed();
115 for pkg in cache.packages(&sort) {
116 println!("{}", pkg.name());
117 assert!(pkg.is_auto_installed())
118 }
119
120 let sort = PackageSort::default().manually_installed();
121 for pkg in cache.packages(&sort) {
122 assert!(!pkg.is_auto_installed());
123 }
124 }
125
126 #[test]
127 fn auto_removable() {
128 let cache = new_cache!().unwrap();
129
130 let sort = PackageSort::default().auto_removable();
131 for pkg in cache.packages(&sort) {
132 assert!(pkg.is_auto_removable())
133 }
134
135 let sort = PackageSort::default().not_auto_removable();
136 for pkg in cache.packages(&sort) {
137 assert!(!pkg.is_auto_removable())
138 }
139 }
140 }