From 69d54d263d33cab0a36083037ed05a5ebe07b6cd Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 26 Apr 2020 23:41:53 +0200 Subject: [PATCH] :rotating_light: Add tests --- .../OperatorSpacingTest.fixed.twig | 4 ++ .../OperatorSpacing/OperatorSpacingTest.php | 6 +++ .../OperatorSpacing/OperatorSpacingTest.twig | 4 ++ .../tests/Token/Tokenizer/TokenizerTest.php | 50 +++++++++++++++++++ .../tests/Token/Tokenizer/TokenizerTest5.twig | 2 + 5 files changed, 66 insertions(+) create mode 100644 TwigCS/tests/Token/Tokenizer/TokenizerTest5.twig diff --git a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.fixed.twig b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.fixed.twig index 774cf2b..416fc26 100644 --- a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.fixed.twig +++ b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.fixed.twig @@ -31,3 +31,7 @@ Untouch +-/*%==: {% if a - 2 == -4 %}{% endif %} {{ a in -2..-3 }} {{ "a_#{1 + 1}" }} + +{{ 'array' starts with 'a' }} +{{ 'array' ends with 'a' }} +{{ 'array' matches 'a' }} diff --git a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php index d03954b..f01cf83 100644 --- a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php +++ b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php @@ -57,6 +57,12 @@ public function testSniff(): void [22 => 6], [33 => 10], [33 => 10], + [35 => 13], + [35 => 13], + [36 => 13], + [36 => 13], + [37 => 13], + [37 => 13], ]); } } diff --git a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.twig b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.twig index d4ed624..fa9e3f6 100644 --- a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.twig +++ b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.twig @@ -31,3 +31,7 @@ Untouch +-/*%==: {% if a - 2 == -4 %}{% endif %} {{ a in -2..-3 }} {{ "a_#{1+1}" }} + +{{ 'array' starts with 'a' }} +{{ 'array' ends with 'a' }} +{{ 'array' matches 'a' }} diff --git a/TwigCS/tests/Token/Tokenizer/TokenizerTest.php b/TwigCS/tests/Token/Tokenizer/TokenizerTest.php index 4e01343..5b4e89b 100644 --- a/TwigCS/tests/Token/Tokenizer/TokenizerTest.php +++ b/TwigCS/tests/Token/Tokenizer/TokenizerTest.php @@ -226,6 +226,56 @@ public function tokenizeDataProvider(): array 32 => Token::EOF_TYPE, ], ], + [ + __DIR__.'/TokenizerTest5.twig', + [ + 0 => Token::BLOCK_START_TYPE, + 1 => Token::WHITESPACE_TYPE, + 2 => Token::BLOCK_TAG_TYPE, + 3 => Token::WHITESPACE_TYPE, + 4 => Token::NAME_TYPE, + 5 => Token::WHITESPACE_TYPE, + 6 => Token::OPERATOR_TYPE, + 7 => Token::WHITESPACE_TYPE, + 8 => Token::NAME_TYPE, + 9 => Token::WHITESPACE_TYPE, + 10 => Token::NAME_TYPE, + 11 => Token::PUNCTUATION_TYPE, + 12 => Token::NAME_TYPE, + 13 => Token::PUNCTUATION_TYPE, + 14 => Token::WHITESPACE_TYPE, + 15 => Token::BLOCK_END_TYPE, + 16 => Token::BLOCK_START_TYPE, + 17 => Token::WHITESPACE_TYPE, + 18 => Token::BLOCK_TAG_TYPE, + 19 => Token::WHITESPACE_TYPE, + 20 => Token::BLOCK_END_TYPE, + 21 => Token::EOL_TYPE, + 22 => Token::BLOCK_START_TYPE, + 23 => Token::WHITESPACE_TYPE, + 24 => Token::BLOCK_TAG_TYPE, + 25 => Token::WHITESPACE_TYPE, + 26 => Token::NAME_TYPE, + 27 => Token::WHITESPACE_TYPE, + 28 => Token::OPERATOR_TYPE, + 29 => Token::WHITESPACE_TYPE, + 30 => Token::NAME_TYPE, + 31 => Token::WHITESPACE_TYPE, + 32 => Token::NAME_TYPE, + 33 => Token::PUNCTUATION_TYPE, + 34 => Token::NAME_TYPE, + 35 => Token::PUNCTUATION_TYPE, + 36 => Token::WHITESPACE_TYPE, + 37 => Token::BLOCK_END_TYPE, + 38 => Token::BLOCK_START_TYPE, + 39 => Token::WHITESPACE_TYPE, + 40 => Token::BLOCK_TAG_TYPE, + 41 => Token::WHITESPACE_TYPE, + 42 => Token::BLOCK_END_TYPE, + 43 => Token::EOL_TYPE, + 44 => Token::EOF_TYPE, + ], + ], ]; } } diff --git a/TwigCS/tests/Token/Tokenizer/TokenizerTest5.twig b/TwigCS/tests/Token/Tokenizer/TokenizerTest5.twig new file mode 100644 index 0000000..e8abd45 --- /dev/null +++ b/TwigCS/tests/Token/Tokenizer/TokenizerTest5.twig @@ -0,0 +1,2 @@ +{% if foo is same as(bar) %}{% endif %} +{% if foo is divisible by(bar) %}{% endif %}