You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/lsp_features/completion.zig
+119Lines changed: 119 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1925,6 +1925,125 @@ test "switch cases" {
1925
1925
});
1926
1926
}
1927
1927
1928
+
test"switch on error set - all values are suggested" {
1929
+
trytestCompletion(
1930
+
\\const err: error{E1, E2} = undefined;
1931
+
\\switch(err) {
1932
+
\\ error.<cursor>
1933
+
\\}
1934
+
, &.{
1935
+
.{ .label="error.E1", .kind=.Constant },
1936
+
.{ .label="error.E2", .kind=.Constant },
1937
+
});
1938
+
}
1939
+
1940
+
test"switch on error set - already used values are not suggested" {
1941
+
trytestCompletion(
1942
+
\\const err: error{E1, E2} = undefined;
1943
+
\\switch(err) {
1944
+
\\ error.E1 => {},
1945
+
\\ error.<cursor>
1946
+
\\}
1947
+
, &.{
1948
+
.{ .label="error.E2", .kind=.Constant },
1949
+
});
1950
+
}
1951
+
1952
+
test"switch on error set - error unions get all values" {
1953
+
trytestCompletion(
1954
+
\\const Err2 = error{F1, F2};
1955
+
\\const Err = error{E1, E2} || Err2;
1956
+
\\const err: Err = undefined;
1957
+
\\switch(err) {
1958
+
\\ error.<cursor>
1959
+
\\}
1960
+
, &.{
1961
+
.{ .label="error.E1", .kind=.Constant },
1962
+
.{ .label="error.E2", .kind=.Constant },
1963
+
.{ .label="error.F1", .kind=.Constant },
1964
+
.{ .label="error.F2", .kind=.Constant },
1965
+
});
1966
+
}
1967
+
1968
+
test"switch on error set - text edits result" {
1969
+
trytestCompletionTextEdit(.{
1970
+
.source=
1971
+
\\const err: error{E1, E2} = undefined;
1972
+
\\switch(err) {
1973
+
\\ error.<cursor>
1974
+
\\}
1975
+
,
1976
+
.label="error.E1",
1977
+
.expected_insert_line=" error.E1",
1978
+
.expected_replace_line=" error.E1",
1979
+
.enable_snippets=false,
1980
+
});
1981
+
}
1982
+
test"switch on error set - insert/replace text edits" {
1983
+
trytestCompletionTextEdit(.{
1984
+
.source=
1985
+
\\const err: error{Err1, Err2} = undefined;
1986
+
\\switch(err) {
1987
+
\\ error.E<cursor>0
1988
+
\\}
1989
+
,
1990
+
.label="error.Err1",
1991
+
.expected_insert_line=" error.Err10",
1992
+
.expected_replace_line=" error.Err1",
1993
+
.enable_snippets=false,
1994
+
});
1995
+
}
1996
+
1997
+
test"switch on error set - completion inside catch block works" {
1998
+
trytestCompletion(
1999
+
\\fn idk() error{ E1, E2 }!void {}
2000
+
\\test {
2001
+
\\ idk() catch |err| {
2002
+
\\ switch (err) {
2003
+
\\ error.<cursor>
2004
+
\\ }
2005
+
\\ };
2006
+
\\}
2007
+
, &.{
2008
+
.{ .label="error.E1", .kind=.Constant },
2009
+
.{ .label="error.E2", .kind=.Constant },
2010
+
});
2011
+
}
2012
+
2013
+
test"switch on error set - completion inside catch statement" {
2014
+
if (true) returnerror.SkipZigTest; // TODO un-skip after https://github.com/zigtools/zls/issues/2341 and/or https://github.com/zigtools/zls/issues/1112
2015
+
trytestCompletion(
2016
+
\\fn idk() error{ E1, E2 }!void {}
2017
+
\\test {
2018
+
\\ idk() catch |err| switch (err) {
2019
+
\\ error.<cursor>
2020
+
\\ };
2021
+
\\}
2022
+
, &.{
2023
+
.{ .label="error.E1", .kind=.Constant },
2024
+
.{ .label="error.E2", .kind=.Constant },
2025
+
});
2026
+
}
2027
+
2028
+
test"switch on error set - Works in a function of a container" {
2029
+
if (true) returnerror.SkipZigTest; // TODO un-skip after https://github.com/zigtools/zls/issues/1535
0 commit comments