Skip to content

Commit 3409eac

Browse files
committed
add some unfinished tests
1 parent ad30382 commit 3409eac

File tree

1 file changed

+78
-121
lines changed

1 file changed

+78
-121
lines changed

crates/hir-ty/src/tests/simple.rs

Lines changed: 78 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,25 +1958,89 @@ use core::ops::Coroutine;
19581958
19591959
pub fn test() {
19601960
let mut coroutine = || {
1961-
yield 1i32;
1961+
yield 1i8;
1962+
2u8
19621963
};
19631964
let _result = Pin::new(&mut coroutine).resume(());
19641965
}
19651966
"#,
19661967
expect![[r#"
1967-
61..175 '{ ...()); }': ()
1968-
71..84 'mut coroutine': |()| yields i32 -> ()
1969-
87..117 '|| { ... }': |()| yields i32 -> ()
1970-
90..117 '{ ... }': ()
1971-
100..110 'yield 1i32': ()
1972-
106..110 '1i32': i32
1973-
127..134 '_result': CoroutineState<i32, ()>
1974-
137..145 'Pin::new': fn new<&mut |()| yields i32 -> ()>(&mut |()| yields i32 -> ()) -> Pin<&mut |()| yields i32 -> ()>
1975-
137..161 'Pin::n...utine)': Pin<&mut |()| yields i32 -> ()>
1976-
137..172 'Pin::n...me(())': CoroutineState<i32, ()>
1977-
146..160 '&mut coroutine': &mut |()| yields i32 -> ()
1978-
151..160 'coroutine': |()| yields i32 -> ()
1979-
169..171 '()': ()
1968+
61..186 '{ ...()); }': ()
1969+
71..84 'mut coroutine': |()| yields i8 -> u8
1970+
87..128 '|| { ... }': |()| yields i8 -> u8
1971+
90..128 '{ ... }': u8
1972+
100..109 'yield 1i8': ()
1973+
106..109 '1i8': i8
1974+
119..122 '2u8': u8
1975+
138..145 '_result': CoroutineState<i8, u8>
1976+
148..156 'Pin::new': fn new<&mut |()| yields i8 -> u8>(&mut |()| yields i8 -> u8) -> Pin<&mut |()| yields i8 -> u8>
1977+
148..172 'Pin::n...utine)': Pin<&mut |()| yields i8 -> u8>
1978+
148..183 'Pin::n...me(())': CoroutineState<i8, u8>
1979+
157..171 '&mut coroutine': &mut |()| yields i8 -> u8
1980+
162..171 'coroutine': |()| yields i8 -> u8
1981+
180..182 '()': ()
1982+
"#]],
1983+
);
1984+
}
1985+
1986+
1987+
#[test]
1988+
fn gen_types_fully_inferred() {
1989+
check_infer(
1990+
r#"
1991+
//- minicore: iterator, deref
1992+
use core::iter::Iterator;
1993+
1994+
pub fn test() {
1995+
let mut generator = gen {
1996+
yield 1i8;
1997+
};
1998+
let _result = generator.next();
1999+
}
2000+
"#,
2001+
expect![[r#"
2002+
41..136 '{ ...t(); }': ()
2003+
51..64 'mut generator': impl Iterator<Item = i8>
2004+
67..97 'gen { ... }': impl Iterator<Item = i8>
2005+
67..97 'gen { ... }': ()
2006+
81..90 'yield 1i8': ()
2007+
87..90 '1i8': i8
2008+
107..114 '_result': Option<i8>
2009+
117..126 'generator': impl Iterator<Item = i8>
2010+
117..133 'genera...next()': Option<i8>
2011+
"#]],
2012+
);
2013+
}
2014+
2015+
2016+
#[test]
2017+
fn async_gen_types_fully_inferred() {
2018+
check_infer(
2019+
r#"
2020+
//- minicore: async_iterator, future, deref
2021+
use core::task::{Context, Poll};
2022+
use core::async_iter::AsyncIterator;
2023+
2024+
pub fn test(mut context: Context) {
2025+
let mut async_generator = async gen {
2026+
yield 1i8;
2027+
};
2028+
let _result = async_generator.poll_next(&mut context);
2029+
}
2030+
"#,
2031+
expect![[r#"
2032+
83..94 'mut context': Context<'_>
2033+
105..235 '{ ...xt); }': ()
2034+
115..134 'mut as...erator': impl AsyncIterator<Item = i8>
2035+
137..173 'async ... }': impl AsyncIterator<Item = i8>
2036+
137..173 'async ... }': ()
2037+
157..166 'yield 1i8': ()
2038+
163..166 '1i8': i8
2039+
183..190 '_result': {unknown}
2040+
193..208 'async_generator': impl AsyncIterator<Item = i8>
2041+
193..232 'async_...ntext)': {unknown}
2042+
219..231 '&mut context': &mut Context<'_>
2043+
224..231 'context': Context<'_>
19802044
"#]],
19812045
);
19822046
}
@@ -2048,114 +2112,7 @@ fn test() {
20482112
);
20492113
}
20502114

2051-
#[test]
2052-
fn gen_types_inferred() {
2053-
check_infer(
2054-
r#"
2055-
//- minicore: iterator, deref
2056-
use core::iter::Iterator;
2057-
2058-
fn f(v: i64) {}
2059-
fn test() {
2060-
let mut g = gen {
2061-
let a = yield 0;
2062-
let a = yield 1;
2063-
let a = yield 2;
2064-
};
2065-
2066-
match g.next() {
2067-
Some(y) => { f(y); }
2068-
None => {}
2069-
}
2070-
}
2071-
"#,
2072-
expect![[r#"
2073-
32..33 'v': i64
2074-
40..42 '{}': ()
2075-
53..236 '{ ... } }': ()
2076-
63..68 'mut g': impl Iterator<Item = i64>
2077-
71..157 'gen { ... }': impl Iterator<Item = i64>
2078-
71..157 'gen { ... }': ()
2079-
89..90 'a': ()
2080-
93..100 'yield 0': ()
2081-
99..100 '0': i64
2082-
114..115 'a': ()
2083-
118..125 'yield 1': ()
2084-
124..125 '1': i64
2085-
139..140 'a': ()
2086-
143..150 'yield 2': ()
2087-
149..150 '2': i64
2088-
164..234 'match ... }': ()
2089-
170..171 'g': impl Iterator<Item = i64>
2090-
170..178 'g.next()': Option<i64>
2091-
189..196 'Some(y)': Option<i64>
2092-
194..195 'y': i64
2093-
200..209 '{ f(y); }': ()
2094-
202..203 'f': fn f(i64)
2095-
202..206 'f(y)': ()
2096-
204..205 'y': i64
2097-
218..222 'None': Option<i64>
2098-
226..228 '{}': ()
2099-
"#]],
2100-
);
2101-
}
2102-
2103-
#[test]
2104-
fn async_gen_types_inferred() {
2105-
check_infer(
2106-
r#"
2107-
//- minicore: async_iterator, future, deref
2108-
use core::task::{Context, Poll};
2109-
use core::async_iter::AsyncIterator;
21102115

2111-
fn f(v: i64) {}
2112-
fn test(mut context: Context) {
2113-
let mut g = async gen {
2114-
let a = yield 0;
2115-
let a = yield 1;
2116-
let a = yield 2;
2117-
};
2118-
2119-
match g.poll_next(&mut context) {
2120-
Poll::Ready(Some(y)) => { f(y); } // FIXME test with 1 there I think this infers stuff it should not
2121-
Poll::Pending => {}
2122-
}
2123-
}
2124-
"#,
2125-
expect![[r#"
2126-
76..77 'v': i64
2127-
84..86 '{}': ()
2128-
95..106 'mut context': Context<'_>
2129-
117..412 '{ ... } }': ()
2130-
127..132 'mut g': impl AsyncIterator<Item = i32>
2131-
135..227 'async ... }': impl AsyncIterator<Item = i32>
2132-
135..227 'async ... }': ()
2133-
159..160 'a': ()
2134-
163..170 'yield 0': ()
2135-
169..170 '0': i32
2136-
184..185 'a': ()
2137-
188..195 'yield 1': ()
2138-
194..195 '1': i32
2139-
209..210 'a': ()
2140-
213..220 'yield 2': ()
2141-
219..220 '2': i32
2142-
234..410 'match ... }': ()
2143-
240..241 'g': impl AsyncIterator<Item = i32>
2144-
240..265 'g.poll...ntext)': Poll<Option<i64>>
2145-
252..264 '&mut context': &mut Context<'_>
2146-
257..264 'context': Context<'_>
2147-
276..296 'Poll::...me(y))': Poll<Option<i64>>
2148-
288..295 'Some(y)': Option<i64>
2149-
293..294 'y': i64
2150-
300..309 '{ f(y); }': ()
2151-
302..303 'f': fn f(i64)
2152-
302..306 'f(y)': ()
2153-
304..305 'y': i64
2154-
385..398 'Poll::Pending': Poll<Option<i64>>
2155-
402..404 '{}': ()
2156-
"#]],
2157-
);
2158-
}
21592116

21602117
#[test]
21612118
fn coroutine_resume_yield_return_unit() {

0 commit comments

Comments
 (0)