Skip to content

Commit 331cff7

Browse files
committed
Abbreviate compiler directive lexing tests using consts
1 parent b471cf8 commit 331cff7

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

core/src/defaults/lexer.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,15 @@ mod tests {
13761376
);
13771377
}
13781378

1379+
const IF_DIRECTIVE: TT = TT::ConditionalDirective(CDK::If);
1380+
const IFDEF_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Ifdef);
1381+
const IFNDEF_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Ifndef);
1382+
const IFOPT_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Ifopt);
1383+
const ELSEIF_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Elseif);
1384+
const ELSE_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Else);
1385+
const IFEND_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Ifend);
1386+
const ENDIF_DIRECTIVE: TT = TT::ConditionalDirective(CDK::Endif);
1387+
13791388
#[test]
13801389
fn lex_compiler_directives() {
13811390
run_test(
@@ -1387,34 +1396,22 @@ mod tests {
13871396
],
13881397
);
13891398
[
1390-
(
1391-
"{$if}",
1392-
TT::ConditionalDirective(ConditionalDirectiveKind::If),
1393-
),
1394-
("{$ifdef}", TT::ConditionalDirective(CDK::Ifdef)),
1395-
("{$ifndef}", TT::ConditionalDirective(CDK::Ifndef)),
1396-
("{$ifopt}", TT::ConditionalDirective(CDK::Ifopt)),
1397-
("{$elseif}", TT::ConditionalDirective(CDK::Elseif)),
1398-
(
1399-
"{$else}",
1400-
TT::ConditionalDirective(ConditionalDirectiveKind::Else),
1401-
),
1402-
("{$ifend}", TT::ConditionalDirective(CDK::Ifend)),
1403-
("{$endif}", TT::ConditionalDirective(CDK::Endif)),
1404-
(
1405-
"(*$if*)",
1406-
TT::ConditionalDirective(ConditionalDirectiveKind::If),
1407-
),
1408-
("(*$ifdef*)", TT::ConditionalDirective(CDK::Ifdef)),
1409-
("(*$ifndef*)", TT::ConditionalDirective(CDK::Ifndef)),
1410-
("(*$ifopt*)", TT::ConditionalDirective(CDK::Ifopt)),
1411-
("(*$elseif*)", TT::ConditionalDirective(CDK::Elseif)),
1412-
(
1413-
"(*$else*)",
1414-
TT::ConditionalDirective(ConditionalDirectiveKind::Else),
1415-
),
1416-
("(*$ifend*)", TT::ConditionalDirective(CDK::Ifend)),
1417-
("(*$endif*)", TT::ConditionalDirective(CDK::Endif)),
1399+
("{$if}", IF_DIRECTIVE),
1400+
("{$ifdef}", IFDEF_DIRECTIVE),
1401+
("{$ifndef}", IFNDEF_DIRECTIVE),
1402+
("{$ifopt}", IFOPT_DIRECTIVE),
1403+
("{$elseif}", ELSEIF_DIRECTIVE),
1404+
("{$else}", ELSE_DIRECTIVE),
1405+
("{$ifend}", IFEND_DIRECTIVE),
1406+
("{$endif}", ENDIF_DIRECTIVE),
1407+
("(*$if*)", IF_DIRECTIVE),
1408+
("(*$ifdef*)", IFDEF_DIRECTIVE),
1409+
("(*$ifndef*)", IFNDEF_DIRECTIVE),
1410+
("(*$ifopt*)", IFOPT_DIRECTIVE),
1411+
("(*$elseif*)", ELSEIF_DIRECTIVE),
1412+
("(*$else*)", ELSE_DIRECTIVE),
1413+
("(*$ifend*)", IFEND_DIRECTIVE),
1414+
("(*$endif*)", ENDIF_DIRECTIVE),
14181415
]
14191416
.into_iter()
14201417
.for_each(run_casing_test);
@@ -1430,10 +1427,7 @@ mod tests {
14301427
14311428
"
14321429
},
1433-
&[(
1434-
"{$if\n// other comment\nFoo;",
1435-
TT::ConditionalDirective(ConditionalDirectiveKind::If),
1436-
)],
1430+
&[("{$if\n// other comment\nFoo;", IF_DIRECTIVE)],
14371431
);
14381432
run_test(
14391433
indoc! {"
@@ -1443,10 +1437,7 @@ mod tests {
14431437
14441438
"
14451439
},
1446-
&[(
1447-
"(*$if\n// other comment\nFoo;",
1448-
TT::ConditionalDirective(ConditionalDirectiveKind::If),
1449-
)],
1440+
&[("(*$if\n// other comment\nFoo;", IF_DIRECTIVE)],
14501441
);
14511442
}
14521443

@@ -2041,7 +2032,7 @@ mod tests {
20412032
("RBX", TT::Identifier),
20422033
(",", TT::Op(OK::Comma)),
20432034
("RBX", TT::Identifier),
2044-
("{$ifdef End}", TT::ConditionalDirective(CDK::Ifdef)),
2035+
("{$ifdef End}", IFDEF_DIRECTIVE),
20452036
("end", TT::Keyword(KK::End)),
20462037
],
20472038
);

0 commit comments

Comments
 (0)