alpha
Login
or
Join now
nandi.uk
/
gleam
Star
2
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Fork of daniellemaywood.uk/gleam — Wasm codegen work
Star
2
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
Add cycle detection tests
author
Adi Salimgereev
committer
Louis Pilfold
date
2 years ago
(Dec 3, 2023, 6:09 PM UTC)
commit
4d003ad3
4d003ad38c63691d3c1735085ec713a0f6247c02
parent
d4cc5e4c
d4cc5e4c71fa159e08c167aca11418c449f17561
+82
-32
1 changed file
Expand all
Collapse all
Unified
Split
compiler-core
src
dep_tree.rs
+82
-32
compiler-core/src/dep_tree.rs
View file
Reviewed
···
42
42
}
43
43
}
44
44
45
45
-
// TODO: test
46
45
fn import_cycle(
47
46
cycle: Cycle<NodeIndex>,
48
47
graph: &petgraph::Graph<(), ()>,
···
84
83
false
85
84
}
86
85
87
87
-
#[test]
88
88
-
fn toposort_deps_test() {
89
89
-
// All deps are nodes
90
90
-
assert_eq!(
91
91
-
toposort_deps(vec![
92
92
-
("a".into(), vec!["b".into()]),
93
93
-
("c".into(), vec![]),
94
94
-
("b".into(), vec!["c".into()])
95
95
-
]),
96
96
-
Ok(vec!["c".into(), "b".into(), "a".into()])
97
97
-
);
98
98
-
99
99
-
// No deps
100
100
-
assert_eq!(
101
101
-
toposort_deps(vec![
102
102
-
("no-deps-1".into(), vec![]),
103
103
-
("no-deps-2".into(), vec![])
104
104
-
]),
105
105
-
Ok(vec!["no-deps-1".into(), "no-deps-2".into(),])
106
106
-
);
107
107
-
108
108
-
// Some deps are not nodes (and thus are ignored)
109
109
-
assert_eq!(
110
110
-
toposort_deps(vec![
111
111
-
("a".into(), vec!["b".into(), "z".into()]),
112
112
-
("b".into(), vec!["x".into()])
113
113
-
]),
114
114
-
Ok(vec!["b".into(), "a".into()])
115
115
-
);
116
116
-
}
117
117
-
118
86
#[derive(Debug, PartialEq)]
119
87
pub enum Error {
120
88
Cycle(Vec<EcoString>),
121
89
}
90
90
+
91
91
+
#[cfg(test)]
92
92
+
mod tests {
93
93
+
use super::*;
94
94
+
95
95
+
#[test]
96
96
+
fn toposort_deps_test() {
97
97
+
// All deps are nodes
98
98
+
assert_eq!(
99
99
+
toposort_deps(vec![
100
100
+
("a".into(), vec!["b".into()]),
101
101
+
("c".into(), vec![]),
102
102
+
("b".into(), vec!["c".into()])
103
103
+
]),
104
104
+
Ok(vec!["c".into(), "b".into(), "a".into()])
105
105
+
);
106
106
+
107
107
+
// No deps
108
108
+
assert_eq!(
109
109
+
toposort_deps(vec![
110
110
+
("no-deps-1".into(), vec![]),
111
111
+
("no-deps-2".into(), vec![])
112
112
+
]),
113
113
+
Ok(vec!["no-deps-1".into(), "no-deps-2".into(),])
114
114
+
);
115
115
+
116
116
+
// Some deps are not nodes (and thus are ignored)
117
117
+
assert_eq!(
118
118
+
toposort_deps(vec![
119
119
+
("a".into(), vec!["b".into(), "z".into()]),
120
120
+
("b".into(), vec!["x".into()])
121
121
+
]),
122
122
+
Ok(vec!["b".into(), "a".into()])
123
123
+
);
124
124
+
}
125
125
+
126
126
+
#[test]
127
127
+
fn cycle_detection() {
128
128
+
// a ---+
129
129
+
// ^ |
130
130
+
// | v
131
131
+
// +----+
132
132
+
assert_eq!(
133
133
+
toposort_deps(vec![("a".into(), vec!["a".into()])]),
134
134
+
Err(Error::Cycle(vec!["a".into()]))
135
135
+
);
136
136
+
137
137
+
// a -> b -> c
138
138
+
// ^ v
139
139
+
// | |
140
140
+
// +---------+
141
141
+
assert_eq!(
142
142
+
toposort_deps(vec![
143
143
+
("a".into(), vec!["b".into()]),
144
144
+
("b".into(), vec!["c".into()]),
145
145
+
("c".into(), vec!["a".into()]),
146
146
+
]),
147
147
+
Err(Error::Cycle(vec!["c".into(), "b".into(), "a".into()]))
148
148
+
);
149
149
+
150
150
+
// a -> b <- e
151
151
+
// | | ^
152
152
+
// v v |
153
153
+
// f c -> d
154
154
+
assert_eq!(
155
155
+
toposort_deps(vec![
156
156
+
("a".into(), vec!["b".into()]),
157
157
+
("b".into(), vec!["c".into()]),
158
158
+
("c".into(), vec!["d".into()]),
159
159
+
("d".into(), vec!["e".into()]),
160
160
+
("e".into(), vec!["b".into()]),
161
161
+
("a".into(), vec!["f".into()]),
162
162
+
]),
163
163
+
Err(Error::Cycle(vec![
164
164
+
"e".into(),
165
165
+
"d".into(),
166
166
+
"c".into(),
167
167
+
"b".into(),
168
168
+
]))
169
169
+
);
170
170
+
}
171
171
+
}