Fix failing test cases and update error messages for negative and zero inputs

This commit is contained in:
darshanr0107
2025-06-16 14:53:09 +05:30
parent 9da6fb39ae
commit 6979aa1013
3 changed files with 9 additions and 11 deletions

View File

@@ -35,15 +35,9 @@ const clear = (): void => {
const addSection = ({ label, value }: D3Section): void => {
if (value <= 0) {
const error: any = new Error(
`Section "${label}" has invalid value: ${value}. Zero and negative values are not allowed in pie charts. All slice values must be > 0`
throw new Error(
`"${label}" has invalid value: ${value}. Zero and negative values are not allowed in pie charts. All slice values must be > 0.`
);
error.hash = {
text: `pie "${label}": ${value}`,
token: `${value}`,
expected: ['a positive number (> 0)'],
};
throw error;
}
if (!sections.has(label)) {
sections.set(label, value);

View File

@@ -17,8 +17,8 @@ terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
terminal FLOAT returns number: /-?[0-9]+\.[0-9]+(?!\.)/;
terminal INT returns number: /-?(0|[1-9][0-9]*)(?!\.)/;
terminal FLOAT returns number: /[0-9]+\.[0-9]+(?!\.)/;
terminal INT returns number: /0|[1-9][0-9]*(?!\.)/;
terminal NUMBER returns number: FLOAT | INT;
terminal STRING returns string: /"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/;

View File

@@ -12,5 +12,9 @@ entry Pie:
;
PieSection:
label=STRING ":" value=NUMBER EOL
label=STRING ":" value=NUMBER_PIE EOL
;
terminal FLOAT_PIE returns number: /-?[0-9]+\.[0-9]+(?!\.)/;
terminal INT_PIE returns number: /-?(0|[1-9][0-9]*)(?!\.)/;
terminal NUMBER_PIE returns number: FLOAT_PIE | INT_PIE;