Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The grammar file Directives.g4 defines the following tokens:
fragment BYTE_UNIT
: [Bb] // bytes
| [Kk][Bb] // kilobytes
| [Mm][Bb] // megabytes
| [Gg][Bb] // gigabytes
| [Tt][Bb] // terabytes
| [Pp][Bb] // petabytes
;
BYTE_SIZE
: Number BYTE_UNIT
;
fragment TIME_UNIT
: 'ns' // nanoseconds
| 'us' // microseconds
| 'ms' // milliseconds
| 's' // seconds
| 'm' // minutes
| 'h' // hours
| 'd' // days
;
TIME_DURATION
: Number TIME_UNIT
;
The DirectivesLexerTest.java includes comprehensive test cases:
@test
public void testByteSizeTokens() {
String input = "1B 1KB 1MB 1GB 1TB 1PB";
DirectivesLexer lexer = new DirectivesLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
List tokenList = tokens.getTokens();
Assert.assertEquals(6, tokenList.size());
for (Token token : tokenList) {
Assert.assertEquals(DirectivesLexer.BYTE_SIZE, token.getType());
}
}
@test
public void testTimeDurationTokens() {
String input = "1ns 1us 1ms 1s 1m 1h 1d";
DirectivesLexer lexer = new DirectivesLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
List tokenList = tokens.getTokens();
Assert.assertEquals(7, tokenList.size());
for (Token token : tokenList) {
Assert.assertEquals(DirectivesLexer.TIME_DURATION, token.getType());
}
}
Testing
The implementation includes tests for:
Valid byte size tokens (B, KB, MB, GB, TB, PB)
Valid time duration tokens (ns, us, ms, s, m, h, d)
Invalid formats and error handling
Case sensitivity handling
Integration with AggregateStats directive
All test cases are passing, including:
Basic token recognition
Unit conversion
Error handling
Integration tests