internal: more focused tests for const arguments

This commit is contained in:
Aleksey Kladov 2021-09-19 16:35:10 +03:00
parent 09531b703d
commit a6181bfdb7
28 changed files with 321 additions and 176 deletions

View File

@ -23,11 +23,13 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
m.complete(p, GENERIC_ARG_LIST);
}
// test type_arg
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
// test generic_arg
// type T = S<i32>;
fn generic_arg(p: &mut Parser) {
match p.current() {
LIFETIME_IDENT => lifetime_arg(p),
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
k if k.is_literal() => const_arg(p),
// test associated_type_bounds
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
@ -35,13 +37,15 @@ fn generic_arg(p: &mut Parser) {
name_ref(p);
opt_generic_arg_list(p, false);
match p.current() {
// NameRef<...> =
// test assoc_type_eq
// type T = StreamingIterator<Item<'a> = &'a T>;
T![=] => {
p.bump_any();
types::type_(p);
m.complete(p, ASSOC_TYPE_ARG);
}
// NameRef<...>:
// test assoc_type_bound
// type T = StreamingIterator<Item<'a>: Clone>;
T![:] if !p.at(T![::]) => {
generic_params::bounds(p);
m.complete(p, ASSOC_TYPE_ARG);
@ -53,35 +57,43 @@ fn generic_arg(p: &mut Parser) {
}
}
}
// test const_generic_negated_literal
// fn f() { S::<-1> }
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
k if k.is_literal() => const_arg(p),
_ => type_arg(p),
}
}
// test lifetime_arg
// type T = S<'static>;
fn lifetime_arg(p: &mut Parser) {
let m = p.start();
lifetime(p);
m.complete(p, LIFETIME_ARG);
}
// test const_arg
// type T = S<92>;
pub(super) fn const_arg(p: &mut Parser) {
let m = p.start();
match p.current() {
// test const_arg_block
// type T = S<{90 + 2}>;
T!['{'] => {
expressions::block_expr(p);
m.complete(p, CONST_ARG);
}
// test const_arg_literal
// type T = S<"hello", 0xdeadbeef>;
k if k.is_literal() => {
expressions::literal(p);
m.complete(p, CONST_ARG);
}
// test const_arg_bool_literal
// type T = S<true>;
T![true] | T![false] => {
expressions::literal(p);
m.complete(p, CONST_ARG);
}
// test const_arg_negative_number
// type T = S<-92>;
T![-] => {
let lm = p.start();
p.bump(T![-]);
@ -89,6 +101,8 @@ pub(super) fn const_arg(p: &mut Parser) {
lm.complete(p, PREFIX_EXPR);
m.complete(p, CONST_ARG);
}
// test const_arg_path
// struct S<const N: u32 = u32::MAX>;
_ => {
let lm = p.start();
paths::use_path(p);

View File

@ -81,8 +81,6 @@ fn const_param(p: &mut Parser, m: Marker) {
if p.at(T![=]) {
// test const_param_defaults
// struct A<const N: i32 = -1>;
// struct B<const N: i32 = {}>;
// struct C<const N: i32 = some::CONST>;
p.bump(T![=]);
generic_args::const_arg(p);
}

View File

@ -1,66 +0,0 @@
SOURCE_FILE@0..59
TYPE_ALIAS@0..58
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "A"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..57
PATH@9..57
PATH_SEGMENT@9..57
NAME_REF@9..10
IDENT@9..10 "B"
GENERIC_ARG_LIST@10..57
L_ANGLE@10..11 "<"
LIFETIME_ARG@11..18
LIFETIME@11..18
LIFETIME_IDENT@11..18 "'static"
COMMA@18..19 ","
WHITESPACE@19..20 " "
TYPE_ARG@20..23
PATH_TYPE@20..23
PATH@20..23
PATH_SEGMENT@20..23
NAME_REF@20..23
IDENT@20..23 "i32"
COMMA@23..24 ","
WHITESPACE@24..25 " "
CONST_ARG@25..26
LITERAL@25..26
INT_NUMBER@25..26 "1"
COMMA@26..27 ","
WHITESPACE@27..28 " "
CONST_ARG@28..33
BLOCK_EXPR@28..33
L_CURLY@28..29 "{"
WHITESPACE@29..30 " "
LITERAL@30..31
INT_NUMBER@30..31 "2"
WHITESPACE@31..32 " "
R_CURLY@32..33 "}"
COMMA@33..34 ","
WHITESPACE@34..35 " "
ASSOC_TYPE_ARG@35..43
NAME_REF@35..39
IDENT@35..39 "Item"
EQ@39..40 "="
PATH_TYPE@40..43
PATH@40..43
PATH_SEGMENT@40..43
NAME_REF@40..43
IDENT@40..43 "u64"
COMMA@43..44 ","
WHITESPACE@44..45 " "
CONST_ARG@45..49
LITERAL@45..49
TRUE_KW@45..49 "true"
COMMA@49..50 ","
WHITESPACE@50..51 " "
CONST_ARG@51..56
LITERAL@51..56
FALSE_KW@51..56 "false"
R_ANGLE@56..57 ">"
SEMICOLON@57..58 ";"
WHITESPACE@58..59 "\n"

View File

@ -1 +0,0 @@
type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;

View File

@ -1,30 +0,0 @@
SOURCE_FILE@0..19
FN@0..18
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..4
IDENT@3..4 "f"
PARAM_LIST@4..6
L_PAREN@4..5 "("
R_PAREN@5..6 ")"
WHITESPACE@6..7 " "
BLOCK_EXPR@7..18
L_CURLY@7..8 "{"
WHITESPACE@8..9 " "
PATH_EXPR@9..16
PATH@9..16
PATH_SEGMENT@9..16
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..16
COLON2@10..12 "::"
L_ANGLE@12..13 "<"
CONST_ARG@13..15
PREFIX_EXPR@13..15
MINUS@13..14 "-"
LITERAL@14..15
INT_NUMBER@14..15 "1"
R_ANGLE@15..16 ">"
WHITESPACE@16..17 " "
R_CURLY@17..18 "}"
WHITESPACE@18..19 "\n"

View File

@ -1,4 +1,4 @@
SOURCE_FILE@0..96
SOURCE_FILE@0..29
STRUCT@0..28
STRUCT_KW@0..6 "struct"
WHITESPACE@6..7 " "
@ -29,68 +29,3 @@ SOURCE_FILE@0..96
R_ANGLE@26..27 ">"
SEMICOLON@27..28 ";"
WHITESPACE@28..29 "\n"
STRUCT@29..57
STRUCT_KW@29..35 "struct"
WHITESPACE@35..36 " "
NAME@36..37
IDENT@36..37 "B"
GENERIC_PARAM_LIST@37..56
L_ANGLE@37..38 "<"
CONST_PARAM@38..55
CONST_KW@38..43 "const"
WHITESPACE@43..44 " "
NAME@44..45
IDENT@44..45 "N"
COLON@45..46 ":"
WHITESPACE@46..47 " "
PATH_TYPE@47..50
PATH@47..50
PATH_SEGMENT@47..50
NAME_REF@47..50
IDENT@47..50 "i32"
WHITESPACE@50..51 " "
EQ@51..52 "="
WHITESPACE@52..53 " "
CONST_ARG@53..55
BLOCK_EXPR@53..55
L_CURLY@53..54 "{"
R_CURLY@54..55 "}"
R_ANGLE@55..56 ">"
SEMICOLON@56..57 ";"
WHITESPACE@57..58 "\n"
STRUCT@58..95
STRUCT_KW@58..64 "struct"
WHITESPACE@64..65 " "
NAME@65..66
IDENT@65..66 "C"
GENERIC_PARAM_LIST@66..94
L_ANGLE@66..67 "<"
CONST_PARAM@67..93
CONST_KW@67..72 "const"
WHITESPACE@72..73 " "
NAME@73..74
IDENT@73..74 "N"
COLON@74..75 ":"
WHITESPACE@75..76 " "
PATH_TYPE@76..79
PATH@76..79
PATH_SEGMENT@76..79
NAME_REF@76..79
IDENT@76..79 "i32"
WHITESPACE@79..80 " "
EQ@80..81 "="
WHITESPACE@81..82 " "
CONST_ARG@82..93
PATH_EXPR@82..93
PATH@82..93
PATH@82..86
PATH_SEGMENT@82..86
NAME_REF@82..86
IDENT@82..86 "some"
COLON2@86..88 "::"
PATH_SEGMENT@88..93
NAME_REF@88..93
IDENT@88..93 "CONST"
R_ANGLE@93..94 ">"
SEMICOLON@94..95 ";"
WHITESPACE@95..96 "\n"

View File

@ -1,3 +1 @@
struct A<const N: i32 = -1>;
struct B<const N: i32 = {}>;
struct C<const N: i32 = some::CONST>;

View File

@ -0,0 +1,31 @@
SOURCE_FILE@0..22
TYPE_ALIAS@0..21
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..20
PATH@9..20
PATH_SEGMENT@9..20
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..20
L_ANGLE@10..11 "<"
CONST_ARG@11..19
BLOCK_EXPR@11..19
L_CURLY@11..12 "{"
BIN_EXPR@12..18
LITERAL@12..14
INT_NUMBER@12..14 "90"
WHITESPACE@14..15 " "
PLUS@15..16 "+"
WHITESPACE@16..17 " "
LITERAL@17..18
INT_NUMBER@17..18 "2"
R_CURLY@18..19 "}"
R_ANGLE@19..20 ">"
SEMICOLON@20..21 ";"
WHITESPACE@21..22 "\n"

View File

@ -0,0 +1 @@
type T = S<{90 + 2}>;

View File

@ -0,0 +1,22 @@
SOURCE_FILE@0..16
TYPE_ALIAS@0..15
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..14
PATH@9..14
PATH_SEGMENT@9..14
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..14
L_ANGLE@10..11 "<"
CONST_ARG@11..13
LITERAL@11..13
INT_NUMBER@11..13 "92"
R_ANGLE@13..14 ">"
SEMICOLON@14..15 ";"
WHITESPACE@15..16 "\n"

View File

@ -0,0 +1 @@
type T = S<92>;

View File

@ -0,0 +1,37 @@
SOURCE_FILE@0..45
TYPE_ALIAS@0..44
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..43
PATH@9..43
PATH_SEGMENT@9..43
NAME_REF@9..26
IDENT@9..26 "StreamingIterator"
GENERIC_ARG_LIST@26..43
L_ANGLE@26..27 "<"
ASSOC_TYPE_ARG@27..42
NAME_REF@27..31
IDENT@27..31 "Item"
GENERIC_ARG_LIST@31..35
L_ANGLE@31..32 "<"
LIFETIME_ARG@32..34
LIFETIME@32..34
LIFETIME_IDENT@32..34 "'a"
R_ANGLE@34..35 ">"
COLON@35..36 ":"
WHITESPACE@36..37 " "
TYPE_BOUND_LIST@37..42
TYPE_BOUND@37..42
PATH_TYPE@37..42
PATH@37..42
PATH_SEGMENT@37..42
NAME_REF@37..42
IDENT@37..42 "Clone"
R_ANGLE@42..43 ">"
SEMICOLON@43..44 ";"
WHITESPACE@44..45 "\n"

View File

@ -0,0 +1 @@
type T = StreamingIterator<Item<'a>: Clone>;

View File

@ -0,0 +1,22 @@
SOURCE_FILE@0..21
TYPE_ALIAS@0..20
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..19
PATH@9..19
PATH_SEGMENT@9..19
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..19
L_ANGLE@10..11 "<"
LIFETIME_ARG@11..18
LIFETIME@11..18
LIFETIME_IDENT@11..18 "'static"
R_ANGLE@18..19 ">"
SEMICOLON@19..20 ";"
WHITESPACE@20..21 "\n"

View File

@ -0,0 +1 @@
type T = S<'static>;

View File

@ -0,0 +1,41 @@
SOURCE_FILE@0..46
TYPE_ALIAS@0..45
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..44
PATH@9..44
PATH_SEGMENT@9..44
NAME_REF@9..26
IDENT@9..26 "StreamingIterator"
GENERIC_ARG_LIST@26..44
L_ANGLE@26..27 "<"
ASSOC_TYPE_ARG@27..43
NAME_REF@27..31
IDENT@27..31 "Item"
GENERIC_ARG_LIST@31..35
L_ANGLE@31..32 "<"
LIFETIME_ARG@32..34
LIFETIME@32..34
LIFETIME_IDENT@32..34 "'a"
R_ANGLE@34..35 ">"
WHITESPACE@35..36 " "
EQ@36..37 "="
WHITESPACE@37..38 " "
REF_TYPE@38..43
AMP@38..39 "&"
LIFETIME@39..41
LIFETIME_IDENT@39..41 "'a"
WHITESPACE@41..42 " "
PATH_TYPE@42..43
PATH@42..43
PATH_SEGMENT@42..43
NAME_REF@42..43
IDENT@42..43 "T"
R_ANGLE@43..44 ">"
SEMICOLON@44..45 ";"
WHITESPACE@45..46 "\n"

View File

@ -0,0 +1 @@
type T = StreamingIterator<Item<'a> = &'a T>;

View File

@ -0,0 +1,37 @@
SOURCE_FILE@0..35
STRUCT@0..34
STRUCT_KW@0..6 "struct"
WHITESPACE@6..7 " "
NAME@7..8
IDENT@7..8 "S"
GENERIC_PARAM_LIST@8..33
L_ANGLE@8..9 "<"
CONST_PARAM@9..32
CONST_KW@9..14 "const"
WHITESPACE@14..15 " "
NAME@15..16
IDENT@15..16 "N"
COLON@16..17 ":"
WHITESPACE@17..18 " "
PATH_TYPE@18..21
PATH@18..21
PATH_SEGMENT@18..21
NAME_REF@18..21
IDENT@18..21 "u32"
WHITESPACE@21..22 " "
EQ@22..23 "="
WHITESPACE@23..24 " "
CONST_ARG@24..32
PATH_EXPR@24..32
PATH@24..32
PATH@24..27
PATH_SEGMENT@24..27
NAME_REF@24..27
IDENT@24..27 "u32"
COLON2@27..29 "::"
PATH_SEGMENT@29..32
NAME_REF@29..32
IDENT@29..32 "MAX"
R_ANGLE@32..33 ">"
SEMICOLON@33..34 ";"
WHITESPACE@34..35 "\n"

View File

@ -0,0 +1 @@
struct S<const N: u32 = u32::MAX>;

View File

@ -0,0 +1,27 @@
SOURCE_FILE@0..33
TYPE_ALIAS@0..32
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..31
PATH@9..31
PATH_SEGMENT@9..31
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..31
L_ANGLE@10..11 "<"
CONST_ARG@11..18
LITERAL@11..18
STRING@11..18 "\"hello\""
COMMA@18..19 ","
WHITESPACE@19..20 " "
CONST_ARG@20..30
LITERAL@20..30
INT_NUMBER@20..30 "0xdeadbeef"
R_ANGLE@30..31 ">"
SEMICOLON@31..32 ";"
WHITESPACE@32..33 "\n"

View File

@ -0,0 +1 @@
type T = S<"hello", 0xdeadbeef>;

View File

@ -0,0 +1,25 @@
SOURCE_FILE@0..17
TYPE_ALIAS@0..16
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..15
PATH@9..15
PATH_SEGMENT@9..15
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..15
L_ANGLE@10..11 "<"
TYPE_ARG@11..14
PATH_TYPE@11..14
PATH@11..14
PATH_SEGMENT@11..14
NAME_REF@11..14
IDENT@11..14 "i32"
R_ANGLE@14..15 ">"
SEMICOLON@15..16 ";"
WHITESPACE@16..17 "\n"

View File

@ -0,0 +1 @@
type T = S<i32>;

View File

@ -0,0 +1,24 @@
SOURCE_FILE@0..17
TYPE_ALIAS@0..16
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..15
PATH@9..15
PATH_SEGMENT@9..15
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..15
L_ANGLE@10..11 "<"
CONST_ARG@11..14
PREFIX_EXPR@11..14
MINUS@11..12 "-"
LITERAL@12..14
INT_NUMBER@12..14 "92"
R_ANGLE@14..15 ">"
SEMICOLON@15..16 ";"
WHITESPACE@16..17 "\n"

View File

@ -0,0 +1 @@
type T = S<-92>;

View File

@ -0,0 +1,22 @@
SOURCE_FILE@0..18
TYPE_ALIAS@0..17
TYPE_KW@0..4 "type"
WHITESPACE@4..5 " "
NAME@5..6
IDENT@5..6 "T"
WHITESPACE@6..7 " "
EQ@7..8 "="
WHITESPACE@8..9 " "
PATH_TYPE@9..16
PATH@9..16
PATH_SEGMENT@9..16
NAME_REF@9..10
IDENT@9..10 "S"
GENERIC_ARG_LIST@10..16
L_ANGLE@10..11 "<"
CONST_ARG@11..15
LITERAL@11..15
TRUE_KW@11..15 "true"
R_ANGLE@15..16 ">"
SEMICOLON@16..17 ";"
WHITESPACE@17..18 "\n"

View File

@ -0,0 +1 @@
type T = S<true>;