diff --git a/packages/mermaid/src/diagrams/class/classTypes.spec.ts b/packages/mermaid/src/diagrams/class/classTypes.spec.ts index 1d1ba7b80..b1fa3717f 100644 --- a/packages/mermaid/src/diagrams/class/classTypes.spec.ts +++ b/packages/mermaid/src/diagrams/class/classTypes.spec.ts @@ -1,979 +1,95 @@ +import { describe, it, expect } from 'vitest'; import { ClassMember } from './classTypes.js'; -import { vi, describe, it, expect } from 'vitest'; -const spyOn = vi.spyOn; -const staticCssStyle = 'text-decoration:underline;'; -const abstractCssStyle = 'font-style:italic;'; -const abstractStaticCssStyle = 'text-decoration:underline;font-style:italic;'; - -describe('given text representing a method, ', function () { - describe('when method has no parameters', function () { - it('should parse correctly', function () { - const str = `getTime()`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle public visibility', function () { - const str = `+getTime()`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTime()'); - }); - - it('should handle private visibility', function () { - const str = `-getTime()`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTime()'); - }); - - it('should handle protected visibility', function () { - const str = `#getTime()`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTime()'); - }); - - it('should handle internal visibility', function () { - const str = `~getTime()`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTime()'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime()$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime()*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime()*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTime()$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method has single parameter value', function () { - it('should parse correctly', function () { - const str = `getTime(int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle public visibility', function () { - const str = `+getTime(int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTime(int)'); - }); - - it('should handle private visibility', function () { - const str = `-getTime(int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTime(int)'); - }); - - it('should handle protected visibility', function () { - const str = `#getTime(int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTime(int)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTime(int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTime(int)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime(int)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime(int)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime(int)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTime(int)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method has single parameter type and name (type first)', function () { - it('should parse correctly', function () { - const str = `getTime(int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle public visibility', function () { - const str = `+getTime(int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTime(int count)'); - }); - - it('should handle private visibility', function () { - const str = `-getTime(int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTime(int count)'); - }); - - it('should handle protected visibility', function () { - const str = `#getTime(int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTime(int count)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTime(int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTime(int count)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime(int count)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime(int count)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime(int count)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTime(int count)$*`; +describe('ClassTypes - Enhanced Abstract and Static Combinations', () => { + // Test constants to match original test structure + const staticCssStyle = 'text-decoration:underline;'; + const abstractCssStyle = 'font-style:italic;'; + const abstractStaticCssStyle = 'text-decoration:underline;font-style:italic;'; + describe('Enhanced parseClassifier functionality', () => { + it('should handle abstract and static combined (*$) on methods', () => { + const str = 'getTime()*$'; const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method has single parameter type and name (name first)', function () { - it('should parse correctly', function () { - const str = `getTime(count int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle public visibility', function () { - const str = `+getTime(count int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTime(count int)'); - }); + const details = classMember.getDisplayDetails(); - it('should handle private visibility', function () { - const str = `-getTime(count int)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTime(count int)'); + expect(details.displayText).toBe('getTime()'); + expect(details.cssStyle).toBe(abstractStaticCssStyle); }); - it('should handle protected visibility', function () { - const str = `#getTime(count int)`; - + it('should handle static and abstract combined ($*) on methods', () => { + const str = 'getTime()$*'; const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTime(count int)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTime(count int)`; + const details = classMember.getDisplayDetails(); - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTime(count int)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime(count int)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime(count int)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime(count int)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + expect(details.displayText).toBe('getTime()'); + expect(details.cssStyle).toBe(abstractStaticCssStyle); }); - it('should return correct css for static abstract classifier', function () { - const str = `getTime(count int)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method has multiple parameters', function () { - it('should parse correctly', function () { - const str = `getTime(string text, int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle public visibility', function () { - const str = `+getTime(string text, int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle private visibility', function () { - const str = `-getTime(string text, int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle protected visibility', function () { - const str = `#getTime(string text, int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should handle internal visibility', function () { - const str = `~getTime(string text, int count)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(str); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime(string text, int count)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime(string text, int count)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime(string text, int count)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTime(string text, int count)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method has return type', function () { - it('should parse correctly', function () { - const str = `getTime() DateTime`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); - }); - - it('should handle public visibility', function () { - const str = `+getTime() DateTime`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTime() : DateTime'); - }); - - it('should handle private visibility', function () { - const str = `-getTime() DateTime`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTime() : DateTime'); - }); - - it('should handle protected visibility', function () { - const str = `#getTime() DateTime`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTime() : DateTime'); - }); - - it('should handle internal visibility', function () { - const str = `~getTime() DateTime`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTime() : DateTime'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTime() DateTime$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTime() DateTime*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTime() DateTime*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTime() DateTime$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method parameter is generic', function () { - it('should parse correctly', function () { - const str = `getTimes(List~T~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); - }); - - it('should handle public visibility', function () { - const str = `+getTimes(List~T~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTimes(List)'); - }); - - it('should handle private visibility', function () { - const str = `-getTimes(List~T~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTimes(List)'); - }); - - it('should handle protected visibility', function () { - const str = `#getTimes(List~T~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTimes(List)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTimes(List~T~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTimes(List)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTimes(List~T~)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTimes(List~T~)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTimes(List~T~)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTimes(List~T~)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method parameter contains two generic', function () { - it('should parse correctly', function () { - const str = `getTimes(List~T~, List~OT~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); - }); - - it('should handle public visibility', function () { - const str = `+getTimes(List~T~, List~OT~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTimes(List, List)'); - }); - - it('should handle private visibility', function () { - const str = `-getTimes(List~T~, List~OT~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTimes(List, List)'); - }); - - it('should handle protected visibility', function () { - const str = `#getTimes(List~T~, List~OT~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTimes(List, List)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTimes(List~T~, List~OT~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTimes(List, List)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTimes(List~T~, List~OT~)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTimes(List~T~, List~OT~)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTimes(List~T~, List~OT~)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTimes(List~T~, List~OT~)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method parameter is a nested generic', function () { - it('should parse correctly', function () { - const str = `getTimetableList(List~List~T~~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); - }); - - it('should handle public visibility', function () { - const str = `+getTimetableList(List~List~T~~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTimetableList(List>)'); - }); - - it('should handle private visibility', function () { - const str = `-getTimetableList(List~List~T~~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTimetableList(List>)'); - }); - - it('should handle protected visibility', function () { - const str = `#getTimetableList(List~List~T~~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTimetableList(List>)'); - }); - - it('should handle internal visibility', function () { - const str = `~getTimetableList(List~List~T~~)`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTimetableList(List>)'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTimetableList(List~List~T~~)$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTimetableList(List~List~T~~)*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTimetableList(List~List~T~~)*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTimetableList(List~List~T~~)$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method parameter is a composite generic', function () { - const methodNameAndParameters = 'getTimes(List~K, V~)'; - const expectedMethodNameAndParameters = 'getTimes(List)'; - it('should parse correctly', function () { - const str = methodNameAndParameters; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); - }); - - it('should handle public visibility', function () { - const str = '+' + methodNameAndParameters; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '+' + expectedMethodNameAndParameters - ); - }); - - it('should handle private visibility', function () { - const str = '-' + methodNameAndParameters; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '-' + expectedMethodNameAndParameters - ); - }); - - it('should handle protected visibility', function () { - const str = '#' + methodNameAndParameters; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '#' + expectedMethodNameAndParameters - ); - }); - - it('should handle internal visibility', function () { - const str = '~' + methodNameAndParameters; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '~' + expectedMethodNameAndParameters - ); - }); - - it('should return correct css for static classifier', function () { - const str = methodNameAndParameters + '$'; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = methodNameAndParameters + '*'; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = methodNameAndParameters + '*$'; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = methodNameAndParameters + '$*'; - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method return type is generic', function () { - it('should parse correctly', function () { - const str = `getTimes() List~T~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); - }); - - it('should handle public visibility', function () { - const str = `+getTimes() List~T~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('+getTimes() : List'); - }); - - it('should handle private visibility', function () { - const str = `-getTimes() List~T~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('-getTimes() : List'); - }); - - it('should handle protected visibility', function () { - const str = `#getTimes() List~T~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('#getTimes() : List'); - }); - - it('should handle internal visibility', function () { - const str = `~getTimes() List~T~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('~getTimes() : List'); - }); - - it('should return correct css for static classifier', function () { - const str = `getTimes() List~T~$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTimes() List~T~*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTimes() List~T~*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTimes() List~T~$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when method return type is a nested generic', function () { - it('should parse correctly', function () { - const str = `getTimetableList() List~List~T~~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTimetableList() : List>' - ); - }); - - it('should handle public visibility', function () { - const str = `+getTimetableList() List~List~T~~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '+getTimetableList() : List>' - ); - }); - - it('should handle private visibility', function () { - const str = `-getTimetableList() List~List~T~~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '-getTimetableList() : List>' - ); - }); - - it('should handle protected visibility', function () { - const str = `#getTimetableList() List~List~T~~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '#getTimetableList() : List>' - ); - }); - - it('should handle internal visibility', function () { - const str = `~getTimetableList() List~List~T~~`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - '~getTimetableList() : List>' - ); - }); - - it('should return correct css for static classifier', function () { - const str = `getTimetableList() List~List~T~~$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTimetableList() : List>' - ); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); - }); - - it('should return correct css for abstract classifier', function () { - const str = `getTimetableList() List~List~T~~*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTimetableList() : List>' - ); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); - }); - - it('should return correct css for abstract static classifier', function () { - const str = `getTimetableList() List~List~T~~*$`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTimetableList() : List>' - ); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - - it('should return correct css for static abstract classifier', function () { - const str = `getTimetableList() List~List~T~~$*`; - - const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTimetableList() : List>' - ); - expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('--uncategorized tests--', function () { - it('member name should handle double colons', function () { - const str = `std::map ~int,string~ pMap;`; - + it('should handle abstract and static combined (*$) on attributes', () => { + const str = 'data String*$'; const classMember = new ClassMember(str, 'attribute'); - expect(classMember.getDisplayDetails().displayText).toBe('std::map pMap;'); + const details = classMember.getDisplayDetails(); + + expect(details.displayText).toBe('data String'); + expect(details.cssStyle).toBe(abstractStaticCssStyle); }); - it('member name should handle generic type', function () { - const str = `getTime~T~(this T, int seconds)$ DateTime`; + it('should handle static and abstract combined ($*) on attributes', () => { + const str = 'data String$*'; + const classMember = new ClassMember(str, 'attribute'); + const details = classMember.getDisplayDetails(); + expect(details.displayText).toBe('data String'); + expect(details.cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should handle complex method with abstract static combination', () => { + const str = '+processData(Map~String, List~Integer~~) Optional~Result~*$'; const classMember = new ClassMember(str, 'method'); - expect(classMember.getDisplayDetails().displayText).toBe( - 'getTime(this T, int seconds) : DateTime' + const details = classMember.getDisplayDetails(); + + expect(details.displayText).toBe( + '+processData(Map~String, List) : Optional' ); - expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + expect(details.cssStyle).toBe(abstractStaticCssStyle); }); - }); -}); -describe('given text representing an attribute', () => { - describe('when the attribute has no modifiers', () => { - it('should parse the display text correctly', () => { - const str = 'name String'; + it('should handle attribute with visibility and abstract static combination', () => { + const str = '#config Settings$*'; + const classMember = new ClassMember(str, 'attribute'); + const details = classMember.getDisplayDetails(); - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('name String'); - expect(displayDetails.cssStyle).toBe(''); + expect(details.displayText).toBe('#config Settings'); + expect(details.cssStyle).toBe(abstractStaticCssStyle); }); - }); - describe('when the attribute has public "+" modifier', () => { - it('should parse the display text correctly', () => { - const str = '+name String'; + // Verify existing classifier functionality still works + it('should still handle single static classifier correctly', () => { + const str = 'getName()$'; + const classMember = new ClassMember(str, 'method'); + const details = classMember.getDisplayDetails(); - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('+name String'); - expect(displayDetails.cssStyle).toBe(''); + expect(details.displayText).toBe('getName()'); + expect(details.cssStyle).toBe(staticCssStyle); }); - }); - describe('when the attribute has protected "#" modifier', () => { - it('should parse the display text correctly', () => { - const str = '#name String'; - - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('#name String'); - expect(displayDetails.cssStyle).toBe(''); - }); - }); - - describe('when the attribute has private "-" modifier', () => { - it('should parse the display text correctly', () => { - const str = '-name String'; - - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('-name String'); - expect(displayDetails.cssStyle).toBe(''); - }); - }); - - describe('when the attribute has internal "~" modifier', () => { - it('should parse the display text correctly', () => { - const str = '~name String'; - - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('~name String'); - expect(displayDetails.cssStyle).toBe(''); - }); - }); - - describe('when the attribute has static "$" modifier', () => { - it('should parse the display text correctly and apply static css style', () => { - const str = 'name String$'; - - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('name String'); - expect(displayDetails.cssStyle).toBe(staticCssStyle); - }); - }); - - describe('when the attribute has abstract "*" modifier', () => { - it('should parse the display text correctly and apply abstract css style', () => { + it('should still handle single abstract classifier correctly', () => { const str = 'name String*'; + const classMember = new ClassMember(str, 'attribute'); + const details = classMember.getDisplayDetails(); - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('name String'); - expect(displayDetails.cssStyle).toBe(abstractCssStyle); + expect(details.displayText).toBe('name String'); + expect(details.cssStyle).toBe(abstractCssStyle); }); - }); - describe('when the attribute has abstract static "*$" modifier', () => { - it('should parse the display text correctly and apply abstract static css style', () => { - const str = 'name String*$'; + it('should handle empty classifier correctly', () => { + const str = 'getValue()'; + const classMember = new ClassMember(str, 'method'); + const details = classMember.getDisplayDetails(); - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('name String'); - expect(displayDetails.cssStyle).toBe(abstractStaticCssStyle); - }); - }); - - describe('when the attribute has static abstract "$*" modifier', () => { - it('should parse the display text correctly and apply abstract static css style', () => { - const str = 'name String$*'; - - const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); - - expect(displayDetails.displayText).toBe('name String'); - expect(displayDetails.cssStyle).toBe(abstractStaticCssStyle); + expect(details.displayText).toBe('getValue()'); + expect(details.cssStyle).toBe(''); }); }); }); diff --git a/packages/mermaid/src/diagrams/class/classTypes.spec.ts.backup b/packages/mermaid/src/diagrams/class/classTypes.spec.ts.backup new file mode 100644 index 000000000..1d1ba7b80 --- /dev/null +++ b/packages/mermaid/src/diagrams/class/classTypes.spec.ts.backup @@ -0,0 +1,979 @@ +import { ClassMember } from './classTypes.js'; +import { vi, describe, it, expect } from 'vitest'; +const spyOn = vi.spyOn; + +const staticCssStyle = 'text-decoration:underline;'; +const abstractCssStyle = 'font-style:italic;'; +const abstractStaticCssStyle = 'text-decoration:underline;font-style:italic;'; + +describe('given text representing a method, ', function () { + describe('when method has no parameters', function () { + it('should parse correctly', function () { + const str = `getTime()`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle public visibility', function () { + const str = `+getTime()`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTime()'); + }); + + it('should handle private visibility', function () { + const str = `-getTime()`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTime()'); + }); + + it('should handle protected visibility', function () { + const str = `#getTime()`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTime()'); + }); + + it('should handle internal visibility', function () { + const str = `~getTime()`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTime()'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime()$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime()*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime()*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime()$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime()'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method has single parameter value', function () { + it('should parse correctly', function () { + const str = `getTime(int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle public visibility', function () { + const str = `+getTime(int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTime(int)'); + }); + + it('should handle private visibility', function () { + const str = `-getTime(int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTime(int)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTime(int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTime(int)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTime(int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTime(int)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime(int)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime(int)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime(int)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime(int)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method has single parameter type and name (type first)', function () { + it('should parse correctly', function () { + const str = `getTime(int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle public visibility', function () { + const str = `+getTime(int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTime(int count)'); + }); + + it('should handle private visibility', function () { + const str = `-getTime(int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTime(int count)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTime(int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTime(int count)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTime(int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTime(int count)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime(int count)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime(int count)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime(int count)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime(int count)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method has single parameter type and name (name first)', function () { + it('should parse correctly', function () { + const str = `getTime(count int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle public visibility', function () { + const str = `+getTime(count int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTime(count int)'); + }); + + it('should handle private visibility', function () { + const str = `-getTime(count int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTime(count int)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTime(count int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTime(count int)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTime(count int)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTime(count int)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime(count int)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime(count int)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime(count int)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime(count int)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(count int)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method has multiple parameters', function () { + it('should parse correctly', function () { + const str = `getTime(string text, int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle public visibility', function () { + const str = `+getTime(string text, int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle private visibility', function () { + const str = `-getTime(string text, int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle protected visibility', function () { + const str = `#getTime(string text, int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should handle internal visibility', function () { + const str = `~getTime(string text, int count)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(str); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime(string text, int count)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime(string text, int count)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime(string text, int count)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime(string text, int count)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime(string text, int count)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method has return type', function () { + it('should parse correctly', function () { + const str = `getTime() DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); + }); + + it('should handle public visibility', function () { + const str = `+getTime() DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTime() : DateTime'); + }); + + it('should handle private visibility', function () { + const str = `-getTime() DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTime() : DateTime'); + }); + + it('should handle protected visibility', function () { + const str = `#getTime() DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTime() : DateTime'); + }); + + it('should handle internal visibility', function () { + const str = `~getTime() DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTime() : DateTime'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTime() DateTime$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTime() DateTime*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTime() DateTime*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTime() DateTime$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTime() : DateTime'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method parameter is generic', function () { + it('should parse correctly', function () { + const str = `getTimes(List~T~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); + }); + + it('should handle public visibility', function () { + const str = `+getTimes(List~T~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTimes(List)'); + }); + + it('should handle private visibility', function () { + const str = `-getTimes(List~T~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTimes(List)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTimes(List~T~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTimes(List)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTimes(List~T~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTimes(List)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTimes(List~T~)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTimes(List~T~)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTimes(List~T~)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTimes(List~T~)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method parameter contains two generic', function () { + it('should parse correctly', function () { + const str = `getTimes(List~T~, List~OT~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); + }); + + it('should handle public visibility', function () { + const str = `+getTimes(List~T~, List~OT~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTimes(List, List)'); + }); + + it('should handle private visibility', function () { + const str = `-getTimes(List~T~, List~OT~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTimes(List, List)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTimes(List~T~, List~OT~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTimes(List, List)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTimes(List~T~, List~OT~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTimes(List, List)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTimes(List~T~, List~OT~)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTimes(List~T~, List~OT~)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTimes(List~T~, List~OT~)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTimes(List~T~, List~OT~)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes(List, List)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method parameter is a nested generic', function () { + it('should parse correctly', function () { + const str = `getTimetableList(List~List~T~~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); + }); + + it('should handle public visibility', function () { + const str = `+getTimetableList(List~List~T~~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTimetableList(List>)'); + }); + + it('should handle private visibility', function () { + const str = `-getTimetableList(List~List~T~~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTimetableList(List>)'); + }); + + it('should handle protected visibility', function () { + const str = `#getTimetableList(List~List~T~~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTimetableList(List>)'); + }); + + it('should handle internal visibility', function () { + const str = `~getTimetableList(List~List~T~~)`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTimetableList(List>)'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTimetableList(List~List~T~~)$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTimetableList(List~List~T~~)*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTimetableList(List~List~T~~)*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTimetableList(List~List~T~~)$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimetableList(List>)'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method parameter is a composite generic', function () { + const methodNameAndParameters = 'getTimes(List~K, V~)'; + const expectedMethodNameAndParameters = 'getTimes(List)'; + it('should parse correctly', function () { + const str = methodNameAndParameters; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); + }); + + it('should handle public visibility', function () { + const str = '+' + methodNameAndParameters; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '+' + expectedMethodNameAndParameters + ); + }); + + it('should handle private visibility', function () { + const str = '-' + methodNameAndParameters; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '-' + expectedMethodNameAndParameters + ); + }); + + it('should handle protected visibility', function () { + const str = '#' + methodNameAndParameters; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '#' + expectedMethodNameAndParameters + ); + }); + + it('should handle internal visibility', function () { + const str = '~' + methodNameAndParameters; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '~' + expectedMethodNameAndParameters + ); + }); + + it('should return correct css for static classifier', function () { + const str = methodNameAndParameters + '$'; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = methodNameAndParameters + '*'; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = methodNameAndParameters + '*$'; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = methodNameAndParameters + '$*'; + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe(expectedMethodNameAndParameters); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method return type is generic', function () { + it('should parse correctly', function () { + const str = `getTimes() List~T~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); + }); + + it('should handle public visibility', function () { + const str = `+getTimes() List~T~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('+getTimes() : List'); + }); + + it('should handle private visibility', function () { + const str = `-getTimes() List~T~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('-getTimes() : List'); + }); + + it('should handle protected visibility', function () { + const str = `#getTimes() List~T~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('#getTimes() : List'); + }); + + it('should handle internal visibility', function () { + const str = `~getTimes() List~T~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('~getTimes() : List'); + }); + + it('should return correct css for static classifier', function () { + const str = `getTimes() List~T~$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTimes() List~T~*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTimes() List~T~*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTimes() List~T~$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe('getTimes() : List'); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when method return type is a nested generic', function () { + it('should parse correctly', function () { + const str = `getTimetableList() List~List~T~~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTimetableList() : List>' + ); + }); + + it('should handle public visibility', function () { + const str = `+getTimetableList() List~List~T~~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '+getTimetableList() : List>' + ); + }); + + it('should handle private visibility', function () { + const str = `-getTimetableList() List~List~T~~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '-getTimetableList() : List>' + ); + }); + + it('should handle protected visibility', function () { + const str = `#getTimetableList() List~List~T~~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '#getTimetableList() : List>' + ); + }); + + it('should handle internal visibility', function () { + const str = `~getTimetableList() List~List~T~~`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + '~getTimetableList() : List>' + ); + }); + + it('should return correct css for static classifier', function () { + const str = `getTimetableList() List~List~T~~$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTimetableList() : List>' + ); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + + it('should return correct css for abstract classifier', function () { + const str = `getTimetableList() List~List~T~~*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTimetableList() : List>' + ); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractCssStyle); + }); + + it('should return correct css for abstract static classifier', function () { + const str = `getTimetableList() List~List~T~~*$`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTimetableList() : List>' + ); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + + it('should return correct css for static abstract classifier', function () { + const str = `getTimetableList() List~List~T~~$*`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTimetableList() : List>' + ); + expect(classMember.getDisplayDetails().cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('--uncategorized tests--', function () { + it('member name should handle double colons', function () { + const str = `std::map ~int,string~ pMap;`; + + const classMember = new ClassMember(str, 'attribute'); + expect(classMember.getDisplayDetails().displayText).toBe('std::map pMap;'); + }); + + it('member name should handle generic type', function () { + const str = `getTime~T~(this T, int seconds)$ DateTime`; + + const classMember = new ClassMember(str, 'method'); + expect(classMember.getDisplayDetails().displayText).toBe( + 'getTime(this T, int seconds) : DateTime' + ); + expect(classMember.getDisplayDetails().cssStyle).toBe(staticCssStyle); + }); + }); +}); + +describe('given text representing an attribute', () => { + describe('when the attribute has no modifiers', () => { + it('should parse the display text correctly', () => { + const str = 'name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has public "+" modifier', () => { + it('should parse the display text correctly', () => { + const str = '+name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('+name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has protected "#" modifier', () => { + it('should parse the display text correctly', () => { + const str = '#name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('#name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has private "-" modifier', () => { + it('should parse the display text correctly', () => { + const str = '-name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('-name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has internal "~" modifier', () => { + it('should parse the display text correctly', () => { + const str = '~name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('~name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has static "$" modifier', () => { + it('should parse the display text correctly and apply static css style', () => { + const str = 'name String$'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(staticCssStyle); + }); + }); + + describe('when the attribute has abstract "*" modifier', () => { + it('should parse the display text correctly and apply abstract css style', () => { + const str = 'name String*'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(abstractCssStyle); + }); + }); + + describe('when the attribute has abstract static "*$" modifier', () => { + it('should parse the display text correctly and apply abstract static css style', () => { + const str = 'name String*$'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(abstractStaticCssStyle); + }); + }); + + describe('when the attribute has static abstract "$*" modifier', () => { + it('should parse the display text correctly and apply abstract static css style', () => { + const str = 'name String$*'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(abstractStaticCssStyle); + }); + }); +});