Skip to content

Commit

Permalink
Add codecov configurations for codecov yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Aug 1, 2024
1 parent 9ce93c4 commit d7ee80f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
fixes:
- "ballerina/data.csv/**/::../ballerina/"

ignore:
- "ballerina-tests"
- "test-utils"

coverage:
precision: 2
round: down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* @since 0.1.0
*/
public final class CsvParser {

private static final char CR = 0x000D;
private static final char HZ_TAB = 0x0009;
private static final char SPACE = 0x0020;
Expand Down Expand Up @@ -102,6 +103,7 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config)
*/

static class StateMachine {

private static final State HEADER_START_STATE = new HeaderStartState();
private static final State HEADER_END_STATE = new HeaderEndState();
private static final State ROW_START_STATE = new RowStartState();
Expand All @@ -112,9 +114,6 @@ static class StateMachine {
private static final State HEADER_ESCAPE_CHAR_STATE = new HeaderEscapedCharacterProcessingState();
private static final State STRING_QUOTE_CHAR_STATE = new StringQuoteValueState();
private static final State HEADER_QUOTE_CHAR_STATE = new HeaderQuoteValueState();



private static final char LINE_BREAK = '\n';

Object currentCsvNode;
Expand Down Expand Up @@ -298,7 +297,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp
currentState = currentState.transition(this, buff, this.index, count);
}
}
currentState = currentState.transition(this, new char[] { EOF }, 0, 1);
currentState = currentState.transition(this, new char[]{EOF}, 0, 1);
if (currentState != ROW_END_STATE && currentState != HEADER_END_STATE) {
if (!this.isHeaderConfigExceedLineNumber) {
throw new CsvParserException("Invalid token found");
Expand All @@ -310,7 +309,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp
}
}

private void addFieldNamesForNonHeaderState() {
private void addFieldNamesForNonHeaderState() {
this.fieldNames.putAll(this.fieldHierarchy);
}

Expand Down Expand Up @@ -339,13 +338,15 @@ private void growCharBuff() {
* A specific state in the CSV parsing state machine.
*/
interface State {

State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException;
}

/**
* Represents the CSV header start state.
*/
private static class HeaderStartState implements State {

@Override
public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException {
char ch;
Expand Down Expand Up @@ -511,6 +512,7 @@ private static void addHeader(StateMachine sm, boolean trim) {
* Represents the CSV header end state.
*/
private static class HeaderEndState implements State {

@Override
public State transition(StateMachine sm, char[] buff, int i, int count) {
return ROW_START_STATE;
Expand All @@ -521,6 +523,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) {
* Represents the CSV row start state.
*/
private static class RowStartState implements State {

char ch;
State state = ROW_START_STATE;

Expand Down Expand Up @@ -650,7 +653,7 @@ private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm)
}

private static boolean ignoreRow(long[] skipLines, int lineNumber) {
for (long skipLine: skipLines) {
for (long skipLine : skipLines) {
if (skipLine == lineNumber) {
return true;
}
Expand Down Expand Up @@ -765,6 +768,7 @@ private static Field getCurrentField(StateMachine sm) {
* Represents the CSV row end state.
*/
private static class RowEndState implements State {

@Override
public State transition(StateMachine sm, char[] buff, int i, int count) {
return ROW_END_STATE;
Expand Down Expand Up @@ -838,7 +842,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count)
return state;
}
}

/**
* Represents the CSV header value with quote state.
*/
Expand Down Expand Up @@ -903,8 +907,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count)
}

/**
* Represents the state where an escaped unicode character in hex format is processed
* from a row value.
* Represents the state where an escaped unicode character in hex format is processed from a row value.
*/
private static class StringValueUnicodeHexProcessingState extends UnicodeHexProcessingState {

Expand All @@ -916,8 +919,7 @@ protected State getSourceState() {
}

/**
* Represents the state where an escaped unicode character in hex format is processed
* from a header name.
* Represents the state where an escaped unicode character in hex format is processed from a header name.
*/
private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessingState {

Expand Down Expand Up @@ -1012,6 +1014,7 @@ protected State getSourceState() {
* Represents the state where an escaped character is processed in a header or row value.
*/
private abstract static class EscapedCharacterProcessingState implements State {

static final Map<Character, Character> ESCAPE_CHAR_MAP = Map.of(DOUBLE_QUOTES_CHAR, QUOTES,
BACKSLASH_CHAR, REV_SOL, SLASH_CHAR, SOL, BACKSPACE_CHAR, BACKSPACE, FORM_FEED_CHAR,
FORMFEED, NEWLINE_CHAR, NEWLINE, CARRIAGE_RETURN_CHAR, CR, TAB_CHAR, HZ_TAB);
Expand Down Expand Up @@ -1077,6 +1080,7 @@ public static boolean isEndOfTheHeaderRow(CsvParser.StateMachine sm, char ch) {
}

public static class CsvParserException extends Exception {

public CsvParserException(String msg) {
super(msg);
}
Expand Down

0 comments on commit d7ee80f

Please sign in to comment.