Best Gherkin-php code snippet using StringGherkinLine.indent
TokenMatcherTest.php
Source:TokenMatcherTest.php
...155 {156 $token = $this->createTokenWithContents(' # This is a comment');157 self::assertTrue($this->tokenMatcher->match_Comment($token));158 self::assertSame(TokenType::Comment, $token->match?->tokenType);159 self::assertSame(0, $token->match?->indent);160 }161 public function testItDoesNotMatchDocstringSeparatorIfNoSeparatorIsThere(): void162 {163 $token = $this->createNonMatchingToken();164 self::assertFalse($this->tokenMatcher->match_DocStringSeparator($token));165 self::assertNull($token->match);166 }167 public function testItMatchesRegularDocstringSeparator(): void168 {169 $token = $this->createTokenWithContents(' """json');170 self::assertTrue($this->tokenMatcher->match_DocStringSeparator($token));171 self::assertSame(TokenType::DocStringSeparator, $token->match?->tokenType);172 self::assertSame('json', $token->match?->text);173 self::assertSame('"""', $token->match?->keyword);174 }175 public function testItMatchesAlternativeDocstringSeparator(): void176 {177 $token = $this->createTokenWithContents(' ```json');178 self::assertTrue($this->tokenMatcher->match_DocStringSeparator($token));179 self::assertSame(TokenType::DocStringSeparator, $token->match?->tokenType);180 self::assertSame('json', $token->match?->text);181 self::assertSame('```', $token->match?->keyword);182 }183 public function testItMatchesClosingRegularDocstringSeparator(): void184 {185 $prevToken = $this->createTokenWithContents(' """json');186 $this->tokenMatcher->match_DocStringSeparator($prevToken);187 $token = $this->createTokenWithContents(' """json');188 self::assertTrue($this->tokenMatcher->match_DocStringSeparator($token));189 self::assertSame(TokenType::DocStringSeparator, $token->match?->tokenType);190 self::assertSame('', $token->match?->text);191 self::assertSame('"""', $token->match?->keyword);192 }193 public function testItDoesNotMatchMismatchedClosingDocstringSeparator(): void194 {195 $prevToken = $this->createTokenWithContents(' ```json');196 $this->tokenMatcher->match_DocStringSeparator($prevToken);197 $token = $this->createTokenWithContents(' """json');198 self::assertFalse($this->tokenMatcher->match_DocStringSeparator($token));199 self::assertNull($token->match);200 }201 public function testItMatchesClosingAlternativeDocstringSeparator(): void202 {203 $prevToken = $this->createTokenWithContents(' ```json');204 $this->tokenMatcher->match_DocStringSeparator($prevToken);205 $token = $this->createTokenWithContents(' ```json');206 self::assertTrue($this->tokenMatcher->match_DocStringSeparator($token));207 self::assertSame(TokenType::DocStringSeparator, $token->match?->tokenType);208 self::assertSame('', $token->match?->text);209 self::assertSame('```', $token->match?->keyword);210 }211 public function testItMatchesOtherPreservingIndent(): void212 {213 $token = $this->createTokenWithContents(' Arbitrary text');214 self::assertTrue($this->tokenMatcher->match_Other($token));215 self::assertSame(TokenType::Other, $token->match?->tokenType);216 self::assertSame(' Arbitrary text', $token->match?->text);217 self::assertSame(0, $token->match?->indent);218 }219 public function testItMatchesOtherWithIndentRemovedInsideDocstring(): void220 {221 $prevToken = $this->createTokenWithContents(' ```');222 $this->tokenMatcher->match_DocStringSeparator($prevToken);223 $token = $this->createTokenWithContents(' Arbitrary text');224 self::assertTrue($this->tokenMatcher->match_Other($token));225 self::assertSame(TokenType::Other, $token->match?->tokenType);226 self::assertSame('Arbitrary text', $token->match?->text);227 self::assertSame(0, $token->match?->indent);228 }229 public function testItUnescapesAlternativeDocstringSeparatorInsideDocstring(): void230 {231 $prevToken = $this->createTokenWithContents(' ```');232 $this->tokenMatcher->match_DocStringSeparator($prevToken);233 $token = $this->createTokenWithContents(' \\`\\`\\`');234 self::assertTrue($this->tokenMatcher->match_Other($token));235 self::assertSame(TokenType::Other, $token->match?->tokenType);236 self::assertSame('```', $token->match?->text);237 self::assertSame(0, $token->match?->indent);238 }239 public function testItUnescapesRegularDocstringSeparatorInsideDocstring(): void240 {241 $prevToken = $this->createTokenWithContents(' """');242 $this->tokenMatcher->match_DocStringSeparator($prevToken);243 $token = $this->createTokenWithContents(' \\"\\"\\"');244 self::assertTrue($this->tokenMatcher->match_Other($token));245 self::assertSame(TokenType::Other, $token->match?->tokenType);246 self::assertSame('"""', $token->match?->text);247 self::assertSame(0, $token->match?->indent);248 }249 public function testItDoesNotMatchTagsWhenLineDoesNotStartWithAt(): void250 {251 $token = $this->createNonMatchingToken();252 self::assertFalse($this->tokenMatcher->match_TagLine($token));253 self::assertNull($token->match);254 }255 public function testItMatchesTagLine(): void256 {257 $token = $this->createTokenWithContents(' @foo @bar');258 self::assertTrue($this->tokenMatcher->match_TagLine($token));259 self::assertSame(TokenType::TagLine, $token->match?->tokenType);260 self::assertEquals(261 [...
StringGherkinLine.php
Source:StringGherkinLine.php
...8 /**9 * Splits a string around | char, only if it's not preceded by an odd number of \10 */11 private const CELL_PATTERN = '/(?<!\\\\)(?:\\\\{2})*\K\\|/u';12 private readonly int $indent;13 private readonly string $trimmedLineText;14 public function __construct(15 private readonly string $lineText,16 private readonly int $line,17 ) {18 $this->trimmedLineText = StringUtils::trim($this->lineText);19 $this->indent = StringUtils::symbolCount($lineText) - StringUtils::symbolCount(StringUtils::ltrim($lineText));20 }21 public function indent(): int22 {23 return $this->indent;24 }25 public function getLineText(int $indentToRemove): string26 {27 if ($indentToRemove < 0 || $indentToRemove > $this->indent) {28 return $this->trimmedLineText;29 }30 return StringUtils::substring($this->lineText, $indentToRemove);31 }32 /** @param non-empty-string $keyword */33 public function startsWithTitleKeyword(string $keyword): bool34 {35 $textLength = StringUtils::symbolCount($keyword);36 return StringUtils::symbolCount($this->trimmedLineText) > $textLength37 && StringUtils::startsWith($this->trimmedLineText, $keyword)38 && StringUtils::subString(39 $this->trimmedLineText,40 $textLength,41 StringUtils::symbolCount(GherkinLanguageConstants::TITLE_KEYWORD_SEPARATOR),42 ) === GherkinLanguageConstants::TITLE_KEYWORD_SEPARATOR;43 }44 public function getRestTrimmed(int $length): string45 {46 return StringUtils::trim(StringUtils::substring($this->trimmedLineText, $length));47 }48 public function isEmpty(): bool49 {50 return StringUtils::symbolCount($this->trimmedLineText) === 0;51 }52 public function startsWith(string $string): bool53 {54 return StringUtils::startsWith($this->trimmedLineText, $string);55 }56 /** @return list<GherkinLineSpan> */57 public function getTableCells(): array58 {59 /**60 * @var list<array{0:string, 1:int}> $splitCells guaranteed by PREG_SPLIT_OFFSET_CAPTURE61 */62 $splitCells = preg_split(self::CELL_PATTERN, $this->lineText, flags: PREG_SPLIT_OFFSET_CAPTURE);63 // Safely remove elements before the first and last separators64 array_shift($splitCells);65 array_pop($splitCells);66 return array_map(67 function ($match) {68 [$cell, $byteOffset] = $match;69 // substr to chop at the byte boundary, then count the chars70 $cellStart = StringUtils::symbolCount(substr($this->lineText, 0, $byteOffset));71 $leftTrimmedCell = StringUtils::ltrimKeepNewLines($cell);72 $cellIndent = StringUtils::symbolCount($cell) - StringUtils::symbolCount($leftTrimmedCell);73 $trimmedCell = StringUtils::rtrimKeepNewLines($leftTrimmedCell);74 // Match \N and then replace based on what X is75 // done this way so that \\n => \n once and isn't then recursively replaced again (or similar)76 $unescaped = preg_replace_callback(77 '/(\\\\.)/u',78 function ($groups) {79 return match ($groups[0]) {80 '\\n' => "\n",81 '\\\\' => '\\',82 '\\|' => '|',83 default => $groups[0],84 };85 },86 $trimmedCell,87 );88 return new GherkinLineSpan($cellStart + $cellIndent + self::OFFSET, $unescaped);89 },90 $splitCells,91 );92 }93 /** @return list<GherkinLineSpan> */94 public function getTags(): array95 {96 $uncommentedLine = preg_replace('/\s' . preg_quote(GherkinLanguageConstants::COMMENT_PREFIX) . '.*$/u', '', $this->trimmedLineText);97 /**98 * @var list<array{0:string, 1:int}> $elements guaranteed by PREG_SPLIT_OFFSET_CAPTURE99 */100 $elements = preg_split('/' . preg_quote(GherkinLanguageConstants::TAG_PREFIX) . '/u', $uncommentedLine, flags: PREG_SPLIT_OFFSET_CAPTURE);101 // Skip before the first tag prefix102 array_shift($elements);103 return array_values(array_filter(array_map(104 function ($element) {105 $token = StringUtils::rtrim($element[0]);106 $column = $this->indent + $element[1];107 if (StringUtils::symbolCount($token) > 0) {108 if (preg_match('/\s+/u', $token)) {109 throw new ParserException("A tag may not contain whitespace", new Location($this->line, $column));110 }111 return new GherkinLineSpan($column, GherkinLanguageConstants::TAG_PREFIX . $token);112 }113 },114 $elements,115 )));116 }117}...
StringGherkinLineTest.php
Source:StringGherkinLineTest.php
...6{7 public function testIndentIsZeroIfLineIsNotIndented(): void8 {9 $line = new StringGherkinLine('HELLOWORLD', 1);10 self::assertSame(0, $line->indent());11 }12 public function testIndentIsSameAsWhitespaceAtStartOfLine(): void13 {14 $line = new StringGherkinLine(' HELLOWORLD', 1);15 self::assertSame(4, $line->indent());16 }17 public function testItGetsLineTextWithSpecifiedIndentRemoved(): void18 {19 $line = new StringGherkinLine(' HELLOWORLD', 1);20 self::assertSame(' HELLOWORLD', $line->getLineText(2));21 }22 public function testItGetsLineTextWithNoIndentWhenCalledWithNegativeNumber(): void23 {24 $line = new StringGherkinLine(' HELLOWORLD', 1);25 self::assertSame('HELLOWORLD', $line->getLineText(-1));26 }27 public function testItGetsLineTextWithNoIndentWhenCalledWithTooBigIndent(): void28 {29 $line = new StringGherkinLine(' HELLOWORLD', 1);...
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine($line, $lineNumber);2$gherkinLine->indent();3$gherkinLine = new StringGherkinLine($line, $lineNumber);4$gherkinLine->getLineText();5$gherkinLine = new StringGherkinLine($line, $lineNumber);6$gherkinLine->getLineText();7$gherkinLine = new StringGherkinLine($line, $lineNumber);8$gherkinLine->getLineText();9$gherkinLine = new StringGherkinLine($line, $lineNumber);10$gherkinLine->getLineText();11$gherkinLine = new StringGherkinLine($line, $lineNumber);12$gherkinLine->getLineText();13$gherkinLine = new StringGherkinLine($line, $lineNumber);14$gherkinLine->getLineText();15$gherkinLine = new StringGherkinLine($line, $lineNumber);16$gherkinLine->getLineText();17$gherkinLine = new StringGherkinLine($line, $lineNumber);18$gherkinLine->getLineText();19$gherkinLine = new StringGherkinLine($line, $lineNumber);20$gherkinLine->getLineText();
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);2$gherkinLine->indent();3echo $gherkinLine->getLineText();4$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);5$gherkinLine->outdent();6echo $gherkinLine->getLineText();7$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);8echo $gherkinLine->getLineText();9$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);10echo $gherkinLine->getLineText();11$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);12echo $gherkinLine->getLineText();13$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);14echo $gherkinLine->getLineText();15$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);16echo $gherkinLine->getLineText();17$gherkinLine = new StringGherkinLine('Given I am on the home page', 1);18echo $gherkinLine->getLineText();19$gherkinLine = new StringGherkinLine('Given I am on the
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);2echo $gherkinLine->indent();3$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);4echo $gherkinLine->asString();5$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);6echo $gherkinLine->getLineText();7$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);8echo $gherkinLine->getLineText();9$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);10echo $gherkinLine->getLineText();11$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);12echo $gherkinLine->getLineText();13$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);14echo $gherkinLine->getLineText();15$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers", 1);16echo $gherkinLine->getLineText();17$gherkinLine = new StringGherkinLine(" Given I have 2 cucumbers",
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);2$gherkinLine->indent(4);3$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);4$gherkinLine->indent(4);5$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);6$gherkinLine->indent(4);7$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);8$gherkinLine->indent(4);9$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);10$gherkinLine->indent(4);11$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);12$gherkinLine->indent(4);13$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);14$gherkinLine->indent(4);15$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);16$gherkinLine->indent(4);17$gherkinLine = new StringGherkinLine("Given I am on the homepage", 1);18$gherkinLine->indent(4);
indent
Using AI Code Generation
1$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);2$line->indent(2);3echo $line->getLineText();4$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);5$line->dedent(2);6echo $line->getLineText();7$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);8echo $line->getLineText();9$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);10echo $line->getLineTextTrimmed();11$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);12echo $line->getLineTextTrimmed();13$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);14echo $line->getLineText();15$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);16echo $line->getLineTextTrimmed();17$line = new StringGherkinLine("Given I have 4 cukes in my belly", 1);
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine(' * a list item', 1);2$gherkinLine->indent(2);3$gherkinLine = new StringGherkinLine(' * a list item', 1);4$gherkinLine->dedent(2);5$gherkinLine = new StringGherkinLine(' * a list item', 1);6$gherkinLine = new StringGherkinLine(' * a list item', 1);7$gherkinLine = new StringGherkinLine(' * a list item', 1);8$gherkinLine = new StringGherkinLine(' * a list item', 1);9$gherkinLine = new StringGherkinLine(' * a list item', 1);10$gherkinLine = new StringGherkinLine(' * a list item', 1);
indent
Using AI Code Generation
1$line = new StringGherkinLine("Given I am on the homepage", 1);2$line->indent(2);3echo $line->getLineText();4$line = new StringGherkinLine(" Given I am on the homepage", 1);5$line->dedent(2);6echo $line->getLineText();7$line = new GherkinLine("Given I am on the homepage", 1);8echo $line->getLineText();
indent
Using AI Code Generation
1$gherkinLine = new StringGherkinLine("Hello World", 1);2$gherkinLine->indent(2);3$gherkinLine = new StringGherkinLine("Hello World", 1);4$gherkinLine->unindent(2);5$gherkinLine = new StringGherkinLine("Hello World", 1);6$gherkinLine->getLineText();7$gherkinLine = new StringGherkinLine("Hello World", 1);8$gherkinLine->getLineText();9$gherkinLine = new StringGherkinLine("Hello World", 1);10$gherkinLine->getLineText();11$gherkinLine = new StringGherkinLine("Hello World", 1);12$gherkinLine->getLineText();13$gherkinLine = new StringGherkinLine("Hello World", 1);14$gherkinLine->getLineText();15$gherkinLine = new StringGherkinLine("Hello World", 1);16$gherkinLine->getLineText();17$gherkinLine = new StringGherkinLine("Hello World", 1);18$gherkinLine->getLineText();19$gherkinLine = new StringGherkinLine("Hello World", 1);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with indent on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!