| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { Pie } from '../src/language/index.js'; |
| 4 | import { expectNoErrorsOrAlternatives, pieParse as parse } from './test-util.js'; |
| 5 | |
| 6 | describe('pie', () => { |
| 7 | describe('should handle pie definition with or without showData', () => { |
| 8 | it.each([ |
| 9 | `pie`, |
| 10 | ` pie `, |
| 11 | `\tpie\t`, |
| 12 | ` |
| 13 | \tpie |
| 14 | `, |
| 15 | ])('should handle regular pie', (context: string) => { |
| 16 | const result = parse(context); |
| 17 | expectNoErrorsOrAlternatives(result); |
| 18 | expect(result.value.$type).toBe(Pie.$type); |
| 19 | }); |
| 20 | |
| 21 | it.each([ |
| 22 | `pie showData`, |
| 23 | ` pie showData `, |
| 24 | `\tpie\tshowData\t`, |
| 25 | ` |
| 26 | pie\tshowData |
| 27 | `, |
| 28 | ])('should handle regular showData', (context: string) => { |
| 29 | const result = parse(context); |
| 30 | expectNoErrorsOrAlternatives(result); |
| 31 | expect(result.value.$type).toBe(Pie.$type); |
| 32 | |
| 33 | const { showData } = result.value; |
| 34 | expect(showData).toBeTruthy(); |
| 35 | }); |
| 36 | }); |
| 37 | describe('should handle TitleAndAccessibilities', () => { |
| 38 | describe('should handle TitleAndAccessibilities without showData', () => { |
| 39 | it.each([ |
| 40 | `pie title sample title`, |
| 41 | ` pie title sample title `, |
| 42 | `\tpie\ttitle sample title\t`, |
| 43 | `pie |
| 44 | \ttitle sample title |
| 45 | `, |
| 46 | ])('should handle regular pie + title in same line', (context: string) => { |
| 47 | const result = parse(context); |
| 48 | expectNoErrorsOrAlternatives(result); |
| 49 | expect(result.value.$type).toBe(Pie.$type); |
| 50 | |
| 51 | const { title } = result.value; |
| 52 | expect(title).toBe('sample title'); |
| 53 | }); |
| 54 | |
| 55 | it.each([ |
| 56 | `pie |
| 57 | title sample title`, |
| 58 | `pie |
| 59 | title sample title |
| 60 | `, |
| 61 | `pie |
| 62 | title sample title`, |
| 63 | `pie |
| 64 | title sample title |
| 65 | `, |
| 66 | ])('should handle regular pie + title in different line', (context: string) => { |
| 67 | const result = parse(context); |
| 68 | expectNoErrorsOrAlternatives(result); |
| 69 | expect(result.value.$type).toBe(Pie.$type); |
| 70 | |
| 71 | const { title } = result.value; |
| 72 | expect(title).toBe('sample title'); |
| 73 | }); |
| 74 | }); |
| 75 | |
| 76 | describe('should handle TitleAndAccessibilities with showData', () => { |
| 77 | it.each([ |
| 78 | `pie showData title sample title`, |
| 79 | `pie showData title sample title |
| 80 | `, |
| 81 | ])('should handle regular pie + showData + title', (context: string) => { |
| 82 | const result = parse(context); |
| 83 | expectNoErrorsOrAlternatives(result); |
| 84 | expect(result.value.$type).toBe(Pie.$type); |
| 85 | |
| 86 | const { showData, title } = result.value; |
| 87 | expect(showData).toBeTruthy(); |
| 88 | expect(title).toBe('sample title'); |
| 89 | }); |
| 90 | |
| 91 | it.each([ |
| 92 | `pie showData |
| 93 | title sample title`, |
| 94 | `pie showData |
| 95 | title sample title |
| 96 | `, |
| 97 | `pie showData |
| 98 | title sample title`, |
| 99 | `pie showData |
| 100 | title sample title |
| 101 | `, |
| 102 | ])('should handle regular showData + title in different line', (context: string) => { |
| 103 | const result = parse(context); |
| 104 | expectNoErrorsOrAlternatives(result); |
| 105 | expect(result.value.$type).toBe(Pie.$type); |
| 106 | |
| 107 | const { showData, title } = result.value; |
| 108 | expect(showData).toBeTruthy(); |
| 109 | expect(title).toBe('sample title'); |
| 110 | }); |
| 111 | }); |
| 112 | }); |
| 113 | |
| 114 | describe('should handle sections', () => { |
| 115 | it.each([ |
| 116 | `pie |
| 117 | "GitHub":100 |
| 118 | "GitLab":50`, |
| 119 | `pie |
| 120 | "GitHub" : 100 |
| 121 | "GitLab" : 50`, |
| 122 | `pie |
| 123 | "GitHub"\t:\t100 |
| 124 | "GitLab"\t:\t50`, |
| 125 | `pie |
| 126 | \t"GitHub" \t : \t 100 |
| 127 | \t"GitLab" \t : \t 50 |
| 128 | `, |
| 129 | ])('should handle regular sections', (context: string) => { |
| 130 | const result = parse(context); |
| 131 | expectNoErrorsOrAlternatives(result); |
| 132 | expect(result.value.$type).toBe(Pie.$type); |
| 133 | |
| 134 | const { sections } = result.value; |
| 135 | expect(sections[0].label).toBe('GitHub'); |
| 136 | expect(sections[0].value).toBe(100); |
| 137 | |
| 138 | expect(sections[1].label).toBe('GitLab'); |
| 139 | expect(sections[1].value).toBe(50); |
| 140 | }); |
| 141 | |
| 142 | it('should handle sections with showData', () => { |
| 143 | const context = `pie showData |
| 144 | "GitHub": 100 |
| 145 | "GitLab": 50`; |
| 146 | const result = parse(context); |
| 147 | expectNoErrorsOrAlternatives(result); |
| 148 | expect(result.value.$type).toBe(Pie.$type); |
| 149 | |
| 150 | const { showData, sections } = result.value; |
| 151 | expect(showData).toBeTruthy(); |
| 152 | |
| 153 | expect(sections[0].label).toBe('GitHub'); |
| 154 | expect(sections[0].value).toBe(100); |
| 155 | |
| 156 | expect(sections[1].label).toBe('GitLab'); |
| 157 | expect(sections[1].value).toBe(50); |
| 158 | }); |
| 159 | |
| 160 | it('should handle sections with title', () => { |
| 161 | const context = `pie title sample wow |
| 162 | "GitHub": 100 |
| 163 | "GitLab": 50`; |
| 164 | const result = parse(context); |
| 165 | expectNoErrorsOrAlternatives(result); |
| 166 | expect(result.value.$type).toBe(Pie.$type); |
| 167 | |
| 168 | const { title, sections } = result.value; |
| 169 | expect(title).toBe('sample wow'); |
| 170 | |
| 171 | expect(sections[0].label).toBe('GitHub'); |
| 172 | expect(sections[0].value).toBe(100); |
| 173 | |
| 174 | expect(sections[1].label).toBe('GitLab'); |
| 175 | expect(sections[1].value).toBe(50); |
| 176 | }); |
| 177 | |
| 178 | it('should handle value with positive decimal', () => { |
| 179 | const context = `pie |
| 180 | "ash": 60.67 |
| 181 | "bat": 40`; |
| 182 | const result = parse(context); |
| 183 | expectNoErrorsOrAlternatives(result); |
| 184 | expect(result.value.$type).toBe(Pie.$type); |
| 185 | |
| 186 | const { sections } = result.value; |
| 187 | expect(sections[0].label).toBe('ash'); |
| 188 | expect(sections[0].value).toBe(60.67); |
| 189 | |
| 190 | expect(sections[1].label).toBe('bat'); |
| 191 | expect(sections[1].value).toBe(40); |
| 192 | }); |
| 193 | |
| 194 | it('should handle sections with accTitle', () => { |
| 195 | const context = `pie accTitle: sample wow |
| 196 | "GitHub": 100 |
| 197 | "GitLab": 50`; |
| 198 | const result = parse(context); |
| 199 | expectNoErrorsOrAlternatives(result); |
| 200 | expect(result.value.$type).toBe(Pie.$type); |
| 201 | |
| 202 | const { accTitle, sections } = result.value; |
| 203 | expect(accTitle).toBe('sample wow'); |
| 204 | |
| 205 | expect(sections[0].label).toBe('GitHub'); |
| 206 | expect(sections[0].value).toBe(100); |
| 207 | |
| 208 | expect(sections[1].label).toBe('GitLab'); |
| 209 | expect(sections[1].value).toBe(50); |
| 210 | }); |
| 211 | |
| 212 | it('should handle sections with single line accDescr', () => { |
| 213 | const context = `pie accDescr: sample wow |
| 214 | "GitHub": 100 |
| 215 | "GitLab": 50`; |
| 216 | const result = parse(context); |
| 217 | expectNoErrorsOrAlternatives(result); |
| 218 | expect(result.value.$type).toBe(Pie.$type); |
| 219 | |
| 220 | const { accDescr, sections } = result.value; |
| 221 | expect(accDescr).toBe('sample wow'); |
| 222 | |
| 223 | expect(sections[0].label).toBe('GitHub'); |
| 224 | expect(sections[0].value).toBe(100); |
| 225 | |
| 226 | expect(sections[1].label).toBe('GitLab'); |
| 227 | expect(sections[1].value).toBe(50); |
| 228 | }); |
| 229 | |
| 230 | it('should handle sections with multi line accDescr', () => { |
| 231 | const context = `pie accDescr { |
| 232 | sample wow |
| 233 | } |
| 234 | "GitHub": 100 |
| 235 | "GitLab": 50`; |
| 236 | const result = parse(context); |
| 237 | expectNoErrorsOrAlternatives(result); |
| 238 | expect(result.value.$type).toBe(Pie.$type); |
| 239 | |
| 240 | const { accDescr, sections } = result.value; |
| 241 | expect(accDescr).toBe('sample wow'); |
| 242 | |
| 243 | expect(sections[0].label).toBe('GitHub'); |
| 244 | expect(sections[0].value).toBe(100); |
| 245 | |
| 246 | expect(sections[1].label).toBe('GitLab'); |
| 247 | expect(sections[1].value).toBe(50); |
| 248 | }); |
| 249 | }); |
| 250 | }); |
| 251 | |