Skip to content

Commit

Permalink
feat(#3706): use human-readable messages in EoIndentLexerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 20, 2024
1 parent a2310c3 commit fbc883a
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions eo-parser/src/test/java/org/eolang/parser/EoIndentLexerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang.parser;

import java.io.IOException;
import org.antlr.v4.runtime.Token;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -48,76 +49,54 @@ public final class EoIndentLexerTest {

@Test
void emitsTab() throws IOException {
final EoIndentLexer lexer = new EoIndentLexer(
new TextOf("\n ")
);
final EoIndentLexer lexer = new EoIndentLexer(new TextOf("\n "));
lexer.nextToken();
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
"We expect the first token to be a new line, whereas the next token is tab indentation",
lexer.nextToken().getType(),
Matchers.is(
EoParser.TAB
)
Matchers.is(EoParser.TAB)
);
}

@Test
void ensuresGrammarFile() throws IOException {
final EoIndentLexer lexer = new EoIndentLexer(
new TextOf("")
);
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
lexer.getGrammarFileName(),
Matchers.is(
"Eo.g4"
)
"We expect to retrieve the correct grammar file name",
new EoIndentLexer(new TextOf("")).getGrammarFileName(),
Matchers.is("Eo.g4")
);
}

@Test
void emitsTabWhenEmptyLine() throws IOException {
final EoIndentLexer lexer = new EoIndentLexer(
new TextOf("\n\n ")
);
final EoIndentLexer lexer = new EoIndentLexer(new TextOf("\n\n "));
lexer.nextToken();
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
"We expect tab indentation to be emitted right after the first new line symbol",
lexer.nextToken().getType(),
Matchers.is(
EoParser.TAB
)
Matchers.is(EoParser.TAB)
);
}

@Test
void emitsUntab() throws IOException {
final EoIndentLexer lexer = new EoIndentLexer(
new TextOf("\n \n \n")
);
final EoIndentLexer lexer = new EoIndentLexer(new TextOf("\n \n \n"));
lexer.nextToken();
lexer.nextToken();
lexer.nextToken();
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
"We expect untab indentation token to be emitted after the second new line symbol",
lexer.nextToken().getType(),
Matchers.is(
EoParser.UNTAB
)
Matchers.is(EoParser.UNTAB)
);
}

@Test
void readsEmptyString() throws IOException {
final EoIndentLexer lexer = new EoIndentLexer(
new TextOf("")
);
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
lexer.nextToken().getType(),
Matchers.is(
EoParser.EOF
)
"We expect the lexer to return EOF token when the input is empty",
new EoIndentLexer(new TextOf("")).nextToken().getType(),
Matchers.is(EoParser.EOF)
);
}
}

0 comments on commit fbc883a

Please sign in to comment.