mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
Fix failing test cases and update error messages for negative and zero inputs
This commit is contained in:
@@ -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);
|
||||
|
@@ -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: /"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/;
|
||||
|
@@ -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;
|
Reference in New Issue
Block a user