File tree Expand file tree Collapse file tree 5 files changed +18
-6
lines changed
src/Languages/Dockerfile/Patterns
tests/Languages/Dockerfile/Patterns Expand file tree Collapse file tree 5 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 1212#[PatternTest(input: 'FROM php ' , output: null )]
1313#[PatternTest(input: 'FROM php:8.1 ' , output: null )]
1414#[PatternTest(input: 'FROM php:8.1 AS stage-one ' , output: 'AS ' )]
15+ #[PatternTest(input: ' FROM php:8.1 AS stage-one ' , output: 'AS ' )]
1516final readonly class ImageAliasKeywordPattern implements Pattern
1617{
1718 use IsPattern;
1819
1920 public function getPattern (): string
2021 {
21- return "^ FROM[\s][\S]+[\s](?<match>AS)[\s][\S]+ " ;
22+ return "/^[\s]* FROM[\s][\S]+[\s](?<match>AS)[\s][\S]+/m " ;
2223 }
2324
2425 public function getTokenType (): TokenTypeEnum
Original file line number Diff line number Diff line change 1212#[PatternTest(input: 'FROM php ' , output: null )]
1313#[PatternTest(input: 'FROM php:8.1 ' , output: null )]
1414#[PatternTest(input: 'FROM php:8.1 AS stage-one ' , output: 'stage-one ' )]
15+ #[PatternTest(input: ' FROM php:8.1 AS stage-one ' , output: 'stage-one ' )]
1516final readonly class ImageAliasNamePattern implements Pattern
1617{
1718 use IsPattern;
1819
1920 public function getPattern (): string
2021 {
21- return "^ FROM[\s][\S]+[\s]AS[\s](?<match>[\S]+) " ;
22+ return "/^[\s]* FROM[\s][\S]+[\s]AS[\s](?<match>[\S]+)/m " ;
2223 }
2324
2425 public function getTokenType (): TokenTypeEnum
Original file line number Diff line number Diff line change 1010use Tempest \Highlight \Tokens \TokenTypeEnum ;
1111
1212#[PatternTest(input: 'FROM php ' , output: 'php ' )]
13+ #[PatternTest(input: ' FROM php ' , output: 'php ' )]
1314#[PatternTest(input: 'FROM php:8.1 ' , output: 'php ' )]
1415#[PatternTest(input: 'FROM php:8.1 AS stage-one ' , output: 'php ' )]
1516final readonly class ImageNamePattern implements Pattern
1819
1920 public function getPattern (): string
2021 {
21- return "^ FROM (?<match>[\w]+) " ;
22+ return "/^[\s]* FROM[\s] (?<match>[\w]+)/m " ;
2223 }
2324
2425 public function getTokenType (): TokenTypeEnum
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public function __construct(private string $keyword)
1818
1919 public function getPattern (): string
2020 {
21- return "^ (?<match> {$ this ->keyword })[\s].* " ;
21+ return "/^[\s]* (?<match> {$ this ->keyword })[\s].*/m " ;
2222 }
2323
2424 public function getTokenType (): TokenTypeEnum
Original file line number Diff line number Diff line change @@ -28,8 +28,17 @@ public function test_pattern()
2828
2929 $ this ->assertMatches (
3030 pattern: new KeywordPattern ('FROM ' ),
31- content: 'RUN some command with FROM in it ' ,
32- expected: null ,
31+ content: ' FROM image:tag AS alias ' ,
32+ expected: 'FROM ' ,
33+ );
34+
35+ $ this ->assertMatches (
36+ pattern: new KeywordPattern ('COPY ' ),
37+ content: <<<'DOCKERFILE'
38+ FROM image:tag
39+ COPY . /usr/share/nginx/html
40+ DOCKERFILE,
41+ expected: 'COPY ' ,
3342 );
3443 }
3544}
You can’t perform that action at this time.
0 commit comments